-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
user can now reset password from a link given in email
- Loading branch information
1 parent
217b8c7
commit 1e416ad
Showing
7 changed files
with
147 additions
and
15 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
client/src/components/Ecommerce/Screen/ForgetPasswordScreen.js
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,52 @@ | ||
import axios from 'axios' | ||
import React, { useState } from 'react' | ||
import { Button, Form } from 'react-bootstrap' | ||
import FormContainer from '../FormContainer' | ||
import Message from '../Message' | ||
import { toastInfoMessage } from '../ToastMessage' | ||
|
||
function ForgetPasswordScreen() { | ||
const [email, setEmail] = useState('') | ||
const [error, setError] = useState('') | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault() | ||
|
||
const config = { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
} | ||
|
||
try { | ||
await axios.post("/api/users/forget-password", { email }, config) | ||
toastInfoMessage("Instructions to reset your password has been sent to your email") | ||
|
||
} catch (error) { | ||
setError(error.response && error.response.data.message ? error.response.data.message : error.message) | ||
setEmail('') | ||
setTimeout(() => { | ||
setError("") | ||
}, 3000); | ||
|
||
} | ||
} | ||
return ( | ||
<FormContainer> | ||
<h1 className='py-2'>Forget Password ?</h1> | ||
<p className='mb-5'>Enter the email address you used when you joined and we’ll send you instructions to reset your password.</p> | ||
{error && <Message variant='danger'>{error}</Message>} | ||
|
||
<Form onSubmit={handleSubmit}> | ||
<Form.Group controlId="email" className='mb-3 mt-5'> | ||
<Form.Label>Email Address</Form.Label> | ||
<Form.Control type="email" placeholder="Enter email" value={email} onChange={(e)=> setEmail(e.target.value)} /> | ||
</Form.Group> | ||
|
||
<Button type='submit' variant='primary' className="auth-btn" >Submit</Button> | ||
</Form> | ||
</FormContainer> | ||
) | ||
} | ||
|
||
export default ForgetPasswordScreen |
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
76 changes: 76 additions & 0 deletions
76
client/src/components/Ecommerce/Screen/PasswordResetScreen.js
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,76 @@ | ||
import axios from 'axios' | ||
import React, { useState } from 'react' | ||
import { Button, Form } from 'react-bootstrap' | ||
import FormContainer from '../FormContainer' | ||
import Message from '../Message' | ||
import { toastSuccessMessage } from '../ToastMessage' | ||
|
||
function ForgetPasswordScreen({match,history}) { | ||
const [password, setPassword] = useState('') | ||
const [confirmPassword, setConfirmPassword] = useState('') | ||
const [error, setError] = useState('') | ||
|
||
const clear = (errorText) => { | ||
setPassword("") | ||
setConfirmPassword("") | ||
setTimeout(() => { | ||
setError("") | ||
}, 3000); | ||
return setError(errorText) | ||
} | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault() | ||
|
||
if (password.length < 6) { | ||
return clear("Password must be at least 6 characters") | ||
} | ||
if (password !== confirmPassword) { | ||
return clear("Password doesn't match") | ||
} | ||
|
||
|
||
const config = { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
} | ||
|
||
|
||
try { | ||
await axios.put(`/api/users/reset-password/${match.params.resetToken}`, { password }, config) | ||
toastSuccessMessage("You're password has been updated") | ||
history.push("/") | ||
|
||
} catch (error) { | ||
setError(error.response && error.response.data.message ? error.response.data.message : error.message) | ||
setPassword("") | ||
setConfirmPassword("") | ||
setTimeout(() => { | ||
setError("") | ||
}, 3000); | ||
|
||
} | ||
} | ||
return ( | ||
<FormContainer> | ||
<h2 className='py-3 text-center'>Reset Your Password</h2> | ||
{error && <Message variant='danger'>{error}</Message>} | ||
<Form onSubmit={handleSubmit}> | ||
<Form.Group controlId="password" className='mb-3'> | ||
<Form.Label>Password</Form.Label> | ||
<Form.Control type="password" placeholder="Enter password" value={password} onChange={(e)=> setPassword(e.target.value)} /> | ||
</Form.Group> | ||
|
||
<Form.Group controlId="confirmPassword" className='mb-4'> | ||
<Form.Label>Retype Password</Form.Label> | ||
<Form.Control type="password" placeholder="Confirm Password" value={confirmPassword} onChange={(e)=> setConfirmPassword(e.target.value)} /> | ||
</Form.Group> | ||
|
||
<Button type='submit' variant='primary' className="auth-btn" >Submit</Button> | ||
</Form> | ||
</FormContainer> | ||
) | ||
} | ||
|
||
export default ForgetPasswordScreen |
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