You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
4 years ago
|
import React from 'react'
|
||
|
import Link from 'next/link'
|
||
|
import Router from 'next/router'
|
||
|
import axios from 'axios'
|
||
|
import Head from 'next/head'
|
||
|
|
||
|
import {useSetUser} from '~/hooks/useUser'
|
||
|
import {FormController, Input, Button} from '~/components/form'
|
||
|
import useAccountRedirect from '~/hooks/useAccountRedirect'
|
||
|
|
||
|
ResetPassword.getInitialProps = async ({ctx}) => {
|
||
|
const {id, key} = ctx.query
|
||
|
|
||
|
return {
|
||
|
link_uuid: id,
|
||
|
link_key: key
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default function ResetPassword({link_uuid, link_key}){
|
||
|
useAccountRedirect()
|
||
|
const setUser = useSetUser()
|
||
|
|
||
|
async function submitReset({password, password2}) {
|
||
|
const {data: user} = await axios.post(`/api/users/recover/password`, {
|
||
|
password,
|
||
|
password2,
|
||
|
link_uuid,
|
||
|
link_key,
|
||
|
})
|
||
|
|
||
|
setUser(user)
|
||
|
|
||
|
if (user.is_admin)
|
||
|
Router.push('/admin')
|
||
|
else
|
||
|
Router.push('/account')
|
||
|
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
<>
|
||
|
<Head>
|
||
|
<title>Reset Password | Society of Socks</title>
|
||
|
</Head>
|
||
|
<FormController afterSubmit={submitReset}>
|
||
|
<h1>Reset Password</h1>
|
||
|
<Input label="Password" type="password" name="password" validate={value=>(value.length >= 8)} hint="Password must be at least 8 characters long" />
|
||
|
<Input label="Repeat password" type="password" name="password2" validate={(value, fields)=>(value === fields.password.value)} hint="Passwords must match" />
|
||
|
<Button type="submit">Reset Password</Button>
|
||
|
</FormController>
|
||
|
</>
|
||
|
)
|
||
|
}
|