2017-06-14 11:31:16 +03:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
2018-06-18 20:17:10 +03:00
|
|
|
Copyright 2018 New Vector Ltd
|
2017-06-14 11:31:16 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2019-08-24 13:59:46 +03:00
|
|
|
import createReactClass from 'create-react-class';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-06-14 11:31:16 +03:00
|
|
|
import sdk from '../../../index';
|
|
|
|
import Email from '../../../email';
|
|
|
|
import AddThreepid from '../../../AddThreepid';
|
2017-06-14 12:53:02 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2017-06-14 11:31:16 +03:00
|
|
|
import Modal from '../../../Modal';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prompt the user to set an email address.
|
|
|
|
*
|
|
|
|
* On success, `onFinished(true)` is called.
|
|
|
|
*/
|
2019-08-24 13:59:46 +03:00
|
|
|
export default createReactClass({
|
2017-06-14 11:31:16 +03:00
|
|
|
displayName: 'SetEmailDialog',
|
|
|
|
propTypes: {
|
2017-12-26 04:03:18 +03:00
|
|
|
onFinished: PropTypes.func.isRequired,
|
2017-06-14 11:31:16 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2018-06-18 20:17:10 +03:00
|
|
|
emailAddress: '',
|
2017-06-14 11:31:16 +03:00
|
|
|
emailBusy: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
onEmailAddressChanged: function(value) {
|
|
|
|
this.setState({
|
|
|
|
emailAddress: value,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onSubmit: function() {
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
|
|
|
|
|
|
|
const emailAddress = this.state.emailAddress;
|
|
|
|
if (!Email.looksValid(emailAddress)) {
|
2017-07-27 19:19:18 +03:00
|
|
|
Modal.createTrackedDialog('Invalid Email Address', '', ErrorDialog, {
|
2017-06-14 11:31:16 +03:00
|
|
|
title: _t("Invalid Email Address"),
|
|
|
|
description: _t("This doesn't appear to be a valid email address"),
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._addThreepid = new AddThreepid();
|
2019-09-19 17:50:18 +03:00
|
|
|
this._addThreepid.addEmailAddress(emailAddress).done(() => {
|
2017-07-27 19:19:18 +03:00
|
|
|
Modal.createTrackedDialog('Verification Pending', '', QuestionDialog, {
|
2017-06-14 11:31:16 +03:00
|
|
|
title: _t("Verification Pending"),
|
|
|
|
description: _t(
|
|
|
|
"Please check your email and click on the link it contains. Once this " +
|
|
|
|
"is done, click continue.",
|
|
|
|
),
|
|
|
|
button: _t('Continue'),
|
|
|
|
onFinished: this.onEmailDialogFinished,
|
|
|
|
});
|
|
|
|
}, (err) => {
|
|
|
|
this.setState({emailBusy: false});
|
|
|
|
console.error("Unable to add email address " + emailAddress + " " + err);
|
2017-08-10 15:49:11 +03:00
|
|
|
Modal.createTrackedDialog('Unable to add email address', '', ErrorDialog, {
|
2017-06-14 11:31:16 +03:00
|
|
|
title: _t("Unable to add email address"),
|
|
|
|
description: ((err && err.message) ? err.message : _t("Operation failed")),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.setState({emailBusy: true});
|
|
|
|
},
|
|
|
|
|
2017-06-14 16:58:39 +03:00
|
|
|
onCancelled: function() {
|
|
|
|
this.props.onFinished(false);
|
|
|
|
},
|
|
|
|
|
2017-06-14 11:31:16 +03:00
|
|
|
onEmailDialogFinished: function(ok) {
|
|
|
|
if (ok) {
|
|
|
|
this.verifyEmailAddress();
|
|
|
|
} else {
|
|
|
|
this.setState({emailBusy: false});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
verifyEmailAddress: function() {
|
|
|
|
this._addThreepid.checkEmailLinkClicked().done(() => {
|
|
|
|
this.props.onFinished(true);
|
|
|
|
}, (err) => {
|
|
|
|
this.setState({emailBusy: false});
|
|
|
|
if (err.errcode == 'M_THREEPID_AUTH_FAILED') {
|
|
|
|
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
|
|
|
const message = _t("Unable to verify email address.") + " " +
|
|
|
|
_t("Please check your email and click on the link it contains. Once this is done, click continue.");
|
2017-08-10 15:51:47 +03:00
|
|
|
Modal.createTrackedDialog('Verification Pending', '3pid Auth Failed', QuestionDialog, {
|
2017-06-14 11:31:16 +03:00
|
|
|
title: _t("Verification Pending"),
|
|
|
|
description: message,
|
|
|
|
button: _t('Continue'),
|
|
|
|
onFinished: this.onEmailDialogFinished,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
console.error("Unable to verify email address: " + err);
|
2017-08-10 15:49:11 +03:00
|
|
|
Modal.createTrackedDialog('Unable to verify email address', '', ErrorDialog, {
|
2017-06-14 11:31:16 +03:00
|
|
|
title: _t("Unable to verify email address."),
|
|
|
|
description: ((err && err.message) ? err.message : _t("Operation failed")),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
|
|
|
const Spinner = sdk.getComponent('elements.Spinner');
|
|
|
|
const EditableText = sdk.getComponent('elements.EditableText');
|
|
|
|
|
|
|
|
const emailInput = this.state.emailBusy ? <Spinner /> : <EditableText
|
2018-06-18 20:17:10 +03:00
|
|
|
initialValue={this.state.emailAddress}
|
2017-06-14 11:31:16 +03:00
|
|
|
className="mx_SetEmailDialog_email_input"
|
2017-12-20 12:13:37 +03:00
|
|
|
autoFocus="true"
|
2017-09-28 13:21:06 +03:00
|
|
|
placeholder={_t("Email address")}
|
2017-06-14 11:31:16 +03:00
|
|
|
placeholderClassName="mx_SetEmailDialog_email_input_placeholder"
|
2017-09-28 13:21:06 +03:00
|
|
|
blurToCancel={false}
|
|
|
|
onValueChanged={this.onEmailAddressChanged} />;
|
2017-06-14 11:31:16 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<BaseDialog className="mx_SetEmailDialog"
|
2017-06-14 16:58:39 +03:00
|
|
|
onFinished={this.onCancelled}
|
2017-06-14 11:31:16 +03:00
|
|
|
title={this.props.title}
|
2017-12-05 15:52:20 +03:00
|
|
|
contentId='mx_Dialog_content'
|
2017-06-14 11:31:16 +03:00
|
|
|
>
|
|
|
|
<div className="mx_Dialog_content">
|
2017-12-05 15:52:20 +03:00
|
|
|
<p id='mx_Dialog_content'>
|
2017-06-14 11:31:16 +03:00
|
|
|
{ _t('This will allow you to reset your password and receive notifications.') }
|
|
|
|
</p>
|
|
|
|
{ emailInput }
|
|
|
|
</div>
|
|
|
|
<div className="mx_Dialog_buttons">
|
|
|
|
<input className="mx_Dialog_primary"
|
|
|
|
type="submit"
|
|
|
|
value={_t("Continue")}
|
|
|
|
onClick={this.onSubmit}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
type="submit"
|
2017-06-19 15:17:12 +03:00
|
|
|
value={_t("Skip")}
|
2017-06-14 18:06:28 +03:00
|
|
|
onClick={this.onCancelled}
|
2017-06-14 11:31:16 +03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</BaseDialog>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|