Skip to content
Snippets Groups Projects
Commit c70048eb authored by Harry Hughes's avatar Harry Hughes
Browse files

Replace models.py

parent 944659e1
Branches
No related tags found
No related merge requests found
from datetime import datetime
from blog import db, login_manager
from flask_login import UserMixin
import bcrypt
from werkzeug.security import generate_password_hash, check_password_hash
class Post(db.Model):
......@@ -20,21 +21,17 @@ class User(UserMixin,db.Model):
post = db.relationship('Post', backref='user', lazy=True)
is_admin=db.Column(db.Boolean,nullable=False,default=False)
email=db.Column(db.String(256), unique=True)
def __repr__(self):
return f"User('{self.username}')"
#adapted from Grinberg(2014, 2018)
@property
def password(self):
raise AttributeError('Password is not readable.')
def set_password(self,password):
salt = bcrypt.gensalt()
hashed_password = bcrypt.hashpw(password.encode(), salt)
self.password = hashed_password.decode()
@password.setter
def password(self,password):
self.password=generate_password_hash(password)
def check_password(self,password):
return bcrypt.checkpw(password.encode(), self.password.encode)
def verify_password(self,password):
return check_password_hash(self.password,password)
def __repr__(self):
return f"User('{self.username}')"
class Portfolio(db.Model):
id = db.Column(db.Integer, primary_key=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment