// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import * as Utils from 'utils/utils.jsx'; import Constants from 'utils/constants.jsx'; import PropTypes from 'prop-types'; import React from 'react'; import ReactDOM from 'react-dom'; import {FormattedMessage} from 'react-intl'; import {oauthToEmail} from 'actions/admin_actions.jsx'; export default class OAuthToEmail extends React.Component { constructor(props) { super(props); this.submit = this.submit.bind(this); this.state = {}; } submit(e) { e.preventDefault(); const state = {}; const password = ReactDOM.findDOMNode(this.refs.password).value; if (!password) { state.error = Utils.localizeMessage('claim.oauth_to_email.enterPwd', 'Please enter a password.'); this.setState(state); return; } const passwordErr = Utils.isValidPassword(password); if (passwordErr !== '') { this.setState({ error: passwordErr }); return; } const confirmPassword = ReactDOM.findDOMNode(this.refs.passwordconfirm).value; if (!confirmPassword || password !== confirmPassword) { state.error = Utils.localizeMessage('claim.oauth_to_email.pwdNotMatch', 'Password do not match.'); this.setState(state); return; } state.error = null; this.setState(state); oauthToEmail( this.props.currentType, this.props.email, password, null, (err) => { this.setState({error: err.message}); } ); } render() { var error = null; if (this.state.error) { error =
; } var formClass = 'form-group'; if (error) { formClass += ' has-error'; } const uiType = `${(this.props.currentType === Constants.SAML_SERVICE ? Constants.SAML_SERVICE.toUpperCase() : Utils.toTitleCase(this.props.currentType))} SSO`; return (

{error}
); } } OAuthToEmail.defaultProps = { }; OAuthToEmail.propTypes = { currentType: PropTypes.string, email: PropTypes.string };