This repository has been archived by the owner on May 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: gjzuloaga <[email protected]>
- Loading branch information
Showing
7 changed files
with
408 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { useRequest } from 'ahooks' | ||
import PageContainer from 'components/PageContainer' | ||
import { useAuth } from 'hooks/useAuth' | ||
import { useState } from 'react' | ||
import { Col, Row } from 'react-bootstrap' | ||
import Button from 'react-bootstrap/Button' | ||
import Form from 'react-bootstrap/Form' | ||
import { Navigate, useNavigate, useSearchParams } from 'react-router-dom' | ||
import { DOMAIN_HOST } from 'utils/constants' | ||
import Backend from 'utils/service' | ||
|
||
const ChangeForm: React.FC = () => { | ||
const { user } = useAuth() | ||
const [searchParams] = useSearchParams() | ||
const [username, setUsername] = useState('') | ||
const [currentPassword, setCurrentPassword] = useState('') | ||
const [newPassword, setNewPassword] = useState('') | ||
const navigate = useNavigate() | ||
const { run: changePasssword } = useRequest( | ||
async () => { | ||
const from = searchParams.get('from') ?? '/' | ||
return Backend.auth.v1AuthChangepasswordCreate( | ||
{ | ||
username, | ||
currentPassword, | ||
newPassword | ||
}, | ||
{ | ||
redirect_url: `${DOMAIN_HOST}${from}` | ||
} | ||
) | ||
}, | ||
{ | ||
manual: true, | ||
onSuccess: () => { | ||
navigate('/logout') // Navigate to the login page | ||
} | ||
} | ||
) | ||
|
||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault() | ||
changePasssword() | ||
} | ||
|
||
return user ? ( | ||
<> | ||
<div className='text-center'> | ||
<h1>Reset Password</h1> | ||
</div> | ||
<Col xs={12} md={8} lg={6} className='mx-auto mt-3'> | ||
<Form onSubmit={handleSubmit} validated> | ||
<Form.Group as={Row} className='mb-3' controlId='formBasicEmail'> | ||
<Form.Label className='text-sm-end' column sm={2}> | ||
Username | ||
</Form.Label> | ||
<Col sm={10}> | ||
<Form.Control | ||
required | ||
type='text' | ||
placeholder='Username' | ||
defaultValue={username} | ||
onChange={e => { | ||
setUsername(e.target.value) | ||
}} | ||
/> | ||
</Col> | ||
</Form.Group> | ||
<Form.Group as={Row} className='mb-3' controlId='formBasicPassword'> | ||
<Form.Label className='text-sm-end' column sm={2}> | ||
Current Password | ||
</Form.Label> | ||
<Col sm={10}> | ||
<Form.Control | ||
required | ||
type='password' | ||
placeholder='Current Password' | ||
defaultValue={currentPassword} | ||
onChange={e => { | ||
setCurrentPassword(e.target.value) | ||
}} | ||
/> | ||
</Col> | ||
</Form.Group> | ||
<Form.Group as={Row} className='mb-3' controlId='formBasicPassword'> | ||
<Form.Label className='text-sm-end' column sm={2}> | ||
New Password | ||
</Form.Label> | ||
<Col sm={10}> | ||
<Form.Control | ||
required | ||
type='password' | ||
placeholder='Password' | ||
defaultValue={newPassword} | ||
onChange={e => { | ||
setNewPassword(e.target.value) | ||
}} | ||
/> | ||
</Col> | ||
</Form.Group> | ||
<Form.Group as={Row} className='mb-3'> | ||
<Col sm={{ span: 10, offset: 2 }}> | ||
<Button variant='primary' type='submit'> | ||
Submit | ||
</Button> | ||
</Col> | ||
</Form.Group> | ||
</Form> | ||
</Col> | ||
</> | ||
) : ( | ||
<Navigate to='/' /> | ||
) | ||
} | ||
|
||
const Index: React.FC = () => ( | ||
<PageContainer> | ||
<ChangeForm /> | ||
</PageContainer> | ||
) | ||
|
||
export default Index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useRequest } from 'ahooks' | ||
import PageContainer from 'components/PageContainer' | ||
import { useState } from 'react' | ||
import { Col, Row, Form, Button, Alert } from 'react-bootstrap' | ||
import Backend from 'utils/service' | ||
|
||
const ForgotPassword: React.FC = () => { | ||
const [email, setEmail] = useState('') | ||
const [info, setInfo] = useState('') | ||
const { run } = useRequest( | ||
async () => Backend.auth.v1AuthForgotpasswordCreate({ email }), | ||
{ | ||
manual: true, | ||
onSuccess: () => { | ||
setInfo('Done! Check you email!') | ||
} | ||
} | ||
) | ||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault() | ||
run() | ||
} | ||
return ( | ||
<PageContainer> | ||
<div className='text-center'> | ||
<h1>Forgot Password</h1> | ||
</div> | ||
<Col xs={12} md={8} lg={6} className='mx-auto mt-3'> | ||
{info ? <Alert variant='success'>{info}</Alert> : null} | ||
<Form onSubmit={handleSubmit}> | ||
<Form.Group as={Row} className='mb-3' controlId='formBasicEmail'> | ||
<Form.Label className='text-sm-end' column sm={2}> | ||
</Form.Label> | ||
<Col sm={10}> | ||
<Form.Control | ||
required | ||
type='email' | ||
placeholder='Enter your email' | ||
value={email} | ||
onChange={e => setEmail(e.target.value)} | ||
/> | ||
</Col> | ||
</Form.Group> | ||
<Form.Group as={Row} className='mb-3'> | ||
<Col sm={{ span: 10, offset: 2 }}> | ||
<Button variant='primary' type='submit'> | ||
Send Reset Email | ||
</Button> | ||
</Col> | ||
</Form.Group> | ||
</Form> | ||
</Col> | ||
</PageContainer> | ||
) | ||
} | ||
|
||
export default ForgotPassword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.