Flask-web_platform/app/models.py
2024-10-09 17:35:57 +08:00

19 lines
640 B
Python

from app import db, login_manager
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
class User(UserMixin, db.Model):
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)
def set_password(self, password):
self.password = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.password, password)
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))