forked from ScoDoc/DocScoDoc
comments
This commit is contained in:
parent
dc004de8ef
commit
46c64ba78b
@ -11,7 +11,7 @@ from time import time
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import cracklib # pylint: disable=import-error
|
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 flask_login import UserMixin, AnonymousUserMixin
|
||||||
|
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
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)
|
return check_password_hash(self.password_hash, password)
|
||||||
|
|
||||||
def get_reset_password_token(self, expires_in=600):
|
def get_reset_password_token(self, expires_in=600):
|
||||||
|
"Un token pour réinitialiser son mot de passe"
|
||||||
return jwt.encode(
|
return jwt.encode(
|
||||||
{"reset_password": self.id, "exp": time() + expires_in},
|
{"reset_password": self.id, "exp": time() + expires_in},
|
||||||
current_app.config["SECRET_KEY"],
|
current_app.config["SECRET_KEY"],
|
||||||
@ -144,15 +145,17 @@ class User(UserMixin, db.Model):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def verify_reset_password_token(token):
|
def verify_reset_password_token(token):
|
||||||
|
"Vérification du token de reéinitialisation du mot de passe"
|
||||||
try:
|
try:
|
||||||
id = jwt.decode(
|
user_id = jwt.decode(
|
||||||
token, current_app.config["SECRET_KEY"], algorithms=["HS256"]
|
token, current_app.config["SECRET_KEY"], algorithms=["HS256"]
|
||||||
)["reset_password"]
|
)["reset_password"]
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
return User.query.get(id)
|
return User.query.get(user_id)
|
||||||
|
|
||||||
def to_dict(self, include_email=True):
|
def to_dict(self, include_email=True):
|
||||||
|
"""l'utilisateur comme un dict, avec des champs supplémentaires"""
|
||||||
data = {
|
data = {
|
||||||
"date_expiration": self.date_expiration.isoformat() + "Z"
|
"date_expiration": self.date_expiration.isoformat() + "Z"
|
||||||
if self.date_expiration
|
if self.date_expiration
|
||||||
@ -472,5 +475,5 @@ def get_super_admin():
|
|||||||
|
|
||||||
|
|
||||||
@login.user_loader
|
@login.user_loader
|
||||||
def load_user(id):
|
def load_user(uid):
|
||||||
return User.query.get(int(id))
|
return User.query.get(int(uid))
|
||||||
|
Loading…
Reference in New Issue
Block a user