forked from roadmapsh/deprecated-version
-
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.
- Loading branch information
1 parent
725aa2b
commit 3072e42
Showing
4 changed files
with
122 additions
and
151 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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { useEffect, useState } from 'preact/hooks'; | ||
import Spinner from '../Spinner'; | ||
import { httpPost } from '../../lib/http'; | ||
import Cookies from 'js-cookie'; | ||
import { TOKEN_COOKIE_NAME } from '../../lib/constants'; | ||
|
||
export default function ResetPasswordForm() { | ||
const [code, setCode] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
const [passwordConfirm, setPasswordConfirm] = useState(''); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [error, setError] = useState(''); | ||
|
||
useEffect(() => { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
const code = urlParams.get('code'); | ||
|
||
if (!code) { | ||
window.location.href = '/login'; | ||
} else { | ||
setCode(code); | ||
} | ||
}, []); | ||
|
||
const handleSubmit = async (e: Event) => { | ||
e.preventDefault(); | ||
setIsLoading(true); | ||
|
||
if (password !== passwordConfirm) { | ||
setIsLoading(false); | ||
setError('Passwords do not match.'); | ||
return; | ||
} | ||
|
||
const { response, error } = await httpPost( | ||
`${import.meta.env.PUBLIC_API_URL}/v1-reset-forgotten-password`, | ||
{ | ||
newPassword: password, | ||
confirmPassword: passwordConfirm, | ||
code, | ||
} | ||
); | ||
|
||
if (error?.message) { | ||
setIsLoading(false); | ||
setError(error.message); | ||
return; | ||
} | ||
|
||
if (!response?.token) { | ||
setIsLoading(false); | ||
setError('Something went wrong. Please try again later.'); | ||
return; | ||
} | ||
|
||
const token = response.token; | ||
Cookies.set(TOKEN_COOKIE_NAME, token); | ||
window.location.href = '/'; | ||
}; | ||
|
||
return ( | ||
<form className="mx-auto w-full" onSubmit={handleSubmit}> | ||
<input | ||
type="password" | ||
className="mb-2 mt-2 block w-full appearance-none rounded-lg border border-gray-300 px-3 py-2 shadow-sm outline-none transition duration-150 ease-in-out placeholder:text-gray-400 focus:ring-2 focus:ring-black focus:ring-offset-1" | ||
required | ||
minLength={6} | ||
placeholder="New Password" | ||
value={password} | ||
onInput={(e) => setPassword((e.target as HTMLInputElement).value)} | ||
/> | ||
|
||
<input | ||
type="password" | ||
className="mt-2 block w-full appearance-none rounded-lg border border-gray-300 px-3 py-2 shadow-sm outline-none transition duration-150 ease-in-out placeholder:text-gray-400 focus:ring-2 focus:ring-black focus:ring-offset-1" | ||
required | ||
minLength={6} | ||
placeholder="Confirm New Password" | ||
value={passwordConfirm} | ||
onInput={(e) => | ||
setPasswordConfirm((e.target as HTMLInputElement).value) | ||
} | ||
/> | ||
|
||
{error && ( | ||
<p className="mt-2 rounded-lg bg-red-100 p-2 text-red-700">{error}</p> | ||
)} | ||
|
||
<button | ||
type="submit" | ||
disabled={isLoading} | ||
className="mt-2 inline-flex w-full items-center justify-center rounded-lg bg-black p-2 py-3 text-sm font-medium text-white outline-none focus:ring-2 focus:ring-black focus:ring-offset-1 disabled:bg-gray-400" | ||
> | ||
{isLoading ? 'Please wait...' : 'Reset Password'} | ||
</button> | ||
</form> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,22 +1,23 @@ | ||
--- | ||
import ResetPasswordForm from '../components/Profile/ResetPasswordForm'; | ||
import ResetPasswordForm from '../components/AuthenticationFlow/ResetPasswordForm'; | ||
import SettingLayout from '../layouts/SettingLayout.astro'; | ||
--- | ||
|
||
<SettingLayout title='Reset Password'> | ||
<div class='container py-16'> | ||
<ResetPasswordForm client:load /> | ||
<div class='container'> | ||
<div | ||
class='mx-auto flex flex-col items-start justify-start pb-28 pt-10 sm:max-w-[400px] sm:items-center sm:justify-center sm:pt-20' | ||
> | ||
<div class='mb-2 text-left sm:mb-5 sm:text-center'> | ||
<h1 class='mb-2 text-3xl font-semibold sm:mb-5 sm:text-5xl'> | ||
Reset Password | ||
</h1> | ||
<p class='mb-3 text-base leading-6 text-gray-600'> | ||
Enter and confirm your new password below. | ||
</p> | ||
</div> | ||
|
||
<ResetPasswordForm client:load /> | ||
</div> | ||
</div> | ||
</SettingLayout> | ||
|
||
<script> | ||
import Cookies from 'js-cookie'; | ||
import { TOKEN_COOKIE_NAME } from '../lib/constants'; | ||
const token = Cookies.get(TOKEN_COOKIE_NAME); | ||
const urlParams = new URLSearchParams(window.location.search); | ||
const code = urlParams.get('code'); | ||
|
||
if (!code || token) { | ||
window.location.href = '/settings/profile'; | ||
} | ||
</script> |