import SvgIcon from '@/components/svg-icon'; import { useAuth } from '@/hooks/auth-hooks'; import { useLogin, useLoginChannels, useLoginWithChannel, useRegister, } from '@/hooks/login-hooks'; import { useSystemConfig } from '@/hooks/system-hooks'; import { rsaPsw } from '@/utils'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'umi'; import Spotlight from '@/components/spotlight'; import { Button, ButtonLoading } from '@/components/ui/button'; import { Checkbox } from '@/components/ui/checkbox'; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { cn } from '@/lib/utils'; import { zodResolver } from '@hookform/resolvers/zod'; import { Eye, EyeOff } from 'lucide-react'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; import { BgSvg } from './bg'; import FlipCard3D from './card'; import './index.less'; const Login = () => { const [title, setTitle] = useState('login'); const navigate = useNavigate(); const { login, loading: signLoading } = useLogin(); const { register, loading: registerLoading } = useRegister(); const { channels, loading: channelsLoading } = useLoginChannels(); const { login: loginWithChannel, loading: loginWithChannelLoading } = useLoginWithChannel(); const { t } = useTranslation('translation', { keyPrefix: 'login' }); const [isLoginPage, setIsLoginPage] = useState(true); const [showPassword, setShowPassword] = useState(false); const loading = signLoading || registerLoading || channelsLoading || loginWithChannelLoading; const { config } = useSystemConfig(); const registerEnabled = config?.registerEnabled !== 0; const { isLogin } = useAuth(); useEffect(() => { if (isLogin) { navigate('/'); } }, [isLogin, navigate]); const handleLoginWithChannel = async (channel: string) => { await loginWithChannel(channel); }; const changeTitle = () => { setIsLoginPage(title !== 'login'); if (title === 'login' && !registerEnabled) { return; } setTimeout(() => { setTitle(title === 'login' ? 'register' : 'login'); }, 200); // setTitle((title) => (title === 'login' ? 'register' : 'login')); }; const FormSchema = z .object({ nickname: z.string().optional(), email: z .string() .email() .min(1, { message: t('emailPlaceholder') }), password: z.string().min(1, { message: t('passwordPlaceholder') }), remember: z.boolean().optional(), }) .superRefine((data, ctx) => { if (title === 'register' && !data.nickname) { ctx.addIssue({ path: ['nickname'], message: 'nicknamePlaceholder', code: z.ZodIssueCode.custom, }); } }); const form = useForm({ defaultValues: { nickname: '', email: '', password: '', confirmPassword: '', remember: false, }, resolver: zodResolver(FormSchema), }); const onCheck = async (params) => { console.log('params', params); try { // const params = await form.validateFields(); const rsaPassWord = rsaPsw(params.password) as string; if (title === 'login') { const code = await login({ email: `${params.email}`.trim(), password: rsaPassWord, }); if (code === 0) { navigate('/'); } } else { const code = await register({ nickname: params.nickname, email: params.email, password: rsaPassWord, }); if (code === 0) { setTitle('login'); } } } catch (errorInfo) { console.log('Failed:', errorInfo); } }; return ( <>
{/* */}
logo
RAGFlow

{t('title')}

{/* border border-accent-primary rounded-full */} {/*
{t('start')}
*/}
{/* Logo and Header */} {/* Login Form */}

{title === 'login' ? t('loginTitle') : t('signUpTitle')}

onCheck(data))} > ( {t('emailLabel')} )} /> {title === 'register' && ( ( {t('nicknameLabel')} )} /> )} ( {t('passwordLabel')}
)} /> {title === 'login' && ( (
{ field.onChange(checked); }} /> {t('rememberMe')}
)} /> )} {title === 'login' ? t('login') : t('continue')} {title === 'login' && channels && channels.length > 0 && (
{channels.map((item) => ( ))}
)} {title === 'login' && registerEnabled && (

{t('signInTip')}

)} {title === 'register' && (

{t('signUpTip')}

)}
); }; export default Login;