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.
40 lines
1.4 KiB
JavaScript
40 lines
1.4 KiB
JavaScript
4 years ago
|
import {useSetUser} from '~/hooks/useUser'
|
||
|
import Head from 'next/head'
|
||
|
import Router from 'next/router'
|
||
|
import redirect from '~/utils/redirectGetInitialProps'
|
||
|
import {FormController, Input, Button} from '~/components/form'
|
||
|
|
||
|
ChangePassword.getInitialProps = async function({ctx, user}) {
|
||
|
if(!user)
|
||
|
return redirect(ctx, 302, '/login')
|
||
|
|
||
|
if(!user.email_confirmed)
|
||
|
return redirect(ctx, 302, '/account/email/confirm')
|
||
|
|
||
|
return {}
|
||
|
}
|
||
|
|
||
|
export default function ChangePassword() {
|
||
|
const setUser = useSetUser()
|
||
|
|
||
|
function afterChange(user) {
|
||
|
setUser(user);
|
||
|
Router.push('/account')
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
<>
|
||
|
<Head>
|
||
|
<title>Change Password | Society of Socks</title>
|
||
|
</Head>
|
||
|
<h2>Change Password</h2>
|
||
|
<FormController method="put" url="/api/users/current/password" afterSubmit={afterChange}>
|
||
|
<Input label="Current Password" type="password" name="oldPassword" validate={value=>(value.length >= 8)} hint="Password must be at least 8 characters long" />
|
||
|
<Input label="New 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">Change Password</Button>
|
||
|
</FormController>
|
||
|
|
||
|
</>
|
||
|
)
|
||
|
}
|