-
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.
add password requirements, configure registration page
- Loading branch information
1 parent
0849bb8
commit b6c5253
Showing
5 changed files
with
169 additions
and
115 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
This file was deleted.
Oops, something went wrong.
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,81 @@ | ||
import React, { useState } from "react"; | ||
import { Alert, Box, Button, Checkbox, FormControlLabel, TextField, Typography } from "@mui/material"; | ||
|
||
function RegisterForm({ onSubmit, errorMessage }) { | ||
const [username, setUsername] = useState(''); | ||
const [email, setEmail] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
const [subscribe, setSubscribe] = useState(false); | ||
|
||
const handleFormSubmit = async (event) => { | ||
event.preventDefault(); | ||
await onSubmit(username, email, password); | ||
}; | ||
|
||
return ( | ||
<Box component="form" onSubmit={handleFormSubmit} noValidate sx={{ mt: 1 }}> | ||
<TextField | ||
margin="normal" | ||
required | ||
fullWidth | ||
id="username" | ||
label="Username" | ||
name="username" | ||
autoComplete="username" | ||
autoFocus | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
/> | ||
<TextField | ||
margin="normal" | ||
required | ||
fullWidth | ||
id="email" | ||
label="Email Address" | ||
name="email" | ||
autoComplete="email" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
/> | ||
<TextField | ||
margin="normal" | ||
required | ||
fullWidth | ||
name="password" | ||
label="Password" | ||
type="password" | ||
id="password" | ||
autoComplete="new-password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
/> | ||
<FormControlLabel | ||
control={<Checkbox value="subscribe" color="primary" />} | ||
label="I want to receive inspiration, marketing promotions and updates via email." | ||
checked={subscribe} | ||
onChange={(e) => setSubscribe(e.target.checked)} | ||
/> | ||
{errorMessage && | ||
<Box mt={2} mb={2}> | ||
<Alert severity="error">{errorMessage}</Alert> | ||
</Box> | ||
} | ||
<Button | ||
type="submit" | ||
fullWidth | ||
variant="contained" | ||
sx={{ mt: 3, mb: 2 }} | ||
> | ||
SIGN UP | ||
</Button> | ||
<Typography align="center" sx={{ mt: 2 }}> | ||
Already have an account? | ||
<Button onClick={() => navigate('/login')}> | ||
Sign in | ||
</Button> | ||
</Typography> | ||
</Box> | ||
) | ||
}; | ||
|
||
export default RegisterForm; |
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,73 @@ | ||
import React, { useState } from 'react'; | ||
import axios from 'axios'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { Alert, Box, Button, Checkbox, Container, FormControlLabel, TextField, Typography } from '@mui/material'; | ||
import LockOutlinedIcon from '@mui/icons-material/LockOutlined'; | ||
import RegisterForm from './RegisterForm'; | ||
import { useAuth } from '../../contexts/AuthContext'; | ||
import { API_URL } from '../../utils/constants'; | ||
|
||
function RegisterPage() { | ||
const [subscribe, setSubscribe] = useState(false); | ||
const [errorMessage, setErrorMessage] = useState(''); | ||
const { updateAuth } = useAuth(); | ||
const navigate = useNavigate(); | ||
|
||
const handleSubmit = async (username, email, password) => { | ||
try { | ||
const response = await axios.post(`${API_URL}register/`, { | ||
username, | ||
email, | ||
password, | ||
// You can add subscribe or any additional fields if required by your API | ||
}); | ||
|
||
if (response.data.message === 'Registration successful') { | ||
updateAuth(true); | ||
navigate('/login'); | ||
} | ||
} catch (error) { | ||
if (error.response) { | ||
if (error.response.status === 400) { | ||
setErrorMessage(error.response.data.detail); | ||
} else if (error.response.data && error.response.data.detail && error.response.data.detail[0]) { | ||
let errorMessage = error.response.data.detail[0].msg; | ||
if (typeof errorMessage === 'string') { | ||
errorMessage = errorMessage.replace('Value error, ', ''); | ||
setErrorMessage(errorMessage); | ||
} | ||
} | ||
} else if (error.request) { | ||
// The request was made but no response was received | ||
console.log(error.request); | ||
} else { | ||
// Something happened in setting up the request that triggered an Error | ||
console.log('Error', error.message) | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<Container component="main" maxWidth="xs"> | ||
<Box | ||
sx={{ | ||
marginTop: 8, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<LockOutlinedIcon color="secondary" sx={{ m: 1, bgcolor: 'background.paper', borderRadius: '50%' }} /> | ||
<Typography component="h1" variant="h5"> | ||
Sign up | ||
</Typography> | ||
<RegisterForm onSubmit={handleSubmit} errorMessage={errorMessage} /> | ||
<Typography variant="body2" color="text.secondary" align="center" sx={{ mt: 5 }}> | ||
Copyright © DocShow AI 2024. | ||
</Typography> | ||
</Box> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default RegisterPage; |