# Path: deploy/app/models.py
# class User(db.Model, UserMixin):
#     __tablename__ = 'users'
#     id = db.Column(db.Integer, primary_key=True)
#     email = db.Column(db.String(64), unique=True, index=True)
#     username = db.Column(db.String(64), unique=True, index=True)
#     password_hash = db.Column(db.String(128))
#     is_ignored = db.Column(db.Boolean, default=False)
#     role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
#     department_id = db.Column(db.Integer, db.ForeignKey('departments.id'))
#     is_super_admin = db.Column(db.Boolean, default=False)
# 
#     @property
#     def password(self):
#         raise AttributeError('Password is not a readable attribute')
# 
#     @password.setter
#     def password(self, password):
#         self.password_hash = generate_password_hash(password)
# 
#     def verify_password(self, password):
#         return check_password_hash(self.password_hash, password)
# 
#     def can(self, permisson):
#         return self.role is not None and \
#                (self.role.permissions & permisson) == permisson
# 
#     def generate_reset_token(self, expiration=3600):
#         s = Serializer(current_app.config['SECRET_KEY'], expiration)
#         return s.dumps({'reset': self.id})
# 
#     def reset_password(self, token, new_password):
#         s = Serializer(current_app.config['SECRET_KEY'])
#         try:
#             data = s.loads(token)
#         except:
#             return False
#         if data.get('reset') != self.id:
#             return False
#         self.password = new_password
#         db.session.add(self)
#         return True
# 
#     @property
#     def is_admin(self):
#         return self.role.name == 'ADMINISTRATOR' or self.is_super_admin
# 
#     @property
#     def is_hr(self):
#         return self.role is not None and self.role.name == 'HR'
# 
#     @property
#     def is_manager(self):
#         return self.role is not None and self.role.name == 'MANAGER'
# 
#     @property
#     def is_authenticated(self):
#         return self.can(Permission.WRITE_REPORT)
# 
#     def __str__(self):
#         return self.username
#         
#     def __repr__(self):
#         return self.username        


from flask_babelex import lazy_gettext as _
from flask_wtf import FlaskForm
from wtforms.fields.html5 import EmailField
from wtforms import BooleanField, SubmitField, \
    StringField, PasswordField, SelectField
from wtforms.validators import DataRequired, Length, EqualTo
from wtforms import ValidationError
from ..models import User
        DataRequired(), Length(1, 64),
        EqualTo('username2', message=_("Usernames doesn't match"))])
    username2 = StringField(_('Confirm New Username'), validators=[
        DataRequired(), Length(1, 64)])
    submit = SubmitField(_('Update Username'))

    def validate_username(self, field):
        if User.query.filter_by(username=field.data).first():
            raise ValidationError(_('Username has been used'))


class PasswordResetRequestForm(FlaskForm):
    email = EmailField(_('Email'), validators=[DataRequired(), Length(1, 64)])
    submit = SubmitField(_('Reset Password'))

    def validate_email(self, field):
        if User.query.filter_by(email=field.data).first() is None:
            raise ValidationError(_('Unknown email address'))


class PasswordResetForm(FlaskForm):
    email = EmailField(_('Email'),  validators=[
        DataRequired(), Length(1, 64)])
    password = PasswordField(_('New Password'), validators=[
        DataRequired(), EqualTo('password2', message="Passwords doesn't match")])
    password2 = PasswordField(_('Confirm New password'),
                              validators=[DataRequired()])
    submit = SubmitField(_('Reset Password'))

    def validate_email(self, field):

# Path: deploy/app/models.py
# class User(db.Model, UserMixin):
#     __tablename__ = 'users'
#     id = db.Column(db.Integer, primary_key=True)
#     email = db.Column(db.String(64), unique=True, index=True)
#     username = db.Column(db.String(64), unique=True, index=True)
#     password_hash = db.Column(db.String(128))
#     is_ignored = db.Column(db.Boolean, default=False)
#     role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
#     department_id = db.Column(db.Integer, db.ForeignKey('departments.id'))
#     is_super_admin = db.Column(db.Boolean, default=False)
# 
#     @property
#     def password(self):
#         raise AttributeError('Password is not a readable attribute')
# 
#     @password.setter
#     def password(self, password):
#         self.password_hash = generate_password_hash(password)
# 
#     def verify_password(self, password):
#         return check_password_hash(self.password_hash, password)
# 
#     def can(self, permisson):
#         return self.role is not None and \
#                (self.role.permissions & permisson) == permisson
# 
#     def generate_reset_token(self, expiration=3600):
#         s = Serializer(current_app.config['SECRET_KEY'], expiration)
#         return s.dumps({'reset': self.id})
# 
#     def reset_password(self, token, new_password):
#         s = Serializer(current_app.config['SECRET_KEY'])
#         try:
#             data = s.loads(token)
#         except:
#             return False
#         if data.get('reset') != self.id:
#             return False
#         self.password = new_password
#         db.session.add(self)
#         return True
# 
#     @property
#     def is_admin(self):
#         return self.role.name == 'ADMINISTRATOR' or self.is_super_admin
# 
#     @property
#     def is_hr(self):
#         return self.role is not None and self.role.name == 'HR'
# 
#     @property
#     def is_manager(self):
#         return self.role is not None and self.role.name == 'MANAGER'
# 
#     @property
#     def is_authenticated(self):
#         return self.can(Permission.WRITE_REPORT)
# 
#     def __str__(self):
#         return self.username
#         
#     def __repr__(self):
#         return self.username        


# Path: deploy/app/auth/forms.py
from flask_babelex import lazy_gettext as _
from flask_wtf import FlaskForm
from wtforms.fields.html5 import EmailField
from wtforms import BooleanField, SubmitField, \
    StringField, PasswordField, SelectField
from wtforms.validators import DataRequired, Length, EqualTo
from wtforms import ValidationError
from ..models import User

        DataRequired(), Length(1, 64),
        EqualTo('username2', message=_("Usernames doesn't match"))])
    username2 = StringField(_('Confirm New Username'), validators=[
        DataRequired(), Length(1, 64)])
    submit = SubmitField(_('Update Username'))

    def validate_username(self, field):
        if User.query.filter_by(username=field.data).first():
            raise ValidationError(_('Username has been used'))


class PasswordResetRequestForm(FlaskForm):
    email = EmailField(_('Email'), validators=[DataRequired(), Length(1, 64)])
    submit = SubmitField(_('Reset Password'))

    def validate_email(self, field):
        if User.query.filter_by(email=field.data).first() is None:
            raise ValidationError(_('Unknown email address'))


class PasswordResetForm(FlaskForm):
    email = EmailField(_('Email'),  validators=[
        DataRequired(), Length(1, 64)])
    password = PasswordField(_('New Password'), validators=[
        DataRequired(), EqualTo('password2', message="Passwords doesn't match")])
    password2 = PasswordField(_('Confirm New password'),
                              validators=[DataRequired()])
    submit = SubmitField(_('Reset Password'))

    def validate_email(self, field):

        if User.query.filter_by(email=field.data).first() is None: