Exemplo n.º 1
0
class User(db.Model, UserMixin):
    id = db.Column(db.String(36), primary_key=True)
    name = db.Column(db.String(80), unique=False, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False, index=True)
    is_active = db.Column(db.Boolean, default=True)

    def __init__(self, **kwargs):
        super(User, self).__init__(**kwargs)

    def __repr__(self):
        return '<User %r>' % self.name

    def get_id(self):
        return self.id
Exemplo n.º 2
0
class Password(db.Model):
    user_id = db.Column(db.String(36), primary_key=True)
    encryted_pw = db.Column(db.String(33), nullable=False)
    salt = db.Column(db.String(36), nullable=False)

    def __init__(self, user_id, password, **kwargs):
        super(Password, self).__init__(**kwargs)
        self.user_id = user_id
        self.salt = str(uuid.uuid4())
        self.encryted_pw = hashlib.md5((password + self.salt).encode('utf-8')).hexdigest()

    def __repr__(self):
        return '<Password of user id: %r>' % self.user_id

    def validate(self, password):
        input_encryted_pw = hashlib.md5((password + self.salt).encode('utf-8')).hexdigest()
        return self.encryted_pw == input_encryted_pw
Exemplo n.º 3
0
class UserProfile(db.Model):
    user_id = db.Column(db.String(36), primary_key=True)
    role_id = db.Column(db.Integer, unique=False, nullable=False)
    department_id = db.Column(db.Integer, unique=False, nullable=False)

    # Nullables:
    first_name = db.Column(db.String(50), unique=False, nullable=True)
    last_name = db.Column(db.String(50), unique=False, nullable=True)
    avatar = db.Column(db.String(300), unique=False, nullable=True)
    gender = db.Column(db.Boolean,
                       nullable=True,
                       comment="T for Male, F for Female",
                       default=None)

    def __repr__(self):
        return f'<User: {self.first_name} {self.last_name}>'
Exemplo n.º 4
0
class Department(db.Model):
    id = db.Column(db.Integer(), primary_key=True, autoincrement=True)
    name = db.Column(db.String(50), unique=True, nullable=False)

    def __repr__(self):
        return f'<Department: {self.name}>'