From 50a3c448f529b05a6e2ea5aa60b2bc85404f697d Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Thu, 2 Dec 2021 20:32:13 +0100 Subject: [PATCH] feat(api): changed reset password EE --- ee/api/chalicelib/core/reset_password.py | 31 ++++++++---------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/ee/api/chalicelib/core/reset_password.py b/ee/api/chalicelib/core/reset_password.py index 3a636c967..c1ac1fe65 100644 --- a/ee/api/chalicelib/core/reset_password.py +++ b/ee/api/chalicelib/core/reset_password.py @@ -1,9 +1,9 @@ -from chalicelib.utils import email_helper, captcha, helper from chalicelib.core import users +from chalicelib.utils import email_helper, captcha, helper -def step1(data): - print("====================== reset password 1 ===============") +def reset(data): + print("====================== reset password ===============") print(data) if helper.allow_captcha() and not captcha.is_valid(data["g-recaptcha-response"]): print("error: Invalid captcha.") @@ -11,26 +11,15 @@ def step1(data): if "email" not in data: return {"errors": ["email not found in body"]} - a_users = users.get_by_email_only(data["email"]) - if len(a_users) > 1: - print(f"multiple users found for [{data['email']}] please contact our support") - return {"errors": ["multiple users, please contact our support"]} - elif len(a_users) == 1: - a_users = a_users[0] - invitation_link = users.generate_new_invitation(user_id=a_users["id"]) + a_user = users.get_by_email_only(data["email"]) + if a_user is not None: + # ---FOR SSO + if a_user.get("origin") is not None and a_user.get("hasPassword", False) is False: + return {"errors": ["Please use your SSO to login"]} + # ---------- + invitation_link = users.generate_new_invitation(user_id=a_user["id"]) email_helper.send_forgot_password(recipient=data["email"], invitation_link=invitation_link) else: print(f"invalid email address [{data['email']}]") return {"errors": ["invalid email address"]} return {"data": {"state": "success"}} - -# def step2(data): -# print("====================== change password 2 ===============") -# user = users.get_by_email_reset(data["email"], data["code"]) -# if not user: -# print("error: wrong email or reset code") -# return {"errors": ["wrong email or reset code"]} -# users.update(tenant_id=user["tenantId"], user_id=user["id"], -# changes={"token": None, "password": data["password"], "generatedPassword": False, -# "verifiedEmail": True}) -# return {"data": {"state": "success"}}