pref: login/forgetpass texts (#2457)

* chore: fastgptfeconfig type

* pref: login, forget password, texts
This commit is contained in:
Finley Ge
2024-08-21 14:46:53 +08:00
committed by GitHub
parent 26d800981c
commit 649de7f028
6 changed files with 84 additions and 34 deletions

View File

@@ -24,7 +24,10 @@ export type FastGPTConfigFileType = {
export type FastGPTFeConfigsType = { export type FastGPTFeConfigsType = {
show_emptyChat?: boolean; show_emptyChat?: boolean;
show_register?: boolean; register_method?: ['email' | 'phone'];
login_method?: ['email' | 'phone']; // Attention: login method is diffrent with oauth
find_password_method?: ['email' | 'phone'];
bind_notification_method?: ['email' | 'phone'];
show_appStore?: boolean; show_appStore?: boolean;
show_git?: boolean; show_git?: boolean;
show_pay?: boolean; show_pay?: boolean;
@@ -43,8 +46,6 @@ export type FastGPTFeConfigsType = {
systemDescription?: string; systemDescription?: string;
googleClientVerKey?: string; googleClientVerKey?: string;
isPlus?: boolean; isPlus?: boolean;
show_phoneLogin?: boolean;
show_emailLogin?: boolean;
sso?: { sso?: {
icon?: string; icon?: string;
title?: string; title?: string;

View File

@@ -8,6 +8,7 @@ import { updateNotificationAccount } from '@/web/support/user/api';
import Icon from '@fastgpt/web/components/common/Icon'; import Icon from '@fastgpt/web/components/common/Icon';
import { useSendCode } from '@/web/support/user/hooks/useSendCode'; import { useSendCode } from '@/web/support/user/hooks/useSendCode';
import { useUserStore } from '@/web/support/user/useUserStore'; import { useUserStore } from '@/web/support/user/useUserStore';
import { useSystemStore } from '@/web/common/system/useSystemStore';
type FormType = { type FormType = {
account: string; account: string;
@@ -17,6 +18,7 @@ type FormType = {
const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => { const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const { initUserInfo } = useUserStore(); const { initUserInfo } = useUserStore();
const { feConfigs } = useSystemStore();
const { register, handleSubmit, trigger, getValues, watch } = useForm<FormType>({ const { register, handleSubmit, trigger, getValues, watch } = useForm<FormType>({
defaultValues: { defaultValues: {
account: '', account: '',
@@ -51,6 +53,17 @@ const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => {
}); });
}, [getValues, sendCode, trigger]); }, [getValues, sendCode, trigger]);
const placeholder = feConfigs?.bind_notification_method
?.map((item) => {
switch (item) {
case 'email':
return t('common:support.user.login.Email');
case 'phone':
return t('common:support.user.login.Phone number');
}
})
.join('/');
return ( return (
<MyModal <MyModal
isOpen isOpen
@@ -70,7 +83,7 @@ const UpdateNotificationModal = ({ onClose }: { onClose: () => void }) => {
flex={1} flex={1}
bg={'myGray.50'} bg={'myGray.50'}
{...register('account', { required: true })} {...register('account', { required: true })}
placeholder={t('user:password.email_phone')} placeholder={placeholder}
></Input> ></Input>
</Flex> </Flex>
<Flex mt="6" alignItems="center" position={'relative'}> <Flex mt="6" alignItems="center" position={'relative'}>

View File

@@ -46,6 +46,18 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
}, [getValues, sendCode, trigger]); }, [getValues, sendCode, trigger]);
const [requesting, setRequesting] = useState(false); const [requesting, setRequesting] = useState(false);
const placeholder = feConfigs?.find_password_method
?.map((item) => {
switch (item) {
case 'email':
return t('common:support.user.login.Email');
case 'phone':
return t('common:support.user.login.Phone number');
default:
return t('common:support.user.login.Username');
}
})
.join('/');
const onclickFindPassword = useCallback( const onclickFindPassword = useCallback(
async ({ username, code, password }: RegisterType) => { async ({ username, code, password }: RegisterType) => {
@@ -89,7 +101,7 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
<FormControl isInvalid={!!errors.username}> <FormControl isInvalid={!!errors.username}>
<Input <Input
bg={'myGray.50'} bg={'myGray.50'}
placeholder={t('user:password.email_phone')} placeholder={placeholder}
{...register('username', { {...register('username', {
required: t('user:password.email_phone_void'), required: t('user:password.email_phone_void'),
pattern: { pattern: {

View File

@@ -57,24 +57,32 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
[loginSuccess, t, toast] [loginSuccess, t, toast]
); );
const isCommunityVersion = feConfigs?.show_register === false && !feConfigs?.isPlus; const isCommunityVersion = !!(feConfigs?.register_method && !feConfigs?.isPlus);
const loginOptions = [ const placeholder = (() => {
feConfigs?.show_phoneLogin ? t('common:support.user.login.Phone number') : '', if (isCommunityVersion) {
feConfigs?.show_emailLogin ? t('common:support.user.login.Email') : '', return t('common:support.user.login.Root login');
t('common:support.user.login.Username') }
].filter(Boolean); return [t('common:support.user.login.Username')]
.concat(
const placeholder = isCommunityVersion feConfigs?.login_method?.map((item) => {
? t('common:support.user.login.Root login') switch (item) {
: loginOptions.join('/'); case 'email':
return t('common:support.user.login.Email');
case 'phone':
return t('common:support.user.login.Phone number');
}
}) ?? []
)
.join('/');
})();
return ( return (
<FormLayout setPageType={setPageType} pageType={LoginPageTypeEnum.passwordLogin}> <FormLayout setPageType={setPageType} pageType={LoginPageTypeEnum.passwordLogin}>
<Box <Box
mt={'42px'} mt={'42px'}
onKeyDown={(e) => { onKeyDown={(e) => {
if (e.keyCode === 13 && !e.shiftKey && !requesting) { if (e.key === 'Enter' && !e.shiftKey && !requesting) {
handleSubmit(onclickLogin)(); handleSubmit(onclickLogin)();
} }
}} }}
@@ -140,9 +148,8 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
{t('common:Login')} {t('common:Login')}
</Button> </Button>
{feConfigs?.show_register && (
<>
<Flex align={'center'} justifyContent={'flex-end'} color={'primary.700'}> <Flex align={'center'} justifyContent={'flex-end'} color={'primary.700'}>
{feConfigs?.find_password_method && feConfigs.find_password_method.length > 0 && (
<Box <Box
cursor={'pointer'} cursor={'pointer'}
_hover={{ textDecoration: 'underline' }} _hover={{ textDecoration: 'underline' }}
@@ -151,6 +158,9 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
> >
{t('common:support.user.login.Forget Password')} {t('common:support.user.login.Forget Password')}
</Box> </Box>
)}
{feConfigs?.register_method && feConfigs.register_method.length > 0 && (
<>
<Box mx={3} h={'16px'} w={'1.5px'} bg={'myGray.250'}></Box> <Box mx={3} h={'16px'} w={'1.5px'} bg={'myGray.250'}></Box>
<Box <Box
cursor={'pointer'} cursor={'pointer'}
@@ -160,9 +170,9 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
> >
{t('common:support.user.login.Register')} {t('common:support.user.login.Register')}
</Box> </Box>
</Flex>
</> </>
)} )}
</Flex>
</Box> </Box>
</FormLayout> </FormLayout>
); );

View File

@@ -67,6 +67,9 @@ const FormLayout = ({ children, setPageType, pageType }: Props) => {
] ]
: []) : [])
]; ];
const show_oauth = !!(feConfigs?.sso || oAuthList.length > 0);
return ( return (
<Flex flexDirection={'column'} h={'100%'}> <Flex flexDirection={'column'} h={'100%'}>
<Flex alignItems={'center'}> <Flex alignItems={'center'}>
@@ -87,9 +90,9 @@ const FormLayout = ({ children, setPageType, pageType }: Props) => {
</Box> </Box>
</Flex> </Flex>
{children} {children}
<Box flex={1} /> {show_oauth && (
{feConfigs?.show_register && oAuthList.length > 0 && (
<> <>
<Box flex={1} />
<Box position={'relative'}> <Box position={'relative'}>
<Divider /> <Divider />
<AbsoluteCenter bg="white" px="4" color={'myGray.500'}> <AbsoluteCenter bg="white" px="4" color={'myGray.500'}>

View File

@@ -90,6 +90,17 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
[loginSuccess, t, toast] [loginSuccess, t, toast]
); );
const placeholder = feConfigs?.register_method
?.map((item) => {
switch (item) {
case 'email':
return t('common:support.user.login.Email');
case 'phone':
return t('common:support.user.login.Phone number');
}
})
.join('/');
return ( return (
<> <>
<Box fontWeight={'bold'} fontSize={'2xl'} textAlign={'center'}> <Box fontWeight={'bold'} fontSize={'2xl'} textAlign={'center'}>
@@ -98,7 +109,7 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
<Box <Box
mt={'42px'} mt={'42px'}
onKeyDown={(e) => { onKeyDown={(e) => {
if (e.keyCode === 13 && !e.shiftKey && !requesting) { if (e.key === 'Enter' && !e.shiftKey && !requesting) {
handleSubmit(onclickRegister)(); handleSubmit(onclickRegister)();
} }
}} }}
@@ -106,7 +117,7 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
<FormControl isInvalid={!!errors.username}> <FormControl isInvalid={!!errors.username}>
<Input <Input
bg={'myGray.50'} bg={'myGray.50'}
placeholder={t('user:password.email_phone')} placeholder={placeholder}
{...register('username', { {...register('username', {
required: t('user:password.email_phone_void'), required: t('user:password.email_phone_void'),
pattern: { pattern: {