diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-03-26 16:17:11 +0000 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-03-26 16:17:11 +0000 |
| commit | 98f0fcdcbdbbd91a2a4da6b44229a178ddb38d31 (patch) | |
| tree | ec6f1254bab7e65954694704a20c947fa268649e /app/models.py | |
| parent | Add email confirmation field (diff) | |
| download | AnnotateChange-98f0fcdcbdbbd91a2a4da6b44229a178ddb38d31.tar.gz AnnotateChange-98f0fcdcbdbbd91a2a4da6b44229a178ddb38d31.zip | |
Add support for email confirmation
Diffstat (limited to 'app/models.py')
| -rw-r--r-- | app/models.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/models.py b/app/models.py index 86e15f0..3bc394c 100644 --- a/app/models.py +++ b/app/models.py @@ -50,6 +50,23 @@ class User(UserMixin, db.Model): return None return User.query.get(_id) + def get_email_confirmation_token(self, expires_in=3600): + return jwt.encode( + {"email": self.email, "exp": time.time() + expires_in}, + current_app.config["SECRET_KEY"], + algorithm="HS256", + ).decode("utf-8") + + @staticmethod + def verify_email_confirmation_token(token): + try: + _email = jwt.decode( + token, current_app.config["SECRET_KEY"], algorithms=["HS256"] + )["email"] + except: + return None + return User.query.filter_by(email=_email).first() + class Dataset(db.Model): id = db.Column(db.Integer, primary_key=True) |
