Chapter 5

This commit is contained in:
2023-06-03 17:32:23 +02:00
parent f9020e921f
commit 428e022bd4
9 changed files with 136 additions and 21 deletions

View File

@@ -1,8 +1,15 @@
from datetime import datetime
from app import db
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import UserMixin
from app import db, login
class User(db.Model):
@login.user_loader
def load_user(id):
return User.query.get(int(id))
class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), index=True, unique=True)
email = db.Column(db.String(120), index=True, unique=True)
@@ -12,6 +19,12 @@ class User(db.Model):
def __repr__(self):
return "<User {}>".format(self.username)
def set_password(self, password):
self.password_hash = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.password_hash, password)
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)