diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2021-06-03 23:44:53 +0530 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2021-06-03 23:44:53 +0530 |
commit | 0090c644eb7eb088be5dc5a9889f654003c4d6c6 (patch) | |
tree | 22c8f28c045578a0e15ad89477c98ccd730ce138 | |
parent | 5525ecf681b83f2393dfda458d39f562ee3eba09 (diff) |
updated user model
-rw-r--r-- | app/models.py | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/app/models.py b/app/models.py index 2734921..bd28e75 100644 --- a/app/models.py +++ b/app/models.py @@ -1,7 +1,43 @@ -class User(db.Model): - id = db.Column(db.Integer, primary_key=True) - username = db.Column(db.String(80), unique=True, nullable=False) - email = db.Column(db.String(120), unique=True, nullable=False) +from sqlalchemy.ext.hybrid import hybrid_property +from flask_login import UserMixin - def __repr__(self): - return '<User %r>' % self.username
\ No newline at end of file +from app import bcrypt, db + +class User(db.Model, UserMixin): + __tablename__ = 'users' + + first_name = db.Column(db.String) + last_name = db.Column(db.String) + email = db.Column(db.String(120), primary_key=True) + confirmation = db.Column(db.Boolean) + paid = db.Column(db.Boolean) + role = db.Column(db.String) + team = db.Column(db.String) + _password = db.Column(db.String) + + @property + def full_name(self): + return '{} {}'.format(self.first_name, self.last_name) + + @hybrid_property + def password(self): + return self._password + + @password.setter + def password(self, plaintext): + self._password = bcrypt.generate_password_hash(plaintext) + + def check_password(self, plaintext): + return bcrypt.check_password_hash(self.password, plaintext) + + def get_id(self): + return self.email + + def get_role(self): + return self.roles + + def get_team(self): + return self.get_team + + def is_paid(self): + return self.paid
\ No newline at end of file |