Newer
Older
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
41
42
43
44
45
46
47
48
49
50
from sqlalchemy.ext.hybrid import hybrid_property, hybrid_method
from sqlalchemy.ext.declarative import declared_attr
from app import bcrypt, db
from app.database import Base
class Blacklist(db.Model):
id = db.Column(db.Integer, primary_key=True)
jti = db.Column(db.String, unique=True, nullable=False)
@declared_attr
def __tablename__(self):
return "blacklist"
def __init__(self, jti):
self.jti = jti
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(254), unique=True, nullable=False)
name = db.Column(db.String(50), nullable=True)
_password = db.Column(db.LargeBinary(60), nullable=False)
authenticated = db.Column(db.Boolean, default=False)
twoAuthConfirmed = db.Column(db.Boolean, default=True) # Change to false for Two factor authen
twoAuthCode = db.Column(db.String(100), nullable=True)
def __init__(self, email, plaintext_password, name=""):
self._password = bcrypt.generate_password_hash(plaintext_password)
self.email = email
self.name = name
self.authenticated = False
def get_dict(self):
return {"id": self.id, "email": self.email, "name": self.name}
@hybrid_property
def password(self):
return self._password
@password.setter
def set_password(self, plaintext_password):
self._password = bcrypt.generate_password_hash(plaintext_password)
@hybrid_method
def is_correct_password(self, plaintext_password):
return bcrypt.check_password_hash(self._password, plaintext_password)