Skip to content

Commit f941aba

Browse files
authored
Update models.py
TimedJSONWebSignatureSerializer has been deprecated from itsdangerous since version 2.1.0 recommended use: URLSafeTimedSerializer URLSafeTimedSerializer does not have an expiration parameters, expiration paramenter. Expiration parameter can be passed to .load(token, max_age) https://stackoverflow.com/questions/46486062/the-dumps-method-of-itsdangerous-throws-a-typeerror https://itsdangerous.palletsprojects.com/en/2.1.x/url_safe/
1 parent 692ccae commit f941aba

File tree

1 file changed

+7
-7
lines changed
  • Python/Flask_Blog/11-Blueprints/flaskblog

1 file changed

+7
-7
lines changed

Python/Flask_Blog/11-Blueprints/flaskblog/models.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import datetime
2-
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
2+
from itsdangerous import URLSafeTimedSerializer as Serializer
33
from flask import current_app
44
from flaskblog import db, login_manager
55
from flask_login import UserMixin
@@ -18,15 +18,15 @@ class User(db.Model, UserMixin):
1818
password = db.Column(db.String(60), nullable=False)
1919
posts = db.relationship('Post', backref='author', lazy=True)
2020

21-
def get_reset_token(self, expires_sec=1800):
22-
s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
23-
return s.dumps({'user_id': self.id}).decode('utf-8')
21+
def get_reset_token(self):
22+
s = Serializer(current_app.config['SECRET_KEY'], 'confirmation')
23+
return s.dumps({'user_id': self.id})
2424

2525
@staticmethod
26-
def verify_reset_token(token):
27-
s = Serializer(current_app.config['SECRET_KEY'])
26+
def verify_reset_token(token, max_age=1800):
27+
s = Serializer(current_app.config['SECRET_KEY'], 'confirmation')
2828
try:
29-
user_id = s.loads(token)['user_id']
29+
user_id = s.loads(token, max_age=max_age)['user_id']
3030
except:
3131
return None
3232
return User.query.get(user_id)

0 commit comments

Comments
 (0)