From ef988371c724dbecfc379c0bebc21f10a5c21e2c Mon Sep 17 00:00:00 2001 From: Joe <1264204425@qq.com> Date: Mon, 9 Sep 2024 17:27:40 +0800 Subject: [PATCH] fix: OAuth error when not allow register --- api/controllers/console/auth/login.py | 2 +- api/controllers/console/auth/oauth.py | 3 ++- api/controllers/console/error.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/controllers/console/auth/login.py b/api/controllers/console/auth/login.py index 8e4f5927d8..139c6a06a9 100644 --- a/api/controllers/console/auth/login.py +++ b/api/controllers/console/auth/login.py @@ -42,7 +42,7 @@ class LoginApi(Resource): raise PasswordMismatchError() except services.errors.account.AccountNotFound: if not dify_config.ALLOW_REGISTER: - raise NotAllowedCreateWorkspace() + raise NotAllowedRegister() token = AccountService.send_reset_password_email(email=args["email"]) return {"result": "fail", "data": token, "message": "account_not_found"} diff --git a/api/controllers/console/auth/oauth.py b/api/controllers/console/auth/oauth.py index aba782c181..e387cf22a3 100644 --- a/api/controllers/console/auth/oauth.py +++ b/api/controllers/console/auth/oauth.py @@ -9,6 +9,7 @@ from werkzeug.exceptions import Unauthorized from configs import dify_config from constants.languages import languages +from controllers.console.error import NotAllowedRegister from extensions.ext_database import db from libs.helper import get_remote_ip from libs.oauth import GitHubOAuth, GoogleOAuth, OAuthUserInfo @@ -124,7 +125,7 @@ def _generate_account(provider: str, user_info: OAuthUserInfo): if not account: if not dify_config.ALLOW_REGISTER: - raise Unauthorized("Account not found") + raise NotAllowedRegister() account_name = user_info.name if user_info.name else "Dify" account = RegisterService.register( email=user_info.email, name=account_name, password=None, open_id=user_info.id, provider=provider diff --git a/api/controllers/console/error.py b/api/controllers/console/error.py index 3cc7bf9603..1d1a93a5c2 100644 --- a/api/controllers/console/error.py +++ b/api/controllers/console/error.py @@ -51,4 +51,4 @@ class NotAllowedCreateWorkspace(BaseHTTPException): class NotAllowedRegister(BaseHTTPException): error_code = "unauthorized" description = "Account not found." - code = 404 + code = 400