Add forgot username/password links and register link to login page & fix something on reset password. Will add those pages too.
This commit is contained in:
@@ -6,6 +6,7 @@ import { Suspense, useEffect, useState } from 'react'
|
|||||||
import { HomeButton } from '@/app/components/HomeButton'
|
import { HomeButton } from '@/app/components/HomeButton'
|
||||||
import { DiscordButton } from '@/app/components/DiscordButton'
|
import { DiscordButton } from '@/app/components/DiscordButton'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import Link from 'next/link'
|
||||||
|
|
||||||
function LoginForm ({ redirect }: { redirect: string | null }) {
|
function LoginForm ({ redirect }: { redirect: string | null }) {
|
||||||
const [loading, setLoading] = useState<boolean>(true)
|
const [loading, setLoading] = useState<boolean>(true)
|
||||||
@@ -31,65 +32,86 @@ function LoginForm ({ redirect }: { redirect: string | null }) {
|
|||||||
{loading ? 'Loading...' : 'Lncvrt Games Login'}
|
{loading ? 'Loading...' : 'Lncvrt Games Login'}
|
||||||
</p>
|
</p>
|
||||||
{!loading && (
|
{!loading && (
|
||||||
<form
|
<>
|
||||||
className='flex flex-col gap-2'
|
<form
|
||||||
onSubmit={async e => {
|
className='flex flex-col gap-2'
|
||||||
e.preventDefault()
|
onSubmit={async e => {
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await axios.post('/api/account/login', {
|
const result = await axios.post('/api/account/login', {
|
||||||
username,
|
username,
|
||||||
password
|
password
|
||||||
})
|
})
|
||||||
if (result.data.success) {
|
if (result.data.success) {
|
||||||
if (result.data.data.session)
|
if (result.data.data.session)
|
||||||
setCookie('accountToken', result.data.data.session)
|
setCookie('accountToken', result.data.data.session)
|
||||||
if (result.data.data.username)
|
if (result.data.data.username)
|
||||||
setCookie('accountUsername', result.data.data.username)
|
setCookie('accountUsername', result.data.data.username)
|
||||||
if (result.data.data.id)
|
if (result.data.data.id)
|
||||||
setCookie('accountId', result.data.data.id)
|
setCookie('accountId', result.data.data.id)
|
||||||
|
|
||||||
router.push(redirect ?? '/account')
|
router.push(redirect ?? '/account')
|
||||||
} else {
|
} else {
|
||||||
alert(
|
alert(
|
||||||
'Failed to login, error: ' + (result.data.message || 'n/a')
|
'Failed to login, error: ' + (result.data.message || 'n/a')
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
} catch (e: any) {
|
||||||
|
if (e.response) {
|
||||||
|
alert(
|
||||||
|
'Failed to login, error: ' +
|
||||||
|
(e.response.data?.message ||
|
||||||
|
JSON.stringify(e.response.data))
|
||||||
|
)
|
||||||
|
} else if (e.request) {
|
||||||
|
alert('Failed to login, no response from server.')
|
||||||
|
} else {
|
||||||
|
alert('Failed to login, error: ' + e.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
}}
|
||||||
if (e.response) {
|
>
|
||||||
alert(
|
<input
|
||||||
'Failed to login, error: ' +
|
id='username'
|
||||||
(e.response.data?.message ||
|
name='username'
|
||||||
JSON.stringify(e.response.data))
|
placeholder='Username'
|
||||||
)
|
type='username'
|
||||||
} else if (e.request) {
|
value={username}
|
||||||
alert('Failed to login, no response from server.')
|
onChange={e => setUsername(e.target.value)}
|
||||||
} else {
|
required
|
||||||
alert('Failed to login, error: ' + e.message)
|
/>
|
||||||
}
|
<input
|
||||||
}
|
id='password'
|
||||||
}}
|
name='password'
|
||||||
>
|
placeholder='Password'
|
||||||
<input
|
type='password'
|
||||||
id='username'
|
value={password}
|
||||||
name='username'
|
onChange={e => setPassword(e.target.value)}
|
||||||
placeholder='Username'
|
required
|
||||||
type='username'
|
/>
|
||||||
value={username}
|
<button type='submit'>Login</button>
|
||||||
onChange={e => setUsername(e.target.value)}
|
</form>
|
||||||
required
|
<div className='flex justify-center flex-col gap-2 mt-6 text-center'>
|
||||||
/>
|
<Link
|
||||||
<input
|
href='/account/forgot-username'
|
||||||
id='password'
|
draggable={false}
|
||||||
name='password'
|
className='button'
|
||||||
placeholder='Password'
|
>
|
||||||
type='password'
|
Forgot username?
|
||||||
value={password}
|
</Link>
|
||||||
onChange={e => setPassword(e.target.value)}
|
<Link
|
||||||
required
|
href='/account/forgot-password'
|
||||||
/>
|
draggable={false}
|
||||||
<button type='submit'>Login</button>
|
className='button'
|
||||||
</form>
|
>
|
||||||
|
Forgot password?
|
||||||
|
</Link>
|
||||||
|
<Link href='/account/register' draggable={false} className='button'>
|
||||||
|
Don't have an account?
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ function ResetPasswordForm ({ codeParam }: { codeParam: string }) {
|
|||||||
)}
|
)}
|
||||||
{result == 2 && (
|
{result == 2 && (
|
||||||
<div className='flex justify-center mt-6'>
|
<div className='flex justify-center mt-6'>
|
||||||
<button className='button'>Login</button>
|
<button>Login</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user