Skip to content

Commit 83bf1c9

Browse files
committed
fix: email code login redirect
1 parent 3c747bc commit 83bf1c9

1 file changed

Lines changed: 6 additions & 57 deletions

File tree

api/controllers/console/auth/login.py

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ def post(self):
3535
try:
3636
account = AccountService.authenticate(args["email"], args["password"])
3737
except services.errors.account.AccountLoginError as e:
38-
return {"code": "unauthorized", "message": str(e)}, 401
38+
if dify_config.ALLOW_REGISTER:
39+
token = AccountService.send_reset_password_email(email=args["email"])
40+
return redirect(f"{dify_config.CONSOLE_WEB_URL}/reset-password?token={token}")
41+
else:
42+
return {"code": "unauthorized", "message": str(e)}, 401
3943

4044
# SELF_HOSTED only have one workspace
4145
tenants = TenantService.get_join_tenants(account)
@@ -79,57 +83,6 @@ def post(self):
7983
return {"result": "success", "data": token}
8084

8185

82-
class ResetPasswordApi(Resource):
83-
@setup_required
84-
def get(self):
85-
parser = reqparse.RequestParser()
86-
parser.add_argument("email", type=email, required=True, location="json")
87-
args = parser.parse_args()
88-
89-
# import mailchimp_transactional as MailchimpTransactional
90-
# from mailchimp_transactional.api_client import ApiClientError
91-
92-
# account = {'email': args['email']}
93-
# account = AccountService.get_by_email(args['email'])
94-
# if account is None:
95-
# raise ValueError('Email not found')
96-
# new_password = AccountService.generate_password()
97-
# AccountService.update_password(account, new_password)
98-
99-
# todo: Send email
100-
# MAILCHIMP_API_KEY = dify_config.MAILCHIMP_TRANSACTIONAL_API_KEY
101-
# mailchimp = MailchimpTransactional(MAILCHIMP_API_KEY)
102-
103-
# message = {
104-
# 'from_email': '[email protected]',
105-
# 'to': [{'email': account['email']}],
106-
# 'subject': 'Reset your Dify password',
107-
# 'html': """
108-
# <p>Dear User,</p>
109-
# <p>The Dify team has generated a new password for you, details as follows:</p>
110-
# <p><strong>{new_password}</strong></p>
111-
# <p>Please change your password to log in as soon as possible.</p>
112-
# <p>Regards,</p>
113-
# <p>The Dify Team</p>
114-
# """
115-
# }
116-
117-
# response = mailchimp.messages.send({
118-
# 'message': message,
119-
# # required for transactional email
120-
# ' settings': {
121-
# 'sandbox_mode': dify_config.MAILCHIMP_SANDBOX_MODE,
122-
# },
123-
# })
124-
125-
# Check if MSG was sent
126-
# if response.status_code != 200:
127-
# # handle error
128-
# pass
129-
130-
return {"result": "success"}
131-
132-
13386
class EmailCodeLoginSendEmailApi(Resource):
13487
@setup_required
13588
def post(self):
@@ -139,11 +92,7 @@ def post(self):
13992

14093
account = AccountService.get_user_through_email(args["email"])
14194
if account is None:
142-
if dify_config.ALLOW_REGISTER:
143-
token = AccountService.send_reset_password_email(email=args["email"])
144-
return redirect(f"{dify_config.CONSOLE_WEB_URL}/reset-password?token={token}")
145-
else:
146-
raise InvalidEmailError()
95+
token = AccountService.send_email_code_login_email(email=args["email"])
14796
else:
14897
token = AccountService.send_email_code_login_email(account=account)
14998

0 commit comments

Comments
 (0)