// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import * as Client from '../utils/client.jsx'; import Constants from '../utils/constants.jsx'; import {injectIntl, intlShape, defineMessages, FormattedMessage, FormattedHTMLMessage} from 'mm-intl'; const holders = defineMessages({ error: { id: 'password_form.error', defaultMessage: 'Please enter at least {chars} characters.' }, update: { id: 'password_form.update', defaultMessage: 'Your password has been updated successfully.' }, pwd: { id: 'password_form.pwd', defaultMessage: 'Password' } }); class PasswordResetForm extends React.Component { constructor(props) { super(props); this.handlePasswordReset = this.handlePasswordReset.bind(this); this.state = {}; } handlePasswordReset(e) { e.preventDefault(); const {formatMessage} = this.props.intl; var state = {}; var password = ReactDOM.findDOMNode(this.refs.password).value.trim(); if (!password || password.length < Constants.MIN_PASSWORD_LENGTH) { state.error = formatMessage(holders.error, {chars: Constants.MIN_PASSWORD_LENGTH}); this.setState(state); return; } state.error = null; this.setState(state); var data = {}; data.new_password = password; data.hash = this.props.hash; data.data = this.props.data; data.name = this.props.teamName; Client.resetPassword(data, function resetSuccess() { this.setState({error: null, updateText: formatMessage(holders.update)}); }.bind(this), function resetFailure(err) { this.setState({error: err.message, updateText: null}); }.bind(this) ); } render() { var updateText = null; if (this.state.updateText) { updateText = (