essai 2 #254

Closed
IDK wants to merge 4 commits from master into refactor_nt
2 changed files with 9 additions and 5 deletions

View File

@ -11,7 +11,7 @@ from time import time
from typing import Optional
import cracklib # pylint: disable=import-error
from flask import current_app, url_for, g
from flask import current_app, g
from flask_login import UserMixin, AnonymousUserMixin
from werkzeug.security import generate_password_hash, check_password_hash
@ -136,6 +136,7 @@ class User(UserMixin, db.Model):
return check_password_hash(self.password_hash, password)
def get_reset_password_token(self, expires_in=600):
"Un token pour réinitialiser son mot de passe"
return jwt.encode(
{"reset_password": self.id, "exp": time() + expires_in},
current_app.config["SECRET_KEY"],
@ -144,15 +145,17 @@ class User(UserMixin, db.Model):
@staticmethod
def verify_reset_password_token(token):
"Vérification du token de reéinitialisation du mot de passe"
try:
id = jwt.decode(
user_id = jwt.decode(
token, current_app.config["SECRET_KEY"], algorithms=["HS256"]
)["reset_password"]
except:
return
return User.query.get(id)
return User.query.get(user_id)
def to_dict(self, include_email=True):
"""l'utilisateur comme un dict, avec des champs supplémentaires"""
data = {
"date_expiration": self.date_expiration.isoformat() + "Z"
if self.date_expiration
@ -472,5 +475,5 @@ def get_super_admin():
@login.user_loader
def load_user(id):
return User.query.get(int(id))
def load_user(uid):
return User.query.get(int(uid))

1
toto Normal file
View File

@ -0,0 +1 @@
hello essai