diff --git a/api/controllers/console/workspace/account.py b/api/controllers/console/workspace/account.py index fd4884f473..cd23b98c0b 100644 --- a/api/controllers/console/workspace/account.py +++ b/api/controllers/console/workspace/account.py @@ -489,6 +489,9 @@ class ChangeEmailResetApi(Resource): AccountService.revoke_change_email_token(args["token"]) + if not AccountService.check_email_unique(args["new_email"]): + raise EmailAlreadyInUseError() + old_email = reset_data.get("old_email", "") if current_user.email != old_email: raise AccountNotFound() @@ -504,11 +507,8 @@ class CheckEmailUnique(Resource): parser = reqparse.RequestParser() parser.add_argument("email", type=email, required=True, location="json") args = parser.parse_args() - with Session(db.engine) as session: - # check if email is already in use - account = session.execute(select(Account).filter_by(email=args["email"])).scalar_one_or_none() - if account is not None: - raise EmailAlreadyInUseError() + if not AccountService.check_email_unique(args["email"]): + raise EmailAlreadyInUseError() return {"result": "success"} diff --git a/api/services/account_service.py b/api/services/account_service.py index 49e1c8bc2d..fc3e4f4d4c 100644 --- a/api/services/account_service.py +++ b/api/services/account_service.py @@ -807,6 +807,10 @@ class AccountService: return False + @staticmethod + def check_email_unique(email: str) -> bool: + return db.session.query(Account).filter_by(email=email).first() is None + class TenantService: @staticmethod diff --git a/api/templates/change_mail_confirm_new_template_en-US.html b/api/templates/change_mail_confirm_new_template_en-US.html index 65d3e882d9..7e2ccca493 100644 --- a/api/templates/change_mail_confirm_new_template_en-US.html +++ b/api/templates/change_mail_confirm_new_template_en-US.html @@ -85,4 +85,5 @@ - \ No newline at end of file + + diff --git a/api/templates/change_mail_confirm_new_template_zh-CN.html b/api/templates/change_mail_confirm_new_template_zh-CN.html index 0139c645cc..ccaaf60255 100644 --- a/api/templates/change_mail_confirm_new_template_zh-CN.html +++ b/api/templates/change_mail_confirm_new_template_zh-CN.html @@ -85,4 +85,5 @@ - \ No newline at end of file + + diff --git a/api/templates/change_mail_confirm_old_template_en-US.html b/api/templates/change_mail_confirm_old_template_en-US.html index d7db4f1314..e5a1cac373 100644 --- a/api/templates/change_mail_confirm_old_template_en-US.html +++ b/api/templates/change_mail_confirm_old_template_en-US.html @@ -85,4 +85,5 @@ - \ No newline at end of file + + diff --git a/api/templates/change_mail_confirm_old_template_zh-CN.html b/api/templates/change_mail_confirm_old_template_zh-CN.html index 901ae55ddc..ce1deccc9e 100644 --- a/api/templates/change_mail_confirm_old_template_zh-CN.html +++ b/api/templates/change_mail_confirm_old_template_zh-CN.html @@ -85,4 +85,5 @@ - \ No newline at end of file + + diff --git a/api/templates/without-brand/change_mail_confirm_new_template_en-US.html b/api/templates/without-brand/change_mail_confirm_new_template_en-US.html index 60c12246a0..ccac8509bf 100644 --- a/api/templates/without-brand/change_mail_confirm_new_template_en-US.html +++ b/api/templates/without-brand/change_mail_confirm_new_template_en-US.html @@ -81,4 +81,5 @@ - \ No newline at end of file + + diff --git a/api/templates/without-brand/change_mail_confirm_new_template_zh-CN.html b/api/templates/without-brand/change_mail_confirm_new_template_zh-CN.html index 4a8de1e0e7..cd0418c236 100644 --- a/api/templates/without-brand/change_mail_confirm_new_template_zh-CN.html +++ b/api/templates/without-brand/change_mail_confirm_new_template_zh-CN.html @@ -81,4 +81,5 @@ - \ No newline at end of file + + diff --git a/api/templates/without-brand/change_mail_confirm_old_template_en-US.html b/api/templates/without-brand/change_mail_confirm_old_template_en-US.html index 7f45d61427..d267f07da9 100644 --- a/api/templates/without-brand/change_mail_confirm_old_template_en-US.html +++ b/api/templates/without-brand/change_mail_confirm_old_template_en-US.html @@ -81,4 +81,5 @@ - \ No newline at end of file + + diff --git a/api/templates/without-brand/change_mail_confirm_old_template_zh-CN.html b/api/templates/without-brand/change_mail_confirm_old_template_zh-CN.html index 9f8bc5d1bf..e9cdd315de 100644 --- a/api/templates/without-brand/change_mail_confirm_old_template_zh-CN.html +++ b/api/templates/without-brand/change_mail_confirm_old_template_zh-CN.html @@ -81,4 +81,5 @@ - \ No newline at end of file + +