This commit is contained in:
parent
f86e3b4725
commit
b0c8cfb024
@ -13,13 +13,12 @@ import {
|
||||
} from '@workspace/airo-ui/components/form';
|
||||
import { Input } from '@workspace/airo-ui/components/input';
|
||||
import { Icon } from '@workspace/airo-ui/custom-components/icon';
|
||||
import { Markdown } from '@workspace/airo-ui/custom-components/markdown';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { Dispatch, SetStateAction, useEffect, useRef, useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { z } from 'zod';
|
||||
import SendCode from '../send-code';
|
||||
import CloudFlareTurnstile, { TurnstileRef } from '../turnstile';
|
||||
import { TurnstileRef } from '../turnstile';
|
||||
|
||||
export default function RegisterForm({
|
||||
loading,
|
||||
@ -35,35 +34,15 @@ export default function RegisterForm({
|
||||
onSwitchForm: Dispatch<SetStateAction<'register' | 'reset' | 'login'>>;
|
||||
}) {
|
||||
const { common } = useGlobalStore();
|
||||
const { verify, auth, invite } = common;
|
||||
const router = useRouter();
|
||||
const handleCheckUser = async (email: string) => {
|
||||
try {
|
||||
if (!auth.email.enable_domain_suffix) return true;
|
||||
const domain = email.split('@')[1];
|
||||
const isValid = auth.email?.domain_suffix_list.split('\n').includes(domain || '');
|
||||
return isValid;
|
||||
} catch (error) {
|
||||
console.log('Error checking user:', error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const formSchema = z
|
||||
.object({
|
||||
email: z.string().email('请输入有效的电子邮件地址。').refine(handleCheckUser, {
|
||||
message: '电子邮件域名不在允许的白名单中。',
|
||||
}),
|
||||
email: z.string().email('请输入有效的电子邮件地址。'),
|
||||
password: z.string().min(1, '请输入密码'), // 必填提示
|
||||
repeat_password: z.string().min(1, '请重复输入密码'), // 必填
|
||||
code: auth.email.enable_verify
|
||||
? z.string().min(1, '请输入验证码') // 必填
|
||||
: z.string().nullish(),
|
||||
invite: invite.forced_invite ? z.string().min(1, '请输入邀请码') : z.string().nullish(),
|
||||
cf_token:
|
||||
verify.enable_register_verify && verify.turnstile_site_key
|
||||
? z.string()
|
||||
: z.string().nullish(),
|
||||
code: z.string().min(1, '请输入验证码'), // 必填,
|
||||
invite: z.string().nullish(),
|
||||
})
|
||||
.superRefine(({ password, repeat_password }, ctx) => {
|
||||
if (password !== repeat_password) {
|
||||
@ -103,9 +82,6 @@ export default function RegisterForm({
|
||||
<>
|
||||
<div className={'h-[84px] text-2xl font-bold leading-[84px]'}>线路优化</div>
|
||||
|
||||
{auth.register.stop_register ? (
|
||||
<Markdown>尊敬的用户,您好</Markdown>
|
||||
) : (
|
||||
<Form {...form}>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className='grid gap-5'>
|
||||
@ -161,7 +137,7 @@ export default function RegisterForm({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
{auth.email.enable_verify && (
|
||||
{
|
||||
<FormField
|
||||
control={form.control}
|
||||
name='code'
|
||||
@ -191,7 +167,7 @@ export default function RegisterForm({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name='invite'
|
||||
@ -210,20 +186,6 @@ export default function RegisterForm({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
{verify.enable_register_verify && (
|
||||
<FormField
|
||||
control={form.control}
|
||||
name='cf_token'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<CloudFlareTurnstile id='register' {...field} ref={turnstile} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className='text-right text-sm'>
|
||||
@ -251,7 +213,6 @@ export default function RegisterForm({
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ export default function Providers({
|
||||
|
||||
const { setCommon, setUser } = useGlobalStore();
|
||||
const pathname = usePathname();
|
||||
const whiteList = ['/'];
|
||||
const whiteList = ['/', '/register'];
|
||||
const isWhite = whiteList.includes(pathname);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user