Add reset token generation functionality in User class.

This commit is contained in:
Patrick Jentsch 2019-07-08 13:55:56 +02:00
parent ed921b68d7
commit 4ef5b480b1

View File

@ -1,4 +1,6 @@
from flask import current_app
from flask_login import UserMixin
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from werkzeug.security import generate_password_hash, check_password_hash
from . import db
from . import login_manager
@ -26,6 +28,10 @@ class User(UserMixin, db.Model):
password_hash = db.Column(db.String(128))
def generate_reset_token(self, expiration=3600):
s = Serializer(current_app.config['SECRET_KEY'], expiration)
return s.dumps({'reset': self.id}).decode('utf-8')
@property
def password(self):
raise AttributeError('password is not a readable attribute')