#2 Added routes for login and logout
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from app import db
|
||||
from flask_login import UserMixin
|
||||
from datetime import datetime
|
||||
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
|
||||
class User(UserMixin, db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
@@ -12,6 +12,9 @@ class User(UserMixin, db.Model):
|
||||
last_seen = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
token = db.Column(db.String(32), index=True, unique=True)
|
||||
|
||||
def __repr__(self):
|
||||
return f'<User {self.username}>'
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
@@ -19,3 +22,11 @@ class User(UserMixin, db.Model):
|
||||
"email": self.email,
|
||||
"about_me": self.about_me,
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user