From 12896bd23eeba79884245c1c29fdc568cf21a7fa Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 14 Mar 2016 08:50:46 -0400 Subject: Converting to Webpack. Stage 1. --- .../admin_console/reset_password_modal.jsx | 162 +++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 webapp/components/admin_console/reset_password_modal.jsx (limited to 'webapp/components/admin_console/reset_password_modal.jsx') diff --git a/webapp/components/admin_console/reset_password_modal.jsx b/webapp/components/admin_console/reset_password_modal.jsx new file mode 100644 index 000000000..f80c740e3 --- /dev/null +++ b/webapp/components/admin_console/reset_password_modal.jsx @@ -0,0 +1,162 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import ReactDOM from 'react-dom'; +import * as Client from 'utils/client.jsx'; +import Constants from 'utils/constants.jsx'; +import {Modal} from 'react-bootstrap'; + +import {injectIntl, intlShape, defineMessages, FormattedMessage} from 'react-intl'; + +var holders = defineMessages({ + submit: { + id: 'admin.reset_password.submit', + defaultMessage: 'Please enter at least {chars} characters.' + } +}); + +import React from 'react'; + +class ResetPasswordModal extends React.Component { + constructor(props) { + super(props); + + this.doSubmit = this.doSubmit.bind(this); + this.doCancel = this.doCancel.bind(this); + + this.state = { + serverError: null + }; + } + + doSubmit(e) { + e.preventDefault(); + var password = ReactDOM.findDOMNode(this.refs.password).value; + + if (!password || password.length < Constants.MIN_PASSWORD_LENGTH) { + this.setState({serverError: this.props.intl.formatMessage(holders.submit, {chars: Constants.MIN_PASSWORD_LENGTH})}); + return; + } + + this.setState({serverError: null}); + + var data = {}; + data.new_password = password; + data.name = this.props.team.name; + data.user_id = this.props.user.id; + + Client.resetPassword(data, + () => { + this.props.onModalSubmit(ReactDOM.findDOMNode(this.refs.password).value); + }, + (err) => { + this.setState({serverError: err.message}); + } + ); + } + + doCancel() { + this.setState({serverError: null}); + this.props.onModalDismissed(); + } + + render() { + if (this.props.user == null) { + return
; + } + + let urlClass = 'input-group input-group--limit'; + let serverError = null; + + if (this.state.serverError) { + urlClass += ' has-error'; + serverError =

{this.state.serverError}

; + } + + return ( + + + + + + +
+ +
+
+
+ + + + +
+ {serverError} +
+
+
+ + + + +
+
+ ); + } +} + +ResetPasswordModal.defaultProps = { + show: false +}; + +ResetPasswordModal.propTypes = { + intl: intlShape.isRequired, + user: React.PropTypes.object, + team: React.PropTypes.object, + show: React.PropTypes.bool.isRequired, + onModalSubmit: React.PropTypes.func, + onModalDismissed: React.PropTypes.func +}; + +export default injectIntl(ResetPasswordModal); \ No newline at end of file -- cgit v1.2.3-1-g7c22