From 3e83be941c346722eeab63d027d405ad6fb86913 Mon Sep 17 00:00:00 2001 From: Joe <1264204425@qq.com> Date: Sat, 14 Sep 2024 16:48:24 +0800 Subject: [PATCH] feat: add fulfill_login_params_from_env --- api/configs/feature/__init__.py | 4 ++-- api/services/feature_service.py | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index 86de62dddd..7dbb80584a 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -611,7 +611,7 @@ class PositionConfig(BaseSettings): class LoginConfig(BaseSettings): ENABLE_EMAIL_CODE_LOGIN: bool = Field( description="whether to enable email code login", - default=True, + default=False, ) ENABLE_EMAIL_PASSWORD_LOGIN: bool = Field( description="whether to enable email password login", @@ -619,7 +619,7 @@ class LoginConfig(BaseSettings): ) ENABLE_SOCIAL_OAUTH_LOGIN: bool = Field( description="whether to enable github/google oauth login", - default=True, + default=False, ) EMAIL_CODE_LOGIN_TOKEN_EXPIRY_HOURS: PositiveFloat = Field( description="expiry time in hours for email code login token", diff --git a/api/services/feature_service.py b/api/services/feature_service.py index 6a7eb8c34a..3b707d4bee 100644 --- a/api/services/feature_service.py +++ b/api/services/feature_service.py @@ -42,11 +42,11 @@ class SystemFeatureModel(BaseModel): sso_enforced_for_web: bool = False sso_enforced_for_web_protocol: str = "" enable_web_sso_switch_component: bool = False - enable_email_code_login: bool = dify_config.ENABLE_EMAIL_CODE_LOGIN - enable_email_password_login: bool = dify_config.ENABLE_EMAIL_PASSWORD_LOGIN - enable_social_oauth_login: bool = dify_config.ENABLE_SOCIAL_OAUTH_LOGIN - is_allow_register: bool = dify_config.ALLOW_REGISTER - is_allow_create_workspace: bool = dify_config.ALLOW_CREATE_WORKSPACE + enable_email_code_login: bool = False + enable_email_password_login: bool = True + enable_social_oauth_login: bool = False + is_allow_register: bool = True + is_allow_create_workspace: bool = True class FeatureService: @@ -65,12 +65,22 @@ class FeatureService: def get_system_features(cls) -> SystemFeatureModel: system_features = SystemFeatureModel() + cls.__fulfill_login_params_from_env(system_features) + if dify_config.ENTERPRISE_ENABLED: system_features.enable_web_sso_switch_component = True cls._fulfill_params_from_enterprise(system_features) return system_features + @classmethod + def __fulfill_login_params_from_env(cls, features: FeatureModel): + features.enable_email_code_login = dify_config.ENABLE_EMAIL_CODE_LOGIN + features.enable_email_password_login = dify_config.ENABLE_EMAIL_PASSWORD_LOGIN + features.enable_social_oauth_login = dify_config.ENABLE_SOCIAL_OAUTH_LOGIN + features.is_allow_register = dify_config.ALLOW_REGISTER + features.is_allow_create_workspace = dify_config.ALLOW_CREATE_WORKSPACE + @classmethod def _fulfill_params_from_env(cls, features: FeatureModel): features.can_replace_logo = dify_config.CAN_REPLACE_LOGO