diff --git a/backend/bot/app/web/webapp/account.py b/backend/bot/app/web/webapp/account.py index 479595a..cf813af 100644 --- a/backend/bot/app/web/webapp/account.py +++ b/backend/bot/app/web/webapp/account.py @@ -11,9 +11,20 @@ from .common import _invalidate_webapp_user_caches from .telegram_notifications import _probe_telegram_notifications_for_user_id +def _email_auth_enabled(settings: Settings) -> bool: + return bool(getattr(settings, "email_auth_configured", True)) + + +def _email_auth_not_configured_response() -> web.Response: + return _json_error(503, "email_auth_not_configured", "Email auth is not configured") + + async def account_email_request_route(request: web.Request) -> web.Response: user_id = _require_user_id(request) settings: Settings = request.app["settings"] + if not _email_auth_enabled(settings): + return _email_auth_not_configured_response() + payload = await _read_json(request) email_payload, validation_error = _validate_model_payload(WebAppEmailPayload, payload) if validation_error: @@ -40,6 +51,10 @@ async def account_email_request_route(request: web.Request) -> web.Response: async def account_email_verify_route(request: web.Request) -> web.Response: user_id = _require_user_id(request) + settings: Settings = request.app["settings"] + if not _email_auth_enabled(settings): + return _email_auth_not_configured_response() + rate_limit_response = await _enforce_webapp_rate_limit( request, user_id=user_id, @@ -55,7 +70,6 @@ async def account_email_verify_route(request: web.Request) -> web.Response: email = email_payload.email code = str(email_payload.code or "") email_service: EmailAuthService = request.app["email_auth_service"] - settings: Settings = request.app["settings"] async_session_factory: sessionmaker = request.app["async_session_factory"] merge_notice: Optional[Dict[str, Any]] = None source_panel_uuid: Optional[str] = None @@ -210,6 +224,9 @@ async def account_email_verify_route(request: web.Request) -> web.Response: async def account_password_request_route(request: web.Request) -> web.Response: user_id = _require_user_id(request) settings: Settings = request.app["settings"] + if not _email_auth_enabled(settings): + return _email_auth_not_configured_response() + async_session_factory: sessionmaker = request.app["async_session_factory"] async with async_session_factory() as session: @@ -232,6 +249,10 @@ async def account_password_request_route(request: web.Request) -> web.Response: async def account_password_confirm_route(request: web.Request) -> web.Response: user_id = _require_user_id(request) + settings = request.app.get("settings") + if not _email_auth_enabled(settings): + return _email_auth_not_configured_response() + payload = await _read_json(request) password_payload, validation_error = _validate_model_payload(WebAppSetPasswordPayload, payload) if validation_error: diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 914a15a..e8ae5c6 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -375,6 +375,9 @@ $: plans = data?.plans?.length ? data.plans : MOCK_SOURCE.data.plans; $: methods = data?.payment_methods?.length ? data.payment_methods : []; $: appSettings = data?.settings || MOCK_SOURCE.data.settings; + $: rawEmailAuthEnabled = + data?.settings?.email_auth_enabled ?? appSettings?.email_auth_enabled ?? CFG.emailAuthEnabled; + $: emailAuthEnabled = rawEmailAuthEnabled !== false && rawEmailAuthEnabled !== "false"; $: subscriptionPurchaseDescription = String( appSettings?.subscription_purchase_description || "" ).trim(); @@ -489,7 +492,7 @@ ); $: telegramNotificationsStartLink = String(user?.telegram_notifications_start_link || ""); $: hasUnlinkedIdentity = - !user?.telegram_linked || !user?.email || telegramNotificationsNeedPrompt; + !user?.telegram_linked || (emailAuthEnabled && !user?.email) || telegramNotificationsNeedPrompt; $: referralBonusDetails = Array.isArray(referral?.bonus_details) ? referral.bonus_details : []; $: referralWelcomeBonusDays = Math.max(0, Number(referral?.welcome_bonus_days || 0)); $: referralOneBonusPerReferee = Boolean(referral?.one_bonus_per_referee); @@ -533,9 +536,15 @@ changeConfirmOpen || topupModalOpen || deviceTopupModalOpen || - linkEmailOpen || - setPasswordOpen + (emailAuthEnabled && linkEmailOpen) || + (emailAuthEnabled && setPasswordOpen) ); + $: if (!emailAuthEnabled && linkEmailOpen) { + accountStore.closeLinkEmailDialog(); + } + $: if (!emailAuthEnabled && setPasswordOpen) { + accountStore.closeSetPasswordDialog(); + } $: if (!tariffMode && !$billingStore.selectedPlan && plans.length) { billingStore.update((s) => ({ ...s, selectedPlan: plans[Math.min(1, plans.length - 1)] })); } @@ -1163,10 +1172,16 @@ } function openSettingsLinkEmailDialog() { + if (!emailAuthEnabled) return; const authDemo = MOCK_SOURCE.data?.auth_demo || {}; accountStore.openLinkEmailDialog(demoAuthLogin ? authDemo.email || "3252a8@proton.me" : ""); } + function openSettingsSetPasswordDialog() { + if (!emailAuthEnabled) return; + accountStore.openSetPasswordDialog(); + } + async function linkTelegramFromSettings() { if (!demoAuthLogin) { await accountStore.linkTelegramAccount(() => telegramMiniAppInitData); @@ -2597,6 +2612,7 @@ {}; export let t = (key) => key; export let updateAccountLanguage = () => {}; + + $: showEmailAccount = emailAuthEnabled || Boolean(user?.email);
@@ -68,7 +71,9 @@
{telegramProfileName} - {profileEmail} + {#if showEmailAccount} + {profileEmail} + {/if} {profileTelegramId}
@@ -122,7 +127,7 @@ {t("wa_settings_email_linked_title")} {user?.email} - {#if user?.email_verified} + {#if emailAuthEnabled && user?.email_verified}