mirror of
https://github.com/janeczku/calibre-web
synced 2025-10-19 01:27:40 +00:00
Test Email now send to user's email address (#834)
Added forgot/reset password routine (#1098, #1063)
This commit is contained in:
@@ -41,6 +41,7 @@ from flask_babel import gettext as _
|
||||
from flask_login import current_user
|
||||
from sqlalchemy.sql.expression import true, false, and_, or_, text, func
|
||||
from werkzeug.datastructures import Headers
|
||||
from werkzeug.security import generate_password_hash
|
||||
|
||||
try:
|
||||
from urllib.parse import quote
|
||||
@@ -407,6 +408,19 @@ def delete_book_gdrive(book, book_format):
|
||||
return error
|
||||
|
||||
|
||||
def reset_password(user_id):
|
||||
existing_user = ub.session.query(ub.User).filter(ub.User.id == user_id).first()
|
||||
password = generate_random_password()
|
||||
existing_user.password = generate_password_hash(password)
|
||||
try:
|
||||
ub.session.commit()
|
||||
send_registration_mail(existing_user.email, existing_user.nickname, password, True)
|
||||
return (1, existing_user.nickname)
|
||||
except Exception:
|
||||
ub.session.rollback()
|
||||
return (0, None)
|
||||
|
||||
|
||||
def generate_random_password():
|
||||
s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%&*()?"
|
||||
passlen = 8
|
||||
|
Reference in New Issue
Block a user