From 10b0b4462107ecebffab4ce3eb0435d3c1b2dd24 Mon Sep 17 00:00:00 2001 From: elijah Date: Thu, 29 Sep 2016 17:00:47 -0700 Subject: [feat] ui - allow users to change their passwords --- ui/app/components/main_panel/user_password_form.js | 123 +++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 ui/app/components/main_panel/user_password_form.js (limited to 'ui/app/components/main_panel/user_password_form.js') diff --git a/ui/app/components/main_panel/user_password_form.js b/ui/app/components/main_panel/user_password_form.js new file mode 100644 index 0000000..5e26b19 --- /dev/null +++ b/ui/app/components/main_panel/user_password_form.js @@ -0,0 +1,123 @@ +// +// A form to change the user password +// + +import React from 'react' +import { Button, Glyphicon, Alert } from 'react-bootstrap' +import Spinner from 'components/spinner' +import PasswordField from 'components/password_field' +import Account from 'models/account' +import bitmask from 'lib/bitmask' + +export default class UserPasswordForm extends React.Component { + + static get defaultProps() {return{ + account: null, + }} + + constructor(props) { + super(props) + this.state = { + error: null, + message: null, + loading: false, + currentPassword: null, + newPassword: null, + repeatPassword: null + } + this.submit = this.submit.bind(this) + this.setNew = this.setNew.bind(this) + this.setCurrent = this.setCurrent.bind(this) + this.setRepeat = this.setRepeat.bind(this) + } + + setCurrent(value) { + this.setState({currentPassword: value}) + } + + setNew(value) { + this.setState({newPassword: value}) + } + + setRepeat(value) { + this.setState({repeatPassword: value}) + } + + submit(e) { + e.preventDefault() // don't reload the page please! + if (!this.maySubmit()) { return } + this.setState({loading: true}) + bitmask.bonafide.user.update( + this.props.account.address, + this.state.currentPassword, + this.state.newPassword).then( + response => { + this.setState({ + currentPassword: null, + newPassword: null, + repeatPassword: null, + message: response, + error: null, + loading: false + }) + }, error => { + this.setState({ + error: error, + message: null, + loading: false + }) + } + ) + } + + maySubmit() { + return ( + !this.state.loading && + this.state.currentPassword && + this.state.newPassword && + this.state.newPassword == this.state.repeatPassword + ) + } + + render () { + let submitButton = null + let message = null + + // style may be: success, warning, danger, info + if (this.state.error) { + message = ( + {this.state.error} + ) + } else if (this.state.message) { + message = ( + {this.state.message} + ) + } + + if (this.state.loading) { + submitButton = + } else { + submitButton = + } + return ( +
+ {message} + + + + {submitButton} + + ) + } + +} -- cgit v1.2.3