33 lines
894 B
Python
33 lines
894 B
Python
from extensions import db
|
|
from flask_bcrypt import Bcrypt
|
|
from flask_login import UserMixin
|
|
|
|
bcrypt = Bcrypt()
|
|
|
|
class User(db.Model, UserMixin):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
username = db.Column(db.String(80), unique=True, nullable=False)
|
|
password = db.Column(db.String(120), nullable=False)
|
|
role = db.Column(db.String(80), nullable=False)
|
|
theme = db.Column(db.String(80), default='light')
|
|
|
|
def set_password(self, password):
|
|
self.password = bcrypt.generate_password_hash(password).decode('utf-8')
|
|
|
|
def check_password(self, password):
|
|
return bcrypt.check_password_hash(self.password, password)
|
|
|
|
@property
|
|
def is_active(self):
|
|
return True
|
|
|
|
@property
|
|
def is_authenticated(self):
|
|
return True
|
|
|
|
@property
|
|
def is_anonymous(self):
|
|
return False
|
|
|
|
def get_id(self):
|
|
return str(self.id) |