This commit is contained in:
parent
b0c8cfb024
commit
f7fa3a46d2
@ -1,10 +1,10 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import EmailAuthForm2 from '@/app/auth/email2/auth-form';
|
import EmailAuthForm1 from '@/app/auth/email2/auth-form';
|
||||||
|
|
||||||
export default function RegisterPage() {
|
export default function RegisterPage() {
|
||||||
return (
|
return (
|
||||||
<div className='container w-full py-8 sm:w-[496px]'>
|
<div className='container w-full py-8 sm:w-[496px]'>
|
||||||
<EmailAuthForm2 isRedirect={true} />
|
<EmailAuthForm1 isRedirect={true} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
45
apps/user/app/(main)/(content)/register2/page.tsx
Normal file
45
apps/user/app/(main)/(content)/register2/page.tsx
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*import { GlobalMap } from '@/components/main/global-map';
|
||||||
|
import { Hero } from '@/components/main/hero';
|
||||||
|
import { ProductShowcase } from '@/components/main/product-showcase/index';
|
||||||
|
import { Stats } from '@/components/main/stats';*/
|
||||||
|
import Header from '@/components/Header/Header';
|
||||||
|
import { queryUserInfo } from '@/services/user/user';
|
||||||
|
import { cookies } from 'next/headers';
|
||||||
|
|
||||||
|
import EmailAuthForm2 from '@/app/auth/email2/auth-form';
|
||||||
|
import { LoginDialogProvider } from '@/app/auth/LoginDialogContext';
|
||||||
|
import FooterCopyright from '@/components/main/FooterCopyright';
|
||||||
|
import FullScreenVideoBackground from '@/components/main/FullScreenVideoBackground';
|
||||||
|
|
||||||
|
export default async function Home() {
|
||||||
|
const Authorization = (await cookies()).get('Authorization')?.value;
|
||||||
|
|
||||||
|
if (Authorization) {
|
||||||
|
let user = null;
|
||||||
|
try {
|
||||||
|
user = await queryUserInfo({
|
||||||
|
skipErrorHandler: true,
|
||||||
|
Authorization,
|
||||||
|
}).then((res) => res.data.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Token validation failed:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
// redirect('/dashboard');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<LoginDialogProvider>
|
||||||
|
<FullScreenVideoBackground />
|
||||||
|
<Header />
|
||||||
|
<main className='fixed inset-0 z-40 flex items-center justify-center'>
|
||||||
|
<div>
|
||||||
|
<EmailAuthForm2 isRedirect={true} />
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
<FooterCopyright />
|
||||||
|
</LoginDialogProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
111
apps/user/app/auth/email1/auth-form.tsx
Normal file
111
apps/user/app/auth/email1/auth-form.tsx
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { resetPassword, userLogin, userRegister } from '@/services/common/auth';
|
||||||
|
import { useTranslations } from 'next-intl';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { ReactNode, useState, useTransition } from 'react';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
import {
|
||||||
|
NEXT_PUBLIC_DEFAULT_USER_EMAIL,
|
||||||
|
NEXT_PUBLIC_DEFAULT_USER_PASSWORD,
|
||||||
|
} from '@/config/constants';
|
||||||
|
import useGlobalStore from '@/config/use-global';
|
||||||
|
import { getRedirectUrl, setAuthorization } from '@/utils/common';
|
||||||
|
import LoginForm from './login-form';
|
||||||
|
import RegisterForm from './register-form';
|
||||||
|
import ResetForm from './reset-form';
|
||||||
|
|
||||||
|
export default function EmailAuthForm(props: { isRedirect: boolean }) {
|
||||||
|
const t = useTranslations('auth');
|
||||||
|
const router = useRouter();
|
||||||
|
const [type, setType] = useState<'login' | 'register' | 'reset'>('register');
|
||||||
|
const [loading, startTransition] = useTransition();
|
||||||
|
const [initialValues, setInitialValues] = useState<{
|
||||||
|
email?: string;
|
||||||
|
password?: string;
|
||||||
|
}>({
|
||||||
|
email: NEXT_PUBLIC_DEFAULT_USER_EMAIL,
|
||||||
|
password: NEXT_PUBLIC_DEFAULT_USER_PASSWORD,
|
||||||
|
});
|
||||||
|
const { getUserInfo } = useGlobalStore();
|
||||||
|
const handleFormSubmit = async (params: any) => {
|
||||||
|
const onLogin = async (token?: string) => {
|
||||||
|
if (!token) return;
|
||||||
|
setAuthorization(token);
|
||||||
|
console.log('props.isRedirect', token);
|
||||||
|
console.log('props.isRedirect', props.isRedirect);
|
||||||
|
console.log('props.isRedirect ', getRedirectUrl());
|
||||||
|
if (props.isRedirect) {
|
||||||
|
router.replace(getRedirectUrl());
|
||||||
|
router.refresh();
|
||||||
|
} else {
|
||||||
|
await getUserInfo();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
startTransition(async () => {
|
||||||
|
try {
|
||||||
|
switch (type) {
|
||||||
|
case 'login': {
|
||||||
|
const login = await userLogin(params);
|
||||||
|
toast.success(t('login.success'));
|
||||||
|
onLogin(login.data.data?.token);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'register': {
|
||||||
|
const create = await userRegister(params);
|
||||||
|
toast.success(t('register.success'));
|
||||||
|
onLogin(create.data.data?.token);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'reset':
|
||||||
|
await resetPassword(params);
|
||||||
|
toast.success(t('reset.success'));
|
||||||
|
setType('login');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
/* empty */
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
let UserForm: ReactNode = null;
|
||||||
|
switch (type) {
|
||||||
|
case 'login':
|
||||||
|
UserForm = (
|
||||||
|
<LoginForm
|
||||||
|
loading={loading}
|
||||||
|
onSubmit={handleFormSubmit}
|
||||||
|
initialValues={initialValues}
|
||||||
|
setInitialValues={setInitialValues}
|
||||||
|
onSwitchForm={setType}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'register':
|
||||||
|
UserForm = (
|
||||||
|
<RegisterForm
|
||||||
|
loading={loading}
|
||||||
|
onSubmit={handleFormSubmit}
|
||||||
|
initialValues={initialValues}
|
||||||
|
setInitialValues={setInitialValues}
|
||||||
|
onSwitchForm={setType}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'reset':
|
||||||
|
UserForm = (
|
||||||
|
<ResetForm
|
||||||
|
loading={loading}
|
||||||
|
onSubmit={handleFormSubmit}
|
||||||
|
initialValues={initialValues}
|
||||||
|
setInitialValues={setInitialValues}
|
||||||
|
onSwitchForm={setType}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserForm;
|
||||||
|
}
|
||||||
147
apps/user/app/auth/email1/login-form.tsx
Normal file
147
apps/user/app/auth/email1/login-form.tsx
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
import useGlobalStore from '@/config/use-global';
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { AiroButton } from '@workspace/airo-ui/components/AiroButton';
|
||||||
|
import { Button } from '@workspace/airo-ui/components/button';
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormMessage,
|
||||||
|
} from '@workspace/airo-ui/components/form';
|
||||||
|
import { Input } from '@workspace/airo-ui/components/input';
|
||||||
|
import { Icon } from '@workspace/airo-ui/custom-components/icon';
|
||||||
|
import { useTranslations } from 'next-intl';
|
||||||
|
import { Dispatch, SetStateAction, useRef } from 'react';
|
||||||
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { z } from 'zod';
|
||||||
|
import CloudFlareTurnstile, { TurnstileRef } from '../turnstile';
|
||||||
|
|
||||||
|
export default function LoginForm({
|
||||||
|
loading,
|
||||||
|
onSubmit,
|
||||||
|
initialValues,
|
||||||
|
setInitialValues,
|
||||||
|
onSwitchForm,
|
||||||
|
}: {
|
||||||
|
loading?: boolean;
|
||||||
|
onSubmit: (data: any) => void;
|
||||||
|
initialValues: any;
|
||||||
|
setInitialValues: Dispatch<SetStateAction<any>>;
|
||||||
|
onSwitchForm: Dispatch<SetStateAction<'register' | 'reset' | 'login'>>;
|
||||||
|
}) {
|
||||||
|
const t = useTranslations('auth.login');
|
||||||
|
const { common } = useGlobalStore();
|
||||||
|
const { verify } = common;
|
||||||
|
|
||||||
|
const formSchema = z.object({
|
||||||
|
email: z.string().email(t('email')),
|
||||||
|
password: z.string(),
|
||||||
|
cf_token:
|
||||||
|
verify.enable_login_verify && verify.turnstile_site_key ? z.string() : z.string().optional(),
|
||||||
|
});
|
||||||
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
|
resolver: zodResolver(formSchema),
|
||||||
|
defaultValues: initialValues,
|
||||||
|
});
|
||||||
|
|
||||||
|
const turnstile = useRef<TurnstileRef>(null);
|
||||||
|
const handleSubmit = form.handleSubmit((data) => {
|
||||||
|
try {
|
||||||
|
onSubmit(data);
|
||||||
|
} catch (error) {
|
||||||
|
turnstile.current?.reset();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className={'h-[84px] text-2xl font-bold leading-[84px]'}>账户验证</div>
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={handleSubmit} className=''>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name='email'
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className={'mb-5'}>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
||||||
|
placeholder='Email'
|
||||||
|
type='email'
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name='password'
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className={'mb-2'}>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
||||||
|
placeholder='Password'
|
||||||
|
type='password'
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{verify.enable_login_verify && (
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name='cf_token'
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className={'last:mb-0'}>
|
||||||
|
<FormControl>
|
||||||
|
<CloudFlareTurnstile id='login' {...field} ref={turnstile} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<div className='flex w-full justify-between text-sm'>
|
||||||
|
<Button
|
||||||
|
variant='link'
|
||||||
|
type='button'
|
||||||
|
className='p-0 text-[#225BA9]'
|
||||||
|
onClick={() => onSwitchForm('reset')}
|
||||||
|
>
|
||||||
|
{t('forgotPassword')}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant='link'
|
||||||
|
type='button'
|
||||||
|
className='p-0 text-[#225BA9]'
|
||||||
|
onClick={() => {
|
||||||
|
setInitialValues(undefined);
|
||||||
|
onSwitchForm('register');
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('registerAccount')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='mt-6 flex justify-center'>
|
||||||
|
<AiroButton
|
||||||
|
type='submit'
|
||||||
|
variant='default'
|
||||||
|
disabled={loading}
|
||||||
|
className='h-auto min-w-[157px] py-2 text-lg font-medium'
|
||||||
|
>
|
||||||
|
{loading && <Icon icon='mdi:loading' className='animate-spin' />}
|
||||||
|
{t('title')}
|
||||||
|
</AiroButton>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
218
apps/user/app/auth/email1/register-form.tsx
Normal file
218
apps/user/app/auth/email1/register-form.tsx
Normal file
@ -0,0 +1,218 @@
|
|||||||
|
'use client';
|
||||||
|
import useGlobalStore from '@/config/use-global';
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { AiroButton } from '@workspace/airo-ui/components/AiroButton';
|
||||||
|
import { Button } from '@workspace/airo-ui/components/button';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormMessage,
|
||||||
|
} from '@workspace/airo-ui/components/form';
|
||||||
|
import { Input } from '@workspace/airo-ui/components/input';
|
||||||
|
import { Icon } from '@workspace/airo-ui/custom-components/icon';
|
||||||
|
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 { TurnstileRef } from '../turnstile';
|
||||||
|
|
||||||
|
export default function RegisterForm({
|
||||||
|
loading,
|
||||||
|
onSubmit,
|
||||||
|
initialValues,
|
||||||
|
setInitialValues,
|
||||||
|
onSwitchForm,
|
||||||
|
}: {
|
||||||
|
loading?: boolean;
|
||||||
|
onSubmit: (data: any) => void;
|
||||||
|
initialValues: any;
|
||||||
|
setInitialValues: Dispatch<SetStateAction<any>>;
|
||||||
|
onSwitchForm: Dispatch<SetStateAction<'register' | 'reset' | 'login'>>;
|
||||||
|
}) {
|
||||||
|
const { common } = useGlobalStore();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const formSchema = z
|
||||||
|
.object({
|
||||||
|
email: z.string().email('请输入有效的电子邮件地址。'),
|
||||||
|
password: z.string().min(1, '请输入密码'), // 必填提示
|
||||||
|
repeat_password: z.string().min(1, '请重复输入密码'), // 必填
|
||||||
|
code: z.string().min(1, '请输入验证码'), // 必填,
|
||||||
|
invite: z.string().nullish(),
|
||||||
|
})
|
||||||
|
.superRefine(({ password, repeat_password }, ctx) => {
|
||||||
|
if (password !== repeat_password) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: '两次密码输入不一致',
|
||||||
|
path: ['repeat_password'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const [inviteDefault, setInviteDefault] = useState('');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const invite = localStorage.getItem('invite') || '';
|
||||||
|
setInviteDefault(invite);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
|
resolver: zodResolver(formSchema),
|
||||||
|
defaultValues: {
|
||||||
|
...initialValues,
|
||||||
|
invite: inviteDefault,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const turnstile = useRef<TurnstileRef>(null);
|
||||||
|
const handleSubmit = form.handleSubmit((data) => {
|
||||||
|
try {
|
||||||
|
onSubmit(data);
|
||||||
|
} catch (error) {
|
||||||
|
turnstile.current?.reset();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className={'h-[84px] text-2xl font-bold leading-[84px]'}>线路优化</div>
|
||||||
|
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<div className='grid gap-5'>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name='email'
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
||||||
|
placeholder='电子邮箱'
|
||||||
|
type='email'
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name='password'
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
||||||
|
placeholder='设置密码'
|
||||||
|
type='password'
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name='repeat_password'
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
||||||
|
disabled={loading}
|
||||||
|
placeholder='再次输入密码'
|
||||||
|
type='password'
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name='code'
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<div className='flex items-center gap-8'>
|
||||||
|
<Input
|
||||||
|
disabled={loading}
|
||||||
|
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
||||||
|
placeholder='邮箱验证码'
|
||||||
|
type='text'
|
||||||
|
{...field}
|
||||||
|
value={field.value as string}
|
||||||
|
/>
|
||||||
|
<SendCode
|
||||||
|
type='email'
|
||||||
|
form={form}
|
||||||
|
params={{
|
||||||
|
...form.getValues(),
|
||||||
|
type: 1,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name='invite'
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
||||||
|
disabled={loading || !!inviteDefault}
|
||||||
|
placeholder={'邀请码(非必填)'}
|
||||||
|
{...field}
|
||||||
|
value={field.value || ''}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='text-right text-sm'>
|
||||||
|
已有账户?
|
||||||
|
<Button
|
||||||
|
variant='link'
|
||||||
|
type='button'
|
||||||
|
className='p-0 text-[#225BA9]'
|
||||||
|
onClick={() => {
|
||||||
|
router.replace('/');
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
登录
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className='mt-6 flex justify-center'>
|
||||||
|
<AiroButton
|
||||||
|
type='submit'
|
||||||
|
disabled={loading}
|
||||||
|
className='h-auto min-w-[157px] py-2 text-lg font-medium'
|
||||||
|
>
|
||||||
|
{loading && <Icon icon='mdi:loading' className='animate-spin' />}
|
||||||
|
注册
|
||||||
|
</AiroButton>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
174
apps/user/app/auth/email1/reset-form.tsx
Normal file
174
apps/user/app/auth/email1/reset-form.tsx
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
import useGlobalStore from '@/config/use-global';
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { AiroButton } from '@workspace/airo-ui/components/AiroButton';
|
||||||
|
import { Button } from '@workspace/airo-ui/components/button';
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormMessage,
|
||||||
|
} from '@workspace/airo-ui/components/form';
|
||||||
|
import { Input } from '@workspace/airo-ui/components/input';
|
||||||
|
import { Icon } from '@workspace/airo-ui/custom-components/icon';
|
||||||
|
import { useTranslations } from 'next-intl';
|
||||||
|
import { Dispatch, SetStateAction, useRef } from 'react';
|
||||||
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { z } from 'zod';
|
||||||
|
import SendCode from '../send-code';
|
||||||
|
import CloudFlareTurnstile, { TurnstileRef } from '../turnstile';
|
||||||
|
|
||||||
|
export default function ResetForm({
|
||||||
|
loading,
|
||||||
|
onSubmit,
|
||||||
|
initialValues,
|
||||||
|
setInitialValues,
|
||||||
|
onSwitchForm,
|
||||||
|
}: {
|
||||||
|
loading?: boolean;
|
||||||
|
onSubmit: (data: any) => void;
|
||||||
|
initialValues: any;
|
||||||
|
setInitialValues: Dispatch<SetStateAction<any>>;
|
||||||
|
onSwitchForm: Dispatch<SetStateAction<'register' | 'reset' | 'login'>>;
|
||||||
|
}) {
|
||||||
|
const t = useTranslations('auth.reset');
|
||||||
|
|
||||||
|
const { common } = useGlobalStore();
|
||||||
|
const { verify, auth } = common;
|
||||||
|
|
||||||
|
const formSchema = z.object({
|
||||||
|
email: z.string().email(t('email')),
|
||||||
|
password: z.string(),
|
||||||
|
code: auth?.email?.enable_verify ? z.string() : z.string().nullish(),
|
||||||
|
cf_token:
|
||||||
|
verify.enable_register_verify && verify.turnstile_site_key
|
||||||
|
? z.string()
|
||||||
|
: z.string().nullish(),
|
||||||
|
});
|
||||||
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
|
resolver: zodResolver(formSchema),
|
||||||
|
defaultValues: initialValues,
|
||||||
|
});
|
||||||
|
|
||||||
|
const turnstile = useRef<TurnstileRef>(null);
|
||||||
|
const handleSubmit = form.handleSubmit((data) => {
|
||||||
|
try {
|
||||||
|
onSubmit(data);
|
||||||
|
} catch (error) {
|
||||||
|
turnstile.current?.reset();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className={'h-[84px] text-2xl font-bold leading-[84px]'}>找回账户</div>
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<div className='grid gap-5'>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name='email'
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
||||||
|
placeholder='Enter your email...'
|
||||||
|
type='email'
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name='code'
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<div className='flex items-center gap-8'>
|
||||||
|
<Input
|
||||||
|
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
||||||
|
disabled={loading}
|
||||||
|
placeholder='Enter code...'
|
||||||
|
type='text'
|
||||||
|
{...field}
|
||||||
|
value={field.value as string}
|
||||||
|
/>
|
||||||
|
<SendCode
|
||||||
|
type='email'
|
||||||
|
form={form}
|
||||||
|
params={{
|
||||||
|
...form.getValues(),
|
||||||
|
type: 2,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name='password'
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
||||||
|
placeholder='Enter your new password...'
|
||||||
|
type='password'
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{verify.enable_reset_password_verify && (
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name='cf_token'
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<CloudFlareTurnstile id='reset' {...field} ref={turnstile} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className='text-right text-sm'>
|
||||||
|
{t('existingAccount')}
|
||||||
|
<Button
|
||||||
|
variant='link'
|
||||||
|
type='button'
|
||||||
|
className='p-0 text-[#225BA9]'
|
||||||
|
onClick={() => {
|
||||||
|
setInitialValues(undefined);
|
||||||
|
onSwitchForm('login');
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('switchToLogin')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className='mt-6 flex justify-center'>
|
||||||
|
<AiroButton
|
||||||
|
type='submit'
|
||||||
|
disabled={loading}
|
||||||
|
className='h-auto min-w-[157px] py-2 text-lg font-medium'
|
||||||
|
>
|
||||||
|
{loading && <Icon icon='mdi:loading' className='animate-spin' />}
|
||||||
|
{t('title')}
|
||||||
|
</AiroButton>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
|||||||
import { AiroButton } from '@workspace/airo-ui/components/AiroButton';
|
import { AiroButton } from '@workspace/airo-ui/components/AiroButton';
|
||||||
import { Button } from '@workspace/airo-ui/components/button';
|
import { Button } from '@workspace/airo-ui/components/button';
|
||||||
|
|
||||||
|
import { useLoginDialog } from '@/app/auth/LoginDialogContext';
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
@ -55,6 +56,7 @@ export default function RegisterForm({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const [inviteDefault, setInviteDefault] = useState('');
|
const [inviteDefault, setInviteDefault] = useState('');
|
||||||
|
const { openLoginDialog } = useLoginDialog();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const invite = localStorage.getItem('invite') || '';
|
const invite = localStorage.getItem('invite') || '';
|
||||||
@ -80,7 +82,7 @@ export default function RegisterForm({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={'h-[84px] text-2xl font-bold leading-[84px]'}>线路优化</div>
|
<div className={'h-[84px] text-2xl font-bold leading-[84px] text-white'}>线路优化</div>
|
||||||
|
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
@ -92,7 +94,9 @@ export default function RegisterForm({
|
|||||||
<FormItem>
|
<FormItem>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input
|
<Input
|
||||||
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
className={
|
||||||
|
'h-[46px] rounded-full bg-white shadow-[inset_0_0_7.6px_0_#00000040]'
|
||||||
|
}
|
||||||
placeholder='电子邮箱'
|
placeholder='电子邮箱'
|
||||||
type='email'
|
type='email'
|
||||||
{...field}
|
{...field}
|
||||||
@ -109,7 +113,9 @@ export default function RegisterForm({
|
|||||||
<FormItem>
|
<FormItem>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input
|
<Input
|
||||||
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
className={
|
||||||
|
'h-[46px] rounded-full bg-white shadow-[inset_0_0_7.6px_0_#00000040]'
|
||||||
|
}
|
||||||
placeholder='设置密码'
|
placeholder='设置密码'
|
||||||
type='password'
|
type='password'
|
||||||
{...field}
|
{...field}
|
||||||
@ -126,7 +132,9 @@ export default function RegisterForm({
|
|||||||
<FormItem>
|
<FormItem>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input
|
<Input
|
||||||
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
className={
|
||||||
|
'h-[46px] rounded-full bg-white shadow-[inset_0_0_7.6px_0_#00000040]'
|
||||||
|
}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
placeholder='再次输入密码'
|
placeholder='再次输入密码'
|
||||||
type='password'
|
type='password'
|
||||||
@ -147,7 +155,9 @@ export default function RegisterForm({
|
|||||||
<div className='flex items-center gap-8'>
|
<div className='flex items-center gap-8'>
|
||||||
<Input
|
<Input
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
className={
|
||||||
|
'h-[46px] rounded-full bg-white shadow-[inset_0_0_7.6px_0_#00000040]'
|
||||||
|
}
|
||||||
placeholder='邮箱验证码'
|
placeholder='邮箱验证码'
|
||||||
type='text'
|
type='text'
|
||||||
{...field}
|
{...field}
|
||||||
@ -175,7 +185,9 @@ export default function RegisterForm({
|
|||||||
<FormItem>
|
<FormItem>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input
|
<Input
|
||||||
className={'h-[46px] rounded-full shadow-[inset_0_0_7.6px_0_#00000040]'}
|
className={
|
||||||
|
'h-[46px] rounded-full bg-white shadow-[inset_0_0_7.6px_0_#00000040]'
|
||||||
|
}
|
||||||
disabled={loading || !!inviteDefault}
|
disabled={loading || !!inviteDefault}
|
||||||
placeholder={'邀请码(非必填)'}
|
placeholder={'邀请码(非必填)'}
|
||||||
{...field}
|
{...field}
|
||||||
@ -195,7 +207,7 @@ export default function RegisterForm({
|
|||||||
type='button'
|
type='button'
|
||||||
className='p-0 text-[#225BA9]'
|
className='p-0 text-[#225BA9]'
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
router.replace('/');
|
openLoginDialog();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
登录
|
登录
|
||||||
@ -204,8 +216,9 @@ export default function RegisterForm({
|
|||||||
<div className='mt-6 flex justify-center'>
|
<div className='mt-6 flex justify-center'>
|
||||||
<AiroButton
|
<AiroButton
|
||||||
type='submit'
|
type='submit'
|
||||||
|
variant={'default'}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
className='h-auto min-w-[157px] py-2 text-lg font-medium'
|
className='h-auto min-w-[157px] border-[3px] border-white bg-white/10 py-2 text-lg font-medium text-white transition hover:bg-white/25'
|
||||||
>
|
>
|
||||||
{loading && <Icon icon='mdi:loading' className='animate-spin' />}
|
{loading && <Icon icon='mdi:loading' className='animate-spin' />}
|
||||||
注册
|
注册
|
||||||
|
|||||||
@ -84,16 +84,14 @@ export default function SendCode({ type, params, form }: SendCodeProps) {
|
|||||||
await getPhoneCode();
|
await getPhoneCode();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const disabled =
|
const disabled = seconds > 0;
|
||||||
seconds > 0 ||
|
|
||||||
(type === 'email' ? !params.email : !params.telephone || !params.telephone_area_code);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<AiroButton
|
<AiroButton
|
||||||
type='button'
|
type='button'
|
||||||
variant={'primary'}
|
variant={'primary'}
|
||||||
className={'h-[30px] w-[109px]'}
|
className={'h-[46px] w-[109px]'}
|
||||||
onClick={handleSendCode}
|
onClick={handleSendCode}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
|
|||||||
@ -33,7 +33,7 @@ export default function Providers({
|
|||||||
|
|
||||||
const { setCommon, setUser } = useGlobalStore();
|
const { setCommon, setUser } = useGlobalStore();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const whiteList = ['/', '/register'];
|
const whiteList = ['/', '/register', '/register2'];
|
||||||
const isWhite = whiteList.includes(pathname);
|
const isWhite = whiteList.includes(pathname);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@ -53,7 +53,7 @@ export function Logout() {
|
|||||||
Crisp.session.reset(); // 2. Unbind the current session
|
Crisp.session.reset(); // 2. Unbind the current session
|
||||||
const pathname = location.pathname;
|
const pathname = location.pathname;
|
||||||
if (
|
if (
|
||||||
!['', '/', '/auth', '/tos', '/privacy-policy', '/register'].includes(pathname) &&
|
!['', '/', '/auth', '/tos', '/privacy-policy', '/register', '/register2'].includes(pathname) &&
|
||||||
!pathname.startsWith('/purchasing') &&
|
!pathname.startsWith('/purchasing') &&
|
||||||
!pathname.startsWith('/oauth/')
|
!pathname.startsWith('/oauth/')
|
||||||
) {
|
) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user