Initial commit
This commit is contained in:
93
website/src/Auth/ResetPassword.js
Normal file
93
website/src/Auth/ResetPassword.js
Normal file
@@ -0,0 +1,93 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Container, Header, Form, Message } from 'semantic-ui-react'
|
||||
import './ResetPassword.scss'
|
||||
import { Validator, ValidatedInput, ValidatedButton } from '../Validated'
|
||||
import { MessageDialog, WaitDialog } from '../Dialog'
|
||||
import { api } from '../helpers'
|
||||
|
||||
export class ResetPassword extends React.Component {
|
||||
static propTypes = {
|
||||
history: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
|
||||
}
|
||||
|
||||
static validations = {
|
||||
newPassword: {
|
||||
alwaysGet: true,
|
||||
isValid: (r, v) => (v.length >= 6)
|
||||
},
|
||||
reenteredNewPassword: {
|
||||
isValid: (r, v) => (v !== '' && v === r.getField('newPassword').value)
|
||||
},
|
||||
submit: {
|
||||
nonValue: true,
|
||||
isDisabled: (r) => (!r.anyModified && !r.allValid)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
validator: new Validator({}, ResetPassword.validations),
|
||||
messageDialog: null,
|
||||
waitDialog: null
|
||||
}
|
||||
this.handleSubmit = this.handleSubmit.bind(this)
|
||||
this.handleMessageDialogDismiss = this.handleMessageDialogDismiss.bind(this)
|
||||
}
|
||||
|
||||
handleSubmit() {
|
||||
const obj = this.state.validator.getValues()
|
||||
const passwordToken = new URLSearchParams(decodeURIComponent(window.location.search)).get('password-token')
|
||||
|
||||
this.setState({ waitDialog: { message: 'Setting Password...' } })
|
||||
api.resetPassword({ newPassword: obj.newPassword, passwordToken }).then(() => {
|
||||
this.setState({ waitDialog: null })
|
||||
this.props.history.replace('/login')
|
||||
}).catch((error) => {
|
||||
this.setState({
|
||||
validator: new Validator({}, ResetPassword.validations), // Reset to avoid accidental rapid retries
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
title: 'We had a problem changing your password',
|
||||
message: error.message
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
handleMessageDialogDismiss() {
|
||||
this.setState({ messageDialog: null })
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container className='password-reset-container'>
|
||||
<Header content='Reset Password' size='large' />
|
||||
<Form size='large' onSubmit={this.handleSubmit}>
|
||||
<ValidatedInput label='New Password' password name='newPassword'
|
||||
message='A new password, cannot be blank or the same as your old password'
|
||||
width={16} validator={this.state.validator} />
|
||||
<ValidatedInput label='Re-entered New Password' password name='reenteredNewPassword'
|
||||
message='The new password again, must match and cannot be blank'
|
||||
width={16} validator={this.state.validator} />
|
||||
<Message info>
|
||||
Passwords can contain special characters and are discouraged from being simple or reused from other sites or applications.
|
||||
<br /><br />
|
||||
Passwords must be at least 6 characters long.
|
||||
</Message>
|
||||
<ValidatedButton className='submit' name='submit' content='Submit'
|
||||
primary submit validator={this.state.validator} />
|
||||
</Form>
|
||||
|
||||
<MessageDialog error open={!!this.state.messageDialog}
|
||||
title={this.state.messageDialog ? this.state.messageDialog.title : ''}
|
||||
message={this.state.messageDialog ? this.state.messageDialog.message : ''}
|
||||
onDismiss={this.handleMessageDialogDismiss} />
|
||||
|
||||
<WaitDialog active={!!this.state.waitDialog}
|
||||
message={this.state.waitDialog ? this.state.waitDialog.message : ''} />
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user