-
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.
create admin user on startup in prod, create change password page tha…
…t is used whenever a users requires a password update, fix bug where fields are not reset upon successfuly password change
- Loading branch information
1 parent
e6ef757
commit 828bf00
Showing
9 changed files
with
112 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ def create_admin_user(): | |
email="[email protected]", | ||
organization_id=1, | ||
role="admin", | ||
requires_password_update=True, | ||
) | ||
|
||
with DatabaseManager() as session: | ||
|
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 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 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,40 @@ | ||
import React, { useState } from 'react' | ||
import { useNavigate } from 'react-router-dom'; | ||
import { Box, Container, Typography } from '@mui/material' | ||
import LockOutlinedIcon from '@mui/icons-material/LockOutlined'; | ||
import ChangePassword from '../../components/change-password/ChangePassword'; | ||
import { updateUserPassword } from '../../utils/updateUserPassword'; | ||
|
||
function ChangePasswordPage() { | ||
const navigate = useNavigate(); | ||
const [errorMessage, setErrorMessage] = useState(''); | ||
const [successMessage, setSuccessMessage] = useState(''); | ||
|
||
const handleChangePassword = async (oldPassword, newPassword, confirmPassword) => { | ||
const success = await updateUserPassword(oldPassword, newPassword, confirmPassword, setErrorMessage, setSuccessMessage); | ||
if (success) { | ||
navigate('/dashboards'); | ||
} | ||
}; | ||
|
||
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"> | ||
Change Password | ||
</Typography> */} | ||
<ChangePassword handleChangePassword={handleChangePassword} errorMessage={errorMessage} successMessage={successMessage} /> | ||
</Box> | ||
</Container> | ||
) | ||
} | ||
|
||
export default ChangePasswordPage |
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 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,40 @@ | ||
import axios from 'axios'; | ||
import { API_URL } from './constants'; | ||
|
||
export const updateUserPassword = async (oldPassword, newPassword, confirmPassword, setErrorMessage, setSuccessMessage) => { | ||
if (newPassword !== confirmPassword) { | ||
setErrorMessage('Passwords do not match!'); | ||
return false; | ||
} | ||
|
||
try { | ||
const response = await axios.put(`${API_URL}users/change-password/`, { old_password: oldPassword, new_password: newPassword }); | ||
|
||
console.log('Server response status:', response.status); // Add this line | ||
|
||
if (response.status === 200) { | ||
console.log('Password changed successfully') | ||
setSuccessMessage('Password changed successfully'); | ||
setErrorMessage(''); | ||
return true; | ||
} else { | ||
setErrorMessage('Failed to change password!'); | ||
setSuccessMessage(''); | ||
return false; | ||
} | ||
} 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') { | ||
setErrorMessage(errorMessage); | ||
} | ||
} | ||
} | ||
} | ||
setErrorMessage(errorMessage); | ||
setSuccessMessage(''); | ||
return false; | ||
}; |