feat(api): changed reset password EE
This commit is contained in:
parent
f45a9e5112
commit
50a3c448f5
1 changed files with 10 additions and 21 deletions
|
|
@ -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"}}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue