diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-03-18 16:05:36 +0000 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-03-18 16:05:36 +0000 |
| commit | b499f31dfcb4e3cf27c34ae0958612a9d43bf910 (patch) | |
| tree | 71e19ad212225060c1ccd3bd9308e0420b1f3ad8 /app/models.py | |
| parent | add gitignore (diff) | |
| download | AnnotateChange-b499f31dfcb4e3cf27c34ae0958612a9d43bf910.tar.gz AnnotateChange-b499f31dfcb4e3cf27c34ae0958612a9d43bf910.zip | |
add errors, email, and reset password
Diffstat (limited to 'app/models.py')
| -rw-r--r-- | app/models.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/app/models.py b/app/models.py index 0483ff7..cb90fda 100644 --- a/app/models.py +++ b/app/models.py @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- import datetime +import jwt +import time from flask_login import UserMixin from werkzeug.security import generate_password_hash, check_password_hash +from app import app from app import db from app import login @@ -28,6 +31,23 @@ class User(UserMixin, db.Model): def check_password(self, password): return check_password_hash(self.password_hash, password) + def get_reset_password_token(self, expires_in=600): + return jwt.encode( + {"reset_password": self.id, "exp": time.time() + expires_in}, + app.config["SECRET_KEY"], + algorithm="HS256", + ).decode("utf-8") + + @staticmethod + def verify_reset_password_token(token): + try: + _id = jwt.decode( + token, app.config["SECRET_KEY"], algorithms=["HS256"] + )["reset_password"] + except: + return None + return User.query.get(_id) + class Dataset(db.Model): id = db.Column(db.Integer, primary_key=True) |
