# Path: hashview/models.py
# class Users(db.Model, UserMixin):
#     id = db.Column(db.Integer, primary_key=True)
#     first_name = db.Column(db.String(20), nullable=False)
#     last_name = db.Column(db.String(20), nullable=False)
#     email_address = db.Column(db.String(50), unique=True, nullable=False)
#     password = db.Column(db.String(60), nullable=False)
#     admin = db.Column(db.Boolean, nullable=False, default=False)
#     pushover_app_id = db.Column(db.String(50), nullable=True)
#     pushover_user_key = db.Column(db.String(50), nullable=True)
#     wordlists = db.relationship('Wordlists', backref='tbd', lazy=True)
#     rules = db.relationship('Rules', backref='owner', lazy=True)
#     jobs = db.relationship('Jobs', backref='owner', lazy=True)
#     tasks = db.relationship('Tasks', backref='owner', lazy=True)
#     taskgroups = db.relationship('TaskGroups', backref='owner', lazy=True)
# 
#     def get_reset_token(self, expires_sec=1800):
#         s = Serializer(Config.SECRET_KEY, expires_sec)
#         return s.dumps({'user_id': self.id}).decode('utf-8')
# 
#     @staticmethod
#     def verify_reset_token(token):
#         s = Serializer(Config.SECRET_KEY)
#         try:
#             user_id = s.loads(token)['user_id']
#         except:
#             return None     
#         return Users.query.get(user_id)


from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, ValidationError, SubmitField
from wtforms.validators import DataRequired, EqualTo, Email, Length
from hashview.models import Users

class UsersForm(FlaskForm):
    first_name = StringField('First Name', validators=[DataRequired(), Length(min=1, max=20)])
    last_name = StringField('Last Name', validators=[DataRequired(), Length(min=1, max=20)])
    email = StringField('Email', validators=[DataRequired(), Email()])
    is_admin = BooleanField('Is Admin')
    password = PasswordField('Password', validators=[DataRequired(), Length(min=14)])
    confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo('password')])
    pushover_app_id = StringField('Pushover App Token (optional)')
    pushover_user_key = StringField('Pushover User Key (optional)')
    submit = SubmitField('Register')

    def validate_email(self, email):

# Path: hashview/models.py
# class Users(db.Model, UserMixin):
#     id = db.Column(db.Integer, primary_key=True)
#     first_name = db.Column(db.String(20), nullable=False)
#     last_name = db.Column(db.String(20), nullable=False)
#     email_address = db.Column(db.String(50), unique=True, nullable=False)
#     password = db.Column(db.String(60), nullable=False)
#     admin = db.Column(db.Boolean, nullable=False, default=False)
#     pushover_app_id = db.Column(db.String(50), nullable=True)
#     pushover_user_key = db.Column(db.String(50), nullable=True)
#     wordlists = db.relationship('Wordlists', backref='tbd', lazy=True)
#     rules = db.relationship('Rules', backref='owner', lazy=True)
#     jobs = db.relationship('Jobs', backref='owner', lazy=True)
#     tasks = db.relationship('Tasks', backref='owner', lazy=True)
#     taskgroups = db.relationship('TaskGroups', backref='owner', lazy=True)
# 
#     def get_reset_token(self, expires_sec=1800):
#         s = Serializer(Config.SECRET_KEY, expires_sec)
#         return s.dumps({'user_id': self.id}).decode('utf-8')
# 
#     @staticmethod
#     def verify_reset_token(token):
#         s = Serializer(Config.SECRET_KEY)
#         try:
#             user_id = s.loads(token)['user_id']
#         except:
#             return None     
#         return Users.query.get(user_id)


# Path: hashview/users/forms.py
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, ValidationError, SubmitField
from wtforms.validators import DataRequired, EqualTo, Email, Length
from hashview.models import Users


class UsersForm(FlaskForm):
    first_name = StringField('First Name', validators=[DataRequired(), Length(min=1, max=20)])
    last_name = StringField('Last Name', validators=[DataRequired(), Length(min=1, max=20)])
    email = StringField('Email', validators=[DataRequired(), Email()])
    is_admin = BooleanField('Is Admin')
    password = PasswordField('Password', validators=[DataRequired(), Length(min=14)])
    confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo('password')])
    pushover_app_id = StringField('Pushover App Token (optional)')
    pushover_user_key = StringField('Pushover User Key (optional)')
    submit = SubmitField('Register')

    def validate_email(self, email):

        user = Users.query.filter_by(email_address = email.data).first()