openreplay/api/chalicelib/core/reset_password.py
Kraiem Taha Yassine 8226e66299
Api v1.14.0 (#1391)
* refactored(chalice): refactored restore user
refactored(chalice): refactored add user

* fix(chalice): allow FastAPI to handel async automatically
fix(chalice): EE support of multiworkers
refactor(chalice): cleaned SSO

* fix(chalice): allow FastAPI to handel async automatically

* feat(DB): associate sessions to feature-flags

* feat(DB): CH associate sessions to feature-flags
2023-07-06 18:13:06 +02:00

19 lines
951 B
Python

import schemas
from chalicelib.core import users
from chalicelib.utils import email_helper, captcha, helper, smtp
def reset(data: schemas.ForgetPasswordPayloadSchema):
print(f"====================== reset password {data.email}")
if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response):
print("error: Invalid captcha.")
return {"errors": ["Invalid captcha."]}
if not smtp.has_smtp():
return {"errors": ["no SMTP configuration found, you can ask your admin to reset your password"]}
a_users = users.get_by_email_only(data.email)
if a_users:
invitation_link = users.generate_new_invitation(user_id=a_users["userId"])
email_helper.send_forgot_password(recipient=data.email, invitation_link=invitation_link)
else:
print(f"!!!invalid email address [{data.email}]")
return {"data": {"state": "A reset link will be sent if this email exists in our system."}}