Merge branch 'master' of gitlab.com:pawnstar/sos-nextjs
commit
99d2a65e17
@ -0,0 +1,40 @@
|
||||
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>
|
||||
|
||||
</>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue