mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-16 13:17:46 +00:00
feat: 支持邮箱登录 (#1438)
This commit is contained in:
parent
46349e8314
commit
74dcb36e67
1 changed files with 43 additions and 2 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import md5 from 'md5'
|
import md5 from 'md5'
|
||||||
import QRCode from 'qrcode'
|
import QRCode from 'qrcode'
|
||||||
import { Fragment } from 'react'
|
import { Fragment } from 'react'
|
||||||
import { loginWithPhone } from '@/api/auth'
|
import {loginWithEmail, loginWithPhone} from '@/api/auth'
|
||||||
import SvgIcon from '@/components/SvgIcon'
|
import SvgIcon from '@/components/SvgIcon'
|
||||||
import { state } from '@/store'
|
import { state } from '@/store'
|
||||||
import { setCookies } from '@/utils/cookie'
|
import { setCookies } from '@/utils/cookie'
|
||||||
|
|
@ -193,11 +193,52 @@ const saveCookie = (cookies: string) => {
|
||||||
const LoginWithEmail = () => {
|
const LoginWithEmail = () => {
|
||||||
const [password, setPassword] = useState('')
|
const [password, setPassword] = useState('')
|
||||||
const [email, setEmail] = useState('')
|
const [email, setEmail] = useState('')
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const doLogin = useMutation(
|
||||||
|
() => {
|
||||||
|
return loginWithEmail({
|
||||||
|
email: email.trim(),
|
||||||
|
md5_password: md5(password.trim())
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess: result => {
|
||||||
|
if (result?.code !== 200) {
|
||||||
|
toast(`Login failed: ${result.code}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
saveCookie(result.cookie)
|
||||||
|
navigate(-1)
|
||||||
|
},
|
||||||
|
onError: error => {
|
||||||
|
toast(`Login failed: ${error}`)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleLogin = () => {
|
||||||
|
if (!email) {
|
||||||
|
toast.error('Please enter email')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!password) {
|
||||||
|
toast.error('Please enter password')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (email.match(/^[^\s@]+@(126|163|yeah|188|vip\.163|vip\.126)\.(com|net)$/) == null){
|
||||||
|
toast.error('Please use netease email')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
doLogin.mutate()
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<EmailInput {...{ email, setEmail }} />
|
<EmailInput {...{ email, setEmail }} />
|
||||||
<PasswordInput {...{ password, setPassword }} />
|
<PasswordInput {...{ password, setPassword }} />
|
||||||
<LoginButton onClick={() => toast('Work in progress')} disabled={true} />
|
<LoginButton onClick={handleLogin} disabled={doLogin.isLoading} />
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue