Skip to content

Commit

Permalink
feat: add init login type
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouhaoJiang committed Oct 17, 2024
1 parent abe6a1b commit be4b62d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
9 changes: 7 additions & 2 deletions api/controllers/console/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
InvalidEmailError,
InvalidTokenError,
)
from controllers.console.error import EmailSendIpLimitError, NotAllowedCreateWorkspace, NotAllowedRegister
from controllers.console.error import (
AccountBannedOrClosedError,
EmailSendIpLimitError,
NotAllowedCreateWorkspace,
NotAllowedRegister,
)
from controllers.console.setup import setup_required
from events.tenant_event import tenant_was_created
from libs.helper import email, extract_remote_ip
Expand Down Expand Up @@ -62,7 +67,7 @@ def post(self):
else:
account = AccountService.authenticate(args["email"], args["password"])
except services.errors.account.AccountLoginError:
raise NotAllowedRegister()
raise AccountBannedOrClosedError()
except services.errors.account.AccountPasswordError:
AccountService.add_login_error_rate_limit(args["email"])
raise EmailOrPasswordMismatchError()
Expand Down
8 changes: 7 additions & 1 deletion api/controllers/console/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ class NotAllowedCreateWorkspace(BaseHTTPException):
code = 400


class AccountBannedOrClosedError(BaseHTTPException):
error_code = "account_banned_or_closed"
description = "Account is banned or closed."
code = 400


class NotAllowedRegister(BaseHTTPException):
error_code = "unauthorized"
description = "Account not found."
description = "account_not_found"
code = 400


Expand Down
11 changes: 11 additions & 0 deletions api/services/account_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
TenantStatus,
)
from models.model import DifySetup
from services.enterprise.enterprise_service import EnterpriseService
from services.errors.account import (
AccountAlreadyInTenantError,
AccountLoginError,
Expand Down Expand Up @@ -953,3 +954,13 @@ def _get_invitation_by_token(
def _generate_refresh_token(length: int = 64):
token = secrets.token_hex(length)
return token


class InitLoginType:
@staticmethod
def init_login_type():
enterprise_info = EnterpriseService.get_info()
dify_config.ENABLE_EMAIL_CODE_LOGIN = enterprise_info["enable_email_code_login"]
dify_config.ENABLE_EMAIL_PASSWORD_LOGIN = enterprise_info["enable_email_password_login"]
dify_config.ALLOW_REGISTER = enterprise_info["is_allow_register"]
dify_config.ALLOW_CREATE_WORKSPACE = enterprise_info["is_allow_create_workspace"]
2 changes: 2 additions & 0 deletions api/services/feature_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pydantic import BaseModel, ConfigDict

from configs import dify_config
from services.account_service import InitLoginType
from services.billing_service import BillingService
from services.enterprise.enterprise_service import EnterpriseService

Expand Down Expand Up @@ -126,6 +127,7 @@ def _fulfill_params_from_billing_api(cls, features: FeatureModel, tenant_id: str

@classmethod
def _fulfill_params_from_enterprise(cls, features):
InitLoginType.init_login_type()
enterprise_info = EnterpriseService.get_info()

features.sso_enforced_for_signin = enterprise_info["sso_enforced_for_signin"]
Expand Down

0 comments on commit be4b62d

Please sign in to comment.