Support login with email

This commit is contained in:
2023-12-20 14:55:15 +08:00
parent 4d072e0de8
commit 73bfe53edc
5 changed files with 13 additions and 13 deletions

2
src/global.d.ts vendored
View File

@@ -149,7 +149,7 @@ interface GroupVo {
} }
interface LoginForm { interface LoginForm {
username: string account: string
password: string password: string
} }

View File

@@ -19,7 +19,7 @@ const Login: React.FC = () => {
const onFinish = (values: LoginForm) => { const onFinish = (values: LoginForm) => {
setIsLoggingIn(true) setIsLoggingIn(true)
void login(values.username, values.password) void login(values.account, values.password)
.then((value) => { .then((value) => {
const res = value.data const res = value.data
const { code, data } = res const { code, data } = res
@@ -64,7 +64,7 @@ const Login: React.FC = () => {
case PERMISSION_LOGIN_USERNAME_PASSWORD_ERROR: case PERMISSION_LOGIN_USERNAME_PASSWORD_ERROR:
void messageApi.error( void messageApi.error(
<> <>
<strong></strong><strong></strong> <strong></strong><strong></strong>
</> </>
) )
setIsLoggingIn(false) setIsLoggingIn(false)
@@ -114,12 +114,12 @@ const Login: React.FC = () => {
> >
<AntdForm.Item <AntdForm.Item
className={'login-from-item'} className={'login-from-item'}
name={'username'} name={'account'}
rules={[{ required: true, message: '用户名为空' }]} rules={[{ required: true, message: '账号为空' }]}
> >
<AntdInput <AntdInput
prefix={<UserOutlined />} prefix={<UserOutlined />}
placeholder={'用户名'} placeholder={'邮箱/用户名'}
disabled={isLoggingIn} disabled={isLoggingIn}
/> />
</AntdForm.Item> </AntdForm.Item>

View File

@@ -522,7 +522,7 @@ const User: React.FC = () => {
getUser() getUser()
break break
case DATABASE_DUPLICATE_KEY: case DATABASE_DUPLICATE_KEY:
void message.error('已存在相同用户名') void message.error('已存在相同用户名或邮箱')
break break
default: default:
void message.error('更新失败,请稍后重试') void message.error('更新失败,请稍后重试')
@@ -551,7 +551,7 @@ const User: React.FC = () => {
getUser() getUser()
break break
case DATABASE_DUPLICATE_KEY: case DATABASE_DUPLICATE_KEY:
void message.error('已存在相同用户名') void message.error('已存在相同用户名或邮箱')
break break
default: default:
void message.error('添加失败,请稍后重试') void message.error('添加失败,请稍后重试')
@@ -810,7 +810,7 @@ const User: React.FC = () => {
<AntdForm.Item <AntdForm.Item
name={'email'} name={'email'}
label={'邮箱'} label={'邮箱'}
rules={[{ whitespace: false, type: 'email' }]} rules={[{ required: true, whitespace: false, type: 'email' }]}
> >
<AntdInput type={'email'} allowClear /> <AntdInput type={'email'} allowClear />
</AntdForm.Item> </AntdForm.Item>

View File

@@ -1,9 +1,9 @@
import { URL_LOGIN, URL_LOGOUT } from '@/constants/urls.constants' import { URL_LOGIN, URL_LOGOUT } from '@/constants/urls.constants'
import request from '@/services' import request from '@/services'
export const r_auth_login = (username: string, password: string) => export const r_auth_login = (account: string, password: string) =>
request.post<TokenVo>(URL_LOGIN, { request.post<TokenVo>(URL_LOGIN, {
username, account,
password password
}) })

View File

@@ -65,8 +65,8 @@ export const getCaptcha = (width: number, high: number, num: number) => {
} }
} }
export const login = async (username: string, password: string) => { export const login = async (account: string, password: string) => {
return await r_auth_login(username, password) return await r_auth_login(account, password)
} }
export const logout = async () => { export const logout = async () => {