Skip to content
Snippets Groups Projects
Commit 4ef5b480 authored by Patrick Jentsch's avatar Patrick Jentsch
Browse files

Add reset token generation functionality in User class.

parent ed921b68
No related branches found
No related tags found
No related merge requests found
from flask import current_app
from flask_login import UserMixin from flask_login import UserMixin
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from werkzeug.security import generate_password_hash, check_password_hash from werkzeug.security import generate_password_hash, check_password_hash
from . import db from . import db
from . import login_manager from . import login_manager
...@@ -26,6 +28,10 @@ class User(UserMixin, db.Model): ...@@ -26,6 +28,10 @@ class User(UserMixin, db.Model):
password_hash = db.Column(db.String(128)) 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 @property
def password(self): def password(self):
raise AttributeError('password is not a readable attribute') raise AttributeError('password is not a readable attribute')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment