summaryrefslogtreecommitdiffstats
path: root/web/react/components/claim
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2015-12-17 12:44:46 -0500
committerJoramWilander <jwawilander@gmail.com>2015-12-17 12:44:46 -0500
commita6ae90ac2a74871331707751e823b4746136ff09 (patch)
tree2651cc8adfeca84a0ee89974ba6c40f167a81123 /web/react/components/claim
parent58358ddd7cd0152bf16a7326e1d595524fb51246 (diff)
downloadchat-a6ae90ac2a74871331707751e823b4746136ff09.tar.gz
chat-a6ae90ac2a74871331707751e823b4746136ff09.tar.bz2
chat-a6ae90ac2a74871331707751e823b4746136ff09.zip
Add ability to switch between SSO and email account
Diffstat (limited to 'web/react/components/claim')
-rw-r--r--web/react/components/claim/claim_account.jsx53
-rw-r--r--web/react/components/claim/email_to_sso.jsx97
-rw-r--r--web/react/components/claim/sso_to_email.jsx113
3 files changed, 263 insertions, 0 deletions
diff --git a/web/react/components/claim/claim_account.jsx b/web/react/components/claim/claim_account.jsx
new file mode 100644
index 000000000..f38f558db
--- /dev/null
+++ b/web/react/components/claim/claim_account.jsx
@@ -0,0 +1,53 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import EmailToSSO from './email_to_sso.jsx';
+import SSOToEmail from './sso_to_email.jsx';
+
+export default class ClaimAccount extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {};
+ }
+ render() {
+ let content;
+ if (this.props.email === '') {
+ content = <p>{'No email specified.'}</p>;
+ } else if (this.props.currentType === '' && this.props.newType !== '') {
+ content = (
+ <EmailToSSO
+ email={this.props.email}
+ type={this.props.newType}
+ teamName={this.props.teamName}
+ teamDisplayName={this.props.teamDisplayName}
+ />
+ );
+ } else {
+ content = (
+ <SSOToEmail
+ email={this.props.email}
+ currentType={this.props.currentType}
+ teamName={this.props.teamName}
+ teamDisplayName={this.props.teamDisplayName}
+ />
+ );
+ }
+
+ return (
+ <div>
+ {content}
+ </div>
+ );
+ }
+}
+
+ClaimAccount.defaultProps = {
+};
+ClaimAccount.propTypes = {
+ currentType: React.PropTypes.string.isRequired,
+ newType: React.PropTypes.string.isRequired,
+ email: React.PropTypes.string.isRequired,
+ teamName: React.PropTypes.string.isRequired,
+ teamDisplayName: React.PropTypes.string.isRequired
+};
diff --git a/web/react/components/claim/email_to_sso.jsx b/web/react/components/claim/email_to_sso.jsx
new file mode 100644
index 000000000..ac0cf876b
--- /dev/null
+++ b/web/react/components/claim/email_to_sso.jsx
@@ -0,0 +1,97 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import * as Utils from '../../utils/utils.jsx';
+import * as Client from '../../utils/client.jsx';
+
+export default class EmailToSSO extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.submit = this.submit.bind(this);
+
+ this.state = {};
+ }
+ submit(e) {
+ e.preventDefault();
+ var state = {};
+
+ var password = ReactDOM.findDOMNode(this.refs.password).value.trim();
+ if (!password) {
+ state.error = 'Please enter your password.';
+ this.setState(state);
+ return;
+ }
+
+ state.error = null;
+ this.setState(state);
+
+ var postData = {};
+ postData.password = password;
+ postData.email = this.props.email;
+ postData.team_name = this.props.teamName;
+ postData.service = this.props.type;
+
+ Client.switchToSSO(postData,
+ (data) => {
+ if (data.follow_link) {
+ window.location.href = data.follow_link;
+ }
+ },
+ (error) => {
+ this.setState({error});
+ }
+ );
+ }
+ render() {
+ var error = null;
+ if (this.state.error) {
+ error = <div className='form-group has-error'><label className='control-label'>{this.state.error}</label></div>;
+ }
+
+ var formClass = 'form-group';
+ if (error) {
+ formClass += ' has-error';
+ }
+
+ const uiType = Utils.toTitleCase(this.props.type) + ' SSO';
+
+ return (
+ <div className='col-sm-12'>
+ <div className='signup-team__container'>
+ <h3>{'Switch Email/Password Account to ' + uiType}</h3>
+ <form onSubmit={this.submit}>
+ <p>{'Upon claiming your account, you will only be able to login with ' + Utils.toTitleCase(this.props.type) + ' SSO.'}</p>
+ <p>{'Enter the password for your ' + this.props.teamDisplayName + ' ' + global.window.mm_config.SiteName + ' account.'}</p>
+ <div className={formClass}>
+ <input
+ type='password'
+ className='form-control'
+ name='password'
+ ref='password'
+ placeholder='Password'
+ spellCheck='false'
+ />
+ </div>
+ {error}
+ <button
+ type='submit'
+ className='btn btn-primary'
+ >
+ {'Switch account to ' + uiType}
+ </button>
+ </form>
+ </div>
+ </div>
+ );
+ }
+}
+
+EmailToSSO.defaultProps = {
+};
+EmailToSSO.propTypes = {
+ type: React.PropTypes.string.isRequired,
+ email: React.PropTypes.string.isRequired,
+ teamName: React.PropTypes.string.isRequired,
+ teamDisplayName: React.PropTypes.string.isRequired
+};
diff --git a/web/react/components/claim/sso_to_email.jsx b/web/react/components/claim/sso_to_email.jsx
new file mode 100644
index 000000000..0868b7f2f
--- /dev/null
+++ b/web/react/components/claim/sso_to_email.jsx
@@ -0,0 +1,113 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import * as Utils from '../../utils/utils.jsx';
+import * as Client from '../../utils/client.jsx';
+
+export default class SSOToEmail 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.trim();
+ if (!password) {
+ state.error = 'Please enter a password.';
+ this.setState(state);
+ return;
+ }
+
+ const confirmPassword = ReactDOM.findDOMNode(this.refs.passwordconfirm).value.trim();
+ if (!confirmPassword || password !== confirmPassword) {
+ state.error = 'Passwords do not match.';
+ this.setState(state);
+ return;
+ }
+
+ state.error = null;
+ this.setState(state);
+
+ var postData = {};
+ postData.password = password;
+ postData.email = this.props.email;
+ postData.team_name = this.props.teamName;
+
+ Client.switchToEmail(postData,
+ (data) => {
+ if (data.follow_link) {
+ window.location.href = data.follow_link;
+ }
+ },
+ (error) => {
+ this.setState({error});
+ }
+ );
+ }
+ render() {
+ var error = null;
+ if (this.state.error) {
+ error = <div className='form-group has-error'><label className='control-label'>{this.state.error}</label></div>;
+ }
+
+ var formClass = 'form-group';
+ if (error) {
+ formClass += ' has-error';
+ }
+
+ const uiType = Utils.toTitleCase(this.props.currentType) + ' SSO';
+
+ return (
+ <div className='col-sm-12'>
+ <div className='signup-team__container'>
+ <h3>{'Switch ' + uiType + ' Account to Email'}</h3>
+ <form onSubmit={this.submit}>
+ <p>{'Upon changing your account type, you will only be able to login with your email and password.'}</p>
+ <p>{'Enter a new password for your ' + this.props.teamDisplayName + ' ' + global.window.mm_config.SiteName + ' account.'}</p>
+ <div className={formClass}>
+ <input
+ type='password'
+ className='form-control'
+ name='password'
+ ref='password'
+ placeholder='New Password'
+ spellCheck='false'
+ />
+ </div>
+ <div className={formClass}>
+ <input
+ type='password'
+ className='form-control'
+ name='passwordconfirm'
+ ref='passwordconfirm'
+ placeholder='Confirm Password'
+ spellCheck='false'
+ />
+ </div>
+ {error}
+ <button
+ type='submit'
+ className='btn btn-primary'
+ >
+ {'Switch ' + uiType + ' account to email and password'}
+ </button>
+ </form>
+ </div>
+ </div>
+ );
+ }
+}
+
+SSOToEmail.defaultProps = {
+};
+SSOToEmail.propTypes = {
+ currentType: React.PropTypes.string.isRequired,
+ email: React.PropTypes.string.isRequired,
+ teamName: React.PropTypes.string.isRequired,
+ teamDisplayName: React.PropTypes.string.isRequired
+};