From 47f2c5853cd65710494eded81fd980a6bfd2164d Mon Sep 17 00:00:00 2001 From: "web@ppanel" Date: Sat, 8 Feb 2025 23:58:03 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(auth):=20Update=20authentica?= =?UTF-8?q?tion=20configuration=20and=20localization=20strings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/app/(auth)/email/register-form.tsx | 8 +- apps/admin/app/(auth)/email/reset-form.tsx | 4 +- .../app/dashboard/auth-control/apple/page.tsx | 23 +- .../app/dashboard/auth-control/email/page.tsx | 306 ++++++++++++------ .../dashboard/auth-control/facebook/page.tsx | 23 +- .../dashboard/auth-control/github/page.tsx | 23 +- .../dashboard/auth-control/google/page.tsx | 23 +- .../app/dashboard/auth-control/phone/page.tsx | 240 ++++++++++---- .../dashboard/auth-control/telegram/page.tsx | 23 +- apps/admin/app/dashboard/order/page.tsx | 2 +- apps/admin/app/dashboard/user/[id]/page.tsx | 2 +- .../user/[id]/user-subscription/index.tsx | 6 +- apps/admin/config/use-global.tsx | 41 +-- apps/admin/locales/cs-CZ/phone.json | 11 +- apps/admin/locales/de-DE/phone.json | 11 +- apps/admin/locales/en-US/phone.json | 11 +- apps/admin/locales/es-ES/phone.json | 11 +- apps/admin/locales/es-MX/phone.json | 11 +- apps/admin/locales/fa-IR/phone.json | 11 +- apps/admin/locales/fi-FI/phone.json | 11 +- apps/admin/locales/fr-FR/phone.json | 11 +- apps/admin/locales/hi-IN/phone.json | 11 +- apps/admin/locales/hu-HU/phone.json | 11 +- apps/admin/locales/ja-JP/phone.json | 11 +- apps/admin/locales/ko-KR/phone.json | 11 +- apps/admin/locales/no-NO/phone.json | 11 +- apps/admin/locales/pl-PL/phone.json | 11 +- apps/admin/locales/pt-BR/phone.json | 11 +- apps/admin/locales/ro-RO/phone.json | 11 +- apps/admin/locales/ru-RU/phone.json | 11 +- apps/admin/locales/th-TH/phone.json | 11 +- apps/admin/locales/tr-TR/phone.json | 11 +- apps/admin/locales/uk-UA/phone.json | 11 +- apps/admin/locales/vi-VN/phone.json | 11 +- apps/admin/locales/zh-CN/phone.json | 11 +- apps/admin/locales/zh-HK/phone.json | 11 +- apps/admin/services/admin/typings.d.ts | 3 +- apps/admin/services/common/oauth.ts | 1 - apps/admin/services/common/typings.d.ts | 2 +- apps/user/app/auth/email/register-form.tsx | 8 +- apps/user/app/auth/email/reset-form.tsx | 4 +- apps/user/app/auth/phone/reset-form.tsx | 2 +- apps/user/config/use-global.tsx | 21 +- apps/user/locales/no-NO/common.json | 1 - apps/user/locales/pt-BR/common.json | 1 - apps/user/services/common/typings.d.ts | 2 +- apps/user/services/user/typings.d.ts | 2 +- .../ui/src/custom-components/tag-input.tsx | 18 +- 48 files changed, 749 insertions(+), 293 deletions(-) diff --git a/apps/admin/app/(auth)/email/register-form.tsx b/apps/admin/app/(auth)/email/register-form.tsx index 9ae0c9c..0c408e5 100644 --- a/apps/admin/app/(auth)/email/register-form.tsx +++ b/apps/admin/app/(auth)/email/register-form.tsx @@ -33,8 +33,8 @@ export default function RegisterForm({ try { const domain = email.split('@')[1]; const isValid = - !auth.email.email_enable_verify || - auth.email?.email_domain_suffix_list.split('\n').includes(domain || ''); + !auth.email.enable_verify || + auth.email?.domain_suffix_list.split('\n').includes(domain || ''); return !isValid; } catch (error) { console.log('Error checking user:', error); @@ -52,7 +52,7 @@ export default function RegisterForm({ }), password: z.string(), repeat_password: z.string(), - code: auth.email.email_enable_verify ? z.string() : z.string().nullish(), + code: auth.email.enable_verify ? z.string() : z.string().nullish(), invite: invite.forced_invite ? z.string() : z.string().nullish(), cf_token: verify.enable_register_verify && verify.turnstile_site_key @@ -120,7 +120,7 @@ export default function RegisterForm({ )} /> - {auth.email.email_enable_verify && ( + {auth.email.enable_verify && ( - {auth?.email?.email_enable_verify && ( + {auth?.email?.enable_verify && ( { - const { data } = await getOAuthByPlatform({ - platform: 'apple', + const { data } = await getAuthMethodConfig({ + method: 'apple', }); return data.data; }, }); - async function updateConfig(key: keyof API.UpdateOAuthConfig, value: unknown) { + async function updateConfig(key: keyof API.UpdataAuthMethodConfigRequest, value: unknown) { try { - await updateOAuthConfig({ + await updateAuthMethodConfig({ ...data, [key]: value, - } as API.UpdateOAuthConfig); + } as API.UpdataAuthMethodConfigRequest); toast.success(t('saveSuccess')); refetch(); } catch (error) { @@ -132,8 +132,13 @@ export default function Page() { updateConfig('redirect', value)} + value={data?.config.redirect_url} + onValueBlur={(value) => + updateConfig('config', { + ...data?.config, + redirect_url: value, + }) + } /> diff --git a/apps/admin/app/dashboard/auth-control/email/page.tsx b/apps/admin/app/dashboard/auth-control/email/page.tsx index db5f9ae..dac5c70 100644 --- a/apps/admin/app/dashboard/auth-control/email/page.tsx +++ b/apps/admin/app/dashboard/auth-control/email/page.tsx @@ -1,6 +1,10 @@ 'use client'; -import { getEmailSmtpConfig, testEmailSmtp, updateEmailSmtpConfig } from '@/services/admin/system'; +import { + getAuthMethodConfig, + testEmailSend, + updateAuthMethodConfig, +} from '@/services/admin/authMethod'; import { useQuery } from '@tanstack/react-query'; import { Button } from '@workspace/ui/components/button'; import { @@ -23,14 +27,16 @@ import { toast } from 'sonner'; export default function Page() { const t = useTranslations('email'); - const ref = useRef>({}); + const ref = useRef>({}); const [email, setEmail] = useState(); const { data, refetch, isFetching } = useQuery({ - queryKey: ['getEmailSmtpConfig'], + queryKey: ['getAuthMethodConfig', 'email'], queryFn: async () => { - const { data } = await getEmailSmtpConfig(); - ref.current = data.data as API.EmailSmtpConfig; + const { data } = await getAuthMethodConfig({ + method: 'email', + }); + ref.current = data.data as API.AuthMethodConfig; return data.data; }, }); @@ -38,10 +44,10 @@ export default function Page() { async function updateConfig(key: string, value: unknown) { if (data?.[key] === value) return; try { - await updateEmailSmtpConfig({ + await updateAuthMethodConfig({ ...ref.current, [key]: value, - } as API.EmailSmtpConfig); + } as API.UpdataAuthMethodConfigRequest); toast.success(t('saveSuccess')); refetch(); } catch (error) { @@ -59,94 +65,193 @@ export default function Page() { - {[ - { - key: 'email_enabled', - label: t('enable'), - description: t('enableDescription'), - component: 'switch', - }, - { - key: 'enable_email_verify', - label: t('emailVerification'), - description: t('emailVerificationDescription'), - component: 'switch', - }, - { - key: 'enable_email_domain_suffix', - label: t('emailSuffixWhitelist'), - description: t('emailSuffixWhitelistDescription'), - component: 'switch', - }, - { - key: 'email_domain_suffix_list', - label: t('whitelistSuffixes'), - description: t('whitelistSuffixesDescription'), - component: 'textarea', - }, - { - key: 'email_smtp_host', - label: t('smtpServerAddress'), - description: t('smtpServerAddressDescription'), - }, - { - key: 'email_smtp_port', - label: t('smtpServerPort'), - description: t('smtpServerPortDescription'), - type: 'number', - }, - { - key: 'email_smtp_ssl', - label: t('smtpEncryptionMethod'), - description: t('smtpEncryptionMethodDescription'), - component: 'switch', - }, - { - key: 'email_smtp_user', - label: t('smtpAccount'), - description: t('smtpAccountDescription'), - }, - { - key: 'email_smtp_pass', - label: t('smtpPassword'), - description: t('smtpPasswordDescription'), - type: 'password', - }, - { - key: 'email_smtp_from', - label: t('senderAddress'), - description: t('senderAddressDescription'), - }, - ].map(({ key, label, description, type = 'text', component = 'input' }) => ( - - - -

{description}

-
- - {component === 'input' ? ( - updateConfig(key, value)} - /> - ) : component === 'switch' ? ( - updateConfig(key, checked)} - /> - ) : ( -