forked from alectrocute/flaskSaaS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
41 lines (28 loc) · 1017 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from sqlalchemy.ext.hybrid import hybrid_property
from flask.ext.login import UserMixin
from app import db, bcrypt
class User(db.Model, UserMixin):
''' A user who has an account on the website. '''
__tablename__ = 'users'
first_name = db.Column(db.String)
last_name = db.Column(db.String)
phone = db.Column(db.String)
email = db.Column(db.String, primary_key=True)
confirmation = db.Column(db.Boolean)
paid = db.Column(db.Boolean)
_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 is_paid(self):
return self.paid