fix: hide email prompts when auth is disabled
This commit is contained in:
@@ -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:
|
||||
|
||||
+22
-6
@@ -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 @@
|
||||
<SettingsScreen
|
||||
{currentLang}
|
||||
{currentLanguageOption}
|
||||
{emailAuthEnabled}
|
||||
{emailLinkStatus}
|
||||
{isAdmin}
|
||||
{languageBusy}
|
||||
@@ -2625,7 +2641,7 @@
|
||||
{openAdminPanel}
|
||||
{openExternalLink}
|
||||
openLinkEmailDialog={openSettingsLinkEmailDialog}
|
||||
openSetPasswordDialog={accountStore.openSetPasswordDialog}
|
||||
openSetPasswordDialog={openSettingsSetPasswordDialog}
|
||||
{setLanguageMenuOpen}
|
||||
{t}
|
||||
updateAccountLanguage={accountStore.updateAccountLanguage}
|
||||
@@ -2654,13 +2670,13 @@
|
||||
{disconnectDevice}
|
||||
{linkEmailBusy}
|
||||
{linkEmailIsError}
|
||||
{linkEmailOpen}
|
||||
linkEmailOpen={emailAuthEnabled && linkEmailOpen}
|
||||
{linkEmailPending}
|
||||
{linkEmailResendCooldown}
|
||||
{linkEmailStatus}
|
||||
{setPasswordBusy}
|
||||
{setPasswordIsError}
|
||||
{setPasswordOpen}
|
||||
setPasswordOpen={emailAuthEnabled && setPasswordOpen}
|
||||
{setPasswordPending}
|
||||
{setPasswordResendCooldown}
|
||||
{setPasswordStatus}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
export let currentLang = "ru";
|
||||
export let currentLanguageOption = null;
|
||||
export let emailAuthEnabled = true;
|
||||
export let emailLinkStatus = "";
|
||||
export let isAdmin = false;
|
||||
export let languageBusy = false;
|
||||
@@ -50,6 +51,8 @@
|
||||
export let setLanguageMenuOpen = () => {};
|
||||
export let t = (key) => key;
|
||||
export let updateAccountLanguage = () => {};
|
||||
|
||||
$: showEmailAccount = emailAuthEnabled || Boolean(user?.email);
|
||||
</script>
|
||||
|
||||
<main class="content with-nav">
|
||||
@@ -68,7 +71,9 @@
|
||||
</div>
|
||||
<div class="settings-profile-meta">
|
||||
<strong>{telegramProfileName}</strong>
|
||||
<small>{profileEmail}</small>
|
||||
{#if showEmailAccount}
|
||||
<small>{profileEmail}</small>
|
||||
{/if}
|
||||
<small>{profileTelegramId}</small>
|
||||
</div>
|
||||
</Card>
|
||||
@@ -122,7 +127,7 @@
|
||||
<strong>{t("wa_settings_email_linked_title")}</strong>
|
||||
<small>{user?.email}</small>
|
||||
</span>
|
||||
{#if user?.email_verified}
|
||||
{#if emailAuthEnabled && user?.email_verified}
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
@@ -135,7 +140,7 @@
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
{:else if emailAuthEnabled}
|
||||
<button
|
||||
class="settings-row attention-wrap"
|
||||
type="button"
|
||||
|
||||
@@ -70,6 +70,30 @@ class RequestSecurityTests(unittest.IsolatedAsyncioTestCase):
|
||||
self.assertEqual(response.status, 403)
|
||||
request.json.assert_not_awaited()
|
||||
|
||||
async def test_account_email_routes_reject_when_email_auth_disabled(self):
|
||||
settings = SimpleNamespace(email_auth_configured=False)
|
||||
handlers = [
|
||||
account_routes.account_email_request_route,
|
||||
account_routes.account_email_verify_route,
|
||||
account_routes.account_password_request_route,
|
||||
account_routes.account_password_confirm_route,
|
||||
]
|
||||
|
||||
with patch.object(account_routes, "_require_user_id", return_value=42):
|
||||
for handler in handlers:
|
||||
request = SimpleNamespace(
|
||||
app={"settings": settings},
|
||||
json=AsyncMock(side_effect=AssertionError("request.json() must not be called")),
|
||||
headers={},
|
||||
cookies={},
|
||||
)
|
||||
|
||||
response = await handler(request)
|
||||
|
||||
self.assertEqual(response.status, 503, handler.__name__)
|
||||
self.assertIn("email_auth_not_configured", response.text)
|
||||
request.json.assert_not_awaited()
|
||||
|
||||
|
||||
class FreeKassaServiceTests(unittest.TestCase):
|
||||
def _make_service(self) -> FreeKassaService:
|
||||
|
||||
Reference in New Issue
Block a user