-
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 functionality for forgot password requests
- Loading branch information
1 parent
dd1d56c
commit a439fd0
Showing
13 changed files
with
326 additions
and
14 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 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 |
---|---|---|
|
@@ -19,3 +19,4 @@ pydantic[email]==2.4.2 | |
langchain==0.0.351 | ||
pytest==6.2.5 | ||
pytest-asyncio==0.15.1 | ||
sendgrid==6.11.0 |
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,26 @@ | ||
from sendgrid import SendGridAPIClient | ||
from sendgrid.helpers.mail import Mail, TrackingSettings, ClickTracking | ||
from typing import List | ||
|
||
from settings import APP_ENV, APP_HOST, SENDGRID_API_KEY | ||
|
||
|
||
async def send_password_reset_email(email: List[str], token: str): | ||
message = Mail( | ||
from_email="[email protected]", | ||
to_emails=email, | ||
subject="DocShow AI - Password Reset Request", | ||
html_content=f'Click on the link to reset your password: <a href="https://{APP_HOST}/reset-password?token={token}">https://{APP_HOST}/reset-password</a>', | ||
) | ||
# Disable click tracking in development | ||
if APP_ENV == "development": | ||
message.tracking_settings = TrackingSettings() | ||
message.tracking_settings.click_tracking = ClickTracking(False, False) | ||
try: | ||
sg = SendGridAPIClient(SENDGRID_API_KEY) | ||
response = await sg.send(message) | ||
print(response.status_code) | ||
print(response.body) | ||
print(response.headers) | ||
except Exception as e: | ||
print(str(e)) |
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,70 @@ | ||
import React, { useState } from 'react'; | ||
import { Box, Button, TextField, Typography } from '@mui/material'; | ||
import Alert from '@mui/material/Alert'; | ||
import axios from 'axios'; | ||
import validator from 'validator'; | ||
import { API_URL } from '../../utils/constants'; | ||
|
||
function ForgotPasswordPage() { | ||
const [email, setEmail] = useState(''); | ||
const [errorMessage, setErrorMessage] = useState(''); | ||
|
||
const handleSubmit = async (event) => { | ||
event.preventDefault(); | ||
|
||
// Validate email | ||
if (!validator.isEmail(email)) { | ||
setErrorMessage('Please enter a valid email address.'); | ||
return; | ||
} | ||
|
||
// Send request to backend server | ||
try { | ||
await axios.post(`${API_URL}users/forgot-password/`, { email }); | ||
alert('Password reset email sent!'); | ||
} catch (error) { | ||
setErrorMessage('Error sending password reset email. Please try again.'); | ||
} | ||
}; | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
marginTop: 8, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<Typography component="h1" variant="h5"> | ||
Forgot Password | ||
</Typography> | ||
<Box component="form" onSubmit={handleSubmit} noValidate sx={{ mt: 1 }}> | ||
<TextField | ||
variant="outlined" | ||
margin="normal" | ||
required | ||
fullWidth | ||
id="email" | ||
label="Email Address" | ||
name="email" | ||
autoComplete="email" | ||
autoFocus | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
/> | ||
<Button | ||
type="submit" | ||
fullWidth | ||
variant="contained" | ||
sx={{ mt: 3, mb: 2 }} | ||
> | ||
Reset Password | ||
</Button> | ||
</Box> | ||
{errorMessage && <Alert severity="error">{errorMessage}</Alert>} | ||
</Box> | ||
); | ||
} | ||
|
||
export default ForgotPasswordPage; |
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.