# Path: server/errors_handlers.py
# class CheckError(ValueError):
#     pass


from flask.ext.security import UserMixin, RoleMixin
from flask.ext.sqlalchemy import SQLAlchemy
from savalidation import ValidationMixin
from flask.ext.security.utils import encrypt_password, verify_password
from datetime import datetime
from .errors_handlers import CheckError
    password = db.Column(db.String(255))
    active = db.Column(db.Boolean(), default=False)
    confirmed_at = db.Column(db.DateTime())
    roles = db.relationship('Role', secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))

    def set_password(self, password):
        self.password = encrypt_password(password)

    def check_password(self, password):
        return verify_password(password, self.password)

    def check_mail_for_uniqueness(self, new_email):
        if self.query.filter_by(email=new_email).first() is None:
            result = True
        else:
            result = False
        return result

    def check_unique_username(self, new_username):
        if self.query.filter_by(username=new_username).first() is None:
            result = True
        else:
            result = False
        return result

    def import_data(self, data):
        try:
            self.email = data['email']
        except KeyError as key_err:

# Path: server/errors_handlers.py
# class CheckError(ValueError):
#     pass


# Path: server/models.py
from flask.ext.security import UserMixin, RoleMixin
from flask.ext.sqlalchemy import SQLAlchemy
from savalidation import ValidationMixin
from flask.ext.security.utils import encrypt_password, verify_password
from datetime import datetime
from .errors_handlers import CheckError

    password = db.Column(db.String(255))
    active = db.Column(db.Boolean(), default=False)
    confirmed_at = db.Column(db.DateTime())
    roles = db.relationship('Role', secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))

    def set_password(self, password):
        self.password = encrypt_password(password)

    def check_password(self, password):
        return verify_password(password, self.password)

    def check_mail_for_uniqueness(self, new_email):
        if self.query.filter_by(email=new_email).first() is None:
            result = True
        else:
            result = False
        return result

    def check_unique_username(self, new_username):
        if self.query.filter_by(username=new_username).first() is None:
            result = True
        else:
            result = False
        return result

    def import_data(self, data):
        try:
            self.email = data['email']
        except KeyError as key_err:

            raise CheckError('Invalid user: missing ' + key_err.args[0])