aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2021-06-03 23:44:53 +0530
committerNavan Chauhan <navanchauhan@gmail.com>2021-06-03 23:44:53 +0530
commit0090c644eb7eb088be5dc5a9889f654003c4d6c6 (patch)
tree22c8f28c045578a0e15ad89477c98ccd730ce138 /app
parent5525ecf681b83f2393dfda458d39f562ee3eba09 (diff)
updated user model
Diffstat (limited to 'app')
-rw-r--r--app/models.py48
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