import React from 'react'; // jshint ignore:line import Button from 'misago/components/button'; // jshint ignore:line import Form from 'misago/components/form'; import FormGroup from 'misago/components/form-group'; // jshint ignore:line import ajax from 'misago/services/ajax'; import snackbar from 'misago/services/snackbar'; export default class extends Form { constructor(props) { super(props); this.state = { new_password: '', repeat_password: '', password: '', validators: { new_password: [], repeat_password: [], password: [] }, isLoading: false }; } clean() { let errors = this.validate(); let lengths = [ this.state.new_password.trim().length, this.state.repeat_password.trim().length, this.state.password.trim().length ]; if (lengths.indexOf(0) !== -1) { snackbar.error(gettext("Fill out all fields.")); return false; } if (errors.new_password) { snackbar.error(errors.new_password[0]); return false; } if (this.state.new_password.trim() !== this.state.repeat_password.trim()) { snackbar.error(gettext("New passwords are different.")); return false; } return true; } send() { return ajax.post(this.props.user.api.change_password, { new_password: this.state.new_password, password: this.state.password }); } handleSuccess(response) { this.setState({ new_password: '', repeat_password: '', password: '' }); snackbar.success(response.detail); } handleError(rejection) { if (rejection.status === 400) { if (rejection.new_password) { snackbar.error(rejection.new_password); } else { snackbar.error(rejection.password); } } else { snackbar.apiError(rejection); } } render() { /* jshint ignore:start */ return

{gettext("Change password")}


; /* jshint ignore:end */ } }