From 0090c644eb7eb088be5dc5a9889f654003c4d6c6 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Thu, 3 Jun 2021 23:44:53 +0530 Subject: updated user model --- app/models.py | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) (limited to 'app') 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 '' % 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 -- cgit v1.2.3