2016-01-12 20:20:16 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2018-06-21 15:51:39 +03:00
|
|
|
Copyright 2017, 2018 New Vector Ltd
|
2016-01-12 20:20: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.
|
|
|
|
*/
|
|
|
|
|
2017-10-27 03:23:50 +03:00
|
|
|
import React from 'react';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-05-25 13:39:08 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2017-10-27 03:23:50 +03:00
|
|
|
import sdk from '../../../index';
|
|
|
|
import Modal from "../../../Modal";
|
|
|
|
import MatrixClientPeg from "../../../MatrixClientPeg";
|
2018-04-06 12:27:03 +03:00
|
|
|
import SdkConfig from "../../../SdkConfig";
|
2016-01-12 20:20:16 +03:00
|
|
|
|
2017-10-27 03:23:50 +03:00
|
|
|
import PasswordReset from "../../../PasswordReset";
|
2016-01-12 20:20:16 +03:00
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'ForgotPassword',
|
|
|
|
|
|
|
|
propTypes: {
|
2017-12-26 04:03:18 +03:00
|
|
|
defaultHsUrl: PropTypes.string,
|
|
|
|
defaultIsUrl: PropTypes.string,
|
|
|
|
customHsUrl: PropTypes.string,
|
|
|
|
customIsUrl: PropTypes.string,
|
|
|
|
onLoginClick: PropTypes.func,
|
|
|
|
onRegisterClick: PropTypes.func,
|
|
|
|
onComplete: PropTypes.func.isRequired,
|
2018-12-05 09:34:57 +03:00
|
|
|
|
|
|
|
// The default server name to use when the user hasn't specified
|
|
|
|
// one. This is used when displaying the defaultHsUrl in the UI.
|
|
|
|
defaultServerName: PropTypes.string,
|
|
|
|
|
|
|
|
// An error passed along from higher up explaining that something
|
|
|
|
// went wrong when finding the defaultHsUrl.
|
|
|
|
defaultServerDiscoveryError: PropTypes.string,
|
2016-01-12 20:20:16 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2016-04-07 14:59:30 +03:00
|
|
|
enteredHomeserverUrl: this.props.customHsUrl || this.props.defaultHsUrl,
|
|
|
|
enteredIdentityServerUrl: this.props.customIsUrl || this.props.defaultIsUrl,
|
2017-10-11 19:56:17 +03:00
|
|
|
progress: null,
|
2018-06-21 16:04:08 +03:00
|
|
|
password: null,
|
|
|
|
password2: null,
|
2018-12-05 09:34:57 +03:00
|
|
|
errorText: null,
|
2016-01-12 20:20:16 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
submitPasswordReset: function(hsUrl, identityUrl, email, password) {
|
|
|
|
this.setState({
|
2017-10-11 19:56:17 +03:00
|
|
|
progress: "sending_email",
|
2016-01-12 20:20:16 +03:00
|
|
|
});
|
|
|
|
this.reset = new PasswordReset(hsUrl, identityUrl);
|
|
|
|
this.reset.resetPassword(email, password).done(() => {
|
|
|
|
this.setState({
|
2017-10-11 19:56:17 +03:00
|
|
|
progress: "sent_email",
|
2016-01-12 20:20:16 +03:00
|
|
|
});
|
|
|
|
}, (err) => {
|
2017-05-23 17:16:31 +03:00
|
|
|
this.showErrorDialog(_t('Failed to send email') + ": " + err.message);
|
2016-01-12 20:20:16 +03:00
|
|
|
this.setState({
|
2017-10-11 19:56:17 +03:00
|
|
|
progress: null,
|
2016-01-12 20:20:16 +03:00
|
|
|
});
|
2017-01-20 17:22:27 +03:00
|
|
|
});
|
2016-01-12 20:20:16 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onVerify: function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
if (!this.reset) {
|
|
|
|
console.error("onVerify called before submitPasswordReset!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.reset.checkEmailLinkClicked().done((res) => {
|
|
|
|
this.setState({ progress: "complete" });
|
|
|
|
}, (err) => {
|
|
|
|
this.showErrorDialog(err.message);
|
2017-01-20 17:22:27 +03:00
|
|
|
});
|
2016-01-12 20:20:16 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onSubmitForm: function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
|
2018-12-05 09:34:57 +03:00
|
|
|
// Don't allow the user to register if there's a discovery error
|
|
|
|
// Without this, the user could end up registering on the wrong homeserver.
|
|
|
|
if (this.props.defaultServerDiscoveryError) {
|
|
|
|
this.setState({errorText: this.props.defaultServerDiscoveryError});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-12 20:20:16 +03:00
|
|
|
if (!this.state.email) {
|
2017-05-23 17:16:31 +03:00
|
|
|
this.showErrorDialog(_t('The email address linked to your account must be entered.'));
|
2017-10-11 19:56:17 +03:00
|
|
|
} else if (!this.state.password || !this.state.password2) {
|
2017-05-27 20:20:35 +03:00
|
|
|
this.showErrorDialog(_t('A new password must be entered.'));
|
2017-10-11 19:56:17 +03:00
|
|
|
} else if (this.state.password !== this.state.password2) {
|
2017-05-23 17:16:31 +03:00
|
|
|
this.showErrorDialog(_t('New passwords must match each other.'));
|
2017-10-11 19:56:17 +03:00
|
|
|
} else {
|
|
|
|
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
2017-07-27 19:19:18 +03:00
|
|
|
Modal.createTrackedDialog('Forgot Password Warning', '', QuestionDialog, {
|
2017-05-25 20:20:48 +03:00
|
|
|
title: _t('Warning!'),
|
2017-01-25 00:36:55 +03:00
|
|
|
description:
|
|
|
|
<div>
|
2017-05-23 17:16:31 +03:00
|
|
|
{ _t(
|
|
|
|
'Resetting password will currently reset any ' +
|
|
|
|
'end-to-end encryption keys on all devices, ' +
|
2017-07-27 19:19:18 +03:00
|
|
|
'making encrypted chat history unreadable, ' +
|
2017-05-23 17:16:31 +03:00
|
|
|
'unless you first export your room keys and re-import ' +
|
2017-10-11 19:56:17 +03:00
|
|
|
'them afterwards. In future this will be improved.',
|
2017-05-27 20:20:35 +03:00
|
|
|
) }
|
2017-01-25 00:36:55 +03:00
|
|
|
</div>,
|
2017-05-23 17:16:31 +03:00
|
|
|
button: _t('Continue'),
|
2017-04-08 01:34:11 +03:00
|
|
|
extraButtons: [
|
2018-06-21 16:04:08 +03:00
|
|
|
<button key="export_keys" className="mx_Dialog_primary"
|
2017-04-08 01:34:11 +03:00
|
|
|
onClick={this._onExportE2eKeysClicked}>
|
2017-05-23 17:16:31 +03:00
|
|
|
{ _t('Export E2E room keys') }
|
2017-10-11 19:56:17 +03:00
|
|
|
</button>,
|
2017-04-08 01:34:11 +03:00
|
|
|
],
|
2017-01-25 00:36:55 +03:00
|
|
|
onFinished: (confirmed) => {
|
|
|
|
if (confirmed) {
|
|
|
|
this.submitPasswordReset(
|
|
|
|
this.state.enteredHomeserverUrl, this.state.enteredIdentityServerUrl,
|
2017-10-11 19:56:17 +03:00
|
|
|
this.state.email, this.state.password,
|
2017-01-25 00:36:55 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2016-01-12 20:20:16 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-04-08 01:34:11 +03:00
|
|
|
_onExportE2eKeysClicked: function() {
|
2018-11-21 19:56:44 +03:00
|
|
|
Modal.createTrackedDialogAsync('Export E2E Keys', 'Forgot Password',
|
|
|
|
import('../../../async-components/views/dialogs/ExportE2eKeysDialog'),
|
|
|
|
{
|
|
|
|
matrixClient: MatrixClientPeg.get(),
|
|
|
|
},
|
|
|
|
);
|
2017-04-08 01:34:11 +03:00
|
|
|
},
|
|
|
|
|
2016-01-12 20:20:16 +03:00
|
|
|
onInputChanged: function(stateKey, ev) {
|
|
|
|
this.setState({
|
2017-10-11 19:56:17 +03:00
|
|
|
[stateKey]: ev.target.value,
|
2016-01-12 20:20:16 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-08-29 16:07:43 +03:00
|
|
|
onServerConfigChange: function(config) {
|
|
|
|
const newState = {};
|
|
|
|
if (config.hsUrl !== undefined) {
|
|
|
|
newState.enteredHomeserverUrl = config.hsUrl;
|
|
|
|
}
|
|
|
|
if (config.isUrl !== undefined) {
|
|
|
|
newState.enteredIdentityServerUrl = config.isUrl;
|
|
|
|
}
|
|
|
|
this.setState(newState);
|
2016-01-12 20:20:16 +03:00
|
|
|
},
|
|
|
|
|
Fix browser navigation not working between /home, /login, /register, etc
All of the anchors were pointed at `#` which, when clicked, would trigger a hash change in the browser. This change races the change made by the screen handling where the screen handling ends up losing. Because the hash is then tracked as empty rather than `#/login` (for example), the state machine considers future changes as no-ops and doesn't do anything with them.
By using `preventDefault` and `stopPropagation` on the anchor click events, we prevent the browser from automatically going to an empty hash, which then means the screen handling isn't racing the browser, and the hash change state machine doesn't no-op.
After applying that fix, going between pages worked great unless you were going from /login to /home. This is because the MatrixChat state machine was now out of sync (a `view` of `LOGIN` but a `page` of `HomePage` - an invalid state). All we have to do here is ensure the right view is used when navigating to the homepage.
Fixes https://github.com/vector-im/riot-web/issues/4061
Note: the concerns in 4061 about logging out upon entering the view appear to have been solved. Navigating to the login page doesn't obliterate your session, at least in my testing.
2018-12-21 03:26:13 +03:00
|
|
|
onLoginClick: function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
this.props.onLoginClick();
|
|
|
|
},
|
|
|
|
|
|
|
|
onRegisterClick: function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
this.props.onRegisterClick();
|
|
|
|
},
|
|
|
|
|
2016-01-12 20:20:16 +03:00
|
|
|
showErrorDialog: function(body, title) {
|
2017-10-11 19:56:17 +03:00
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2017-08-10 17:21:01 +03:00
|
|
|
Modal.createTrackedDialog('Forgot Password Error', '', ErrorDialog, {
|
2016-01-12 20:20:16 +03:00
|
|
|
title: title,
|
2017-05-23 17:16:31 +03:00
|
|
|
description: body,
|
2016-01-12 20:20:16 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2019-01-22 03:33:17 +03:00
|
|
|
const AuthPage = sdk.getComponent("auth.AuthPage");
|
|
|
|
const AuthHeader = sdk.getComponent("auth.AuthHeader");
|
2019-01-23 04:28:23 +03:00
|
|
|
const AuthBody = sdk.getComponent("auth.AuthBody");
|
2019-01-22 01:11:10 +03:00
|
|
|
const ServerConfig = sdk.getComponent("auth.ServerConfig");
|
2017-10-11 19:56:17 +03:00
|
|
|
const Spinner = sdk.getComponent("elements.Spinner");
|
2016-01-12 20:20:16 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
let resetPasswordJsx;
|
2016-01-12 20:20:16 +03:00
|
|
|
|
|
|
|
if (this.state.progress === "sending_email") {
|
2017-01-20 17:22:27 +03:00
|
|
|
resetPasswordJsx = <Spinner />;
|
2017-10-11 19:56:17 +03:00
|
|
|
} else if (this.state.progress === "sent_email") {
|
2016-01-12 20:20:16 +03:00
|
|
|
resetPasswordJsx = (
|
2017-10-27 03:35:21 +03:00
|
|
|
<div className="mx_Login_prompt">
|
2018-06-21 16:04:08 +03:00
|
|
|
{ _t("An email has been sent to %(emailAddress)s. Once you've followed the link it contains, " +
|
|
|
|
"click below.", { emailAddress: this.state.email }) }
|
2016-01-12 20:20:16 +03:00
|
|
|
<br />
|
|
|
|
<input className="mx_Login_submit" type="button" onClick={this.onVerify}
|
2017-10-11 19:56:17 +03:00
|
|
|
value={_t('I have verified my email address')} />
|
2016-01-12 20:20:16 +03:00
|
|
|
</div>
|
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
} else if (this.state.progress === "complete") {
|
2016-01-12 20:20:16 +03:00
|
|
|
resetPasswordJsx = (
|
2017-10-27 03:35:21 +03:00
|
|
|
<div className="mx_Login_prompt">
|
2017-05-23 17:16:31 +03:00
|
|
|
<p>{ _t('Your password has been reset') }.</p>
|
2018-06-21 16:04:08 +03:00
|
|
|
<p>{ _t('You have been logged out of all devices and will no longer receive push notifications. ' +
|
|
|
|
'To re-enable notifications, sign in again on each device') }.</p>
|
2016-01-12 20:20:16 +03:00
|
|
|
<input className="mx_Login_submit" type="button" onClick={this.props.onComplete}
|
2017-10-11 19:56:17 +03:00
|
|
|
value={_t('Return to login screen')} />
|
2016-01-12 20:20:16 +03:00
|
|
|
</div>
|
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
} else {
|
2017-10-27 03:23:50 +03:00
|
|
|
let serverConfigSection;
|
2018-06-21 16:04:08 +03:00
|
|
|
if (!SdkConfig.get()['disable_custom_urls']) {
|
2017-10-27 03:23:50 +03:00
|
|
|
serverConfigSection = (
|
|
|
|
<ServerConfig ref="serverConfig"
|
|
|
|
withToggleButton={true}
|
|
|
|
defaultHsUrl={this.props.defaultHsUrl}
|
|
|
|
defaultIsUrl={this.props.defaultIsUrl}
|
|
|
|
customHsUrl={this.props.customHsUrl}
|
|
|
|
customIsUrl={this.props.customIsUrl}
|
|
|
|
onServerConfigChange={this.onServerConfigChange}
|
|
|
|
delayTimeMs={0} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-12-05 09:34:57 +03:00
|
|
|
let errorText = null;
|
|
|
|
const err = this.state.errorText || this.props.defaultServerDiscoveryError;
|
|
|
|
if (err) {
|
|
|
|
errorText = <div className="mx_Login_error">{ err }</div>;
|
|
|
|
}
|
|
|
|
|
2016-01-12 20:20:16 +03:00
|
|
|
resetPasswordJsx = (
|
|
|
|
<div>
|
2016-03-06 22:33:36 +03:00
|
|
|
<div className="mx_Login_prompt">
|
2017-05-23 17:16:31 +03:00
|
|
|
{ _t('To reset your password, enter the email address linked to your account') }:
|
2016-03-06 22:33:36 +03:00
|
|
|
</div>
|
2016-01-12 20:20:16 +03:00
|
|
|
<div>
|
|
|
|
<form onSubmit={this.onSubmitForm}>
|
|
|
|
<input className="mx_Login_field" ref="user" type="text"
|
2016-10-14 17:34:44 +03:00
|
|
|
name="reset_email" // define a name so browser's password autofill gets less confused
|
2016-01-12 20:20:16 +03:00
|
|
|
value={this.state.email}
|
|
|
|
onChange={this.onInputChanged.bind(this, "email")}
|
2017-10-11 19:56:17 +03:00
|
|
|
placeholder={_t('Email address')} autoFocus />
|
2016-01-12 20:20:16 +03:00
|
|
|
<br />
|
|
|
|
<input className="mx_Login_field" ref="pass" type="password"
|
2016-10-14 17:34:44 +03:00
|
|
|
name="reset_password"
|
2016-01-12 20:20:16 +03:00
|
|
|
value={this.state.password}
|
|
|
|
onChange={this.onInputChanged.bind(this, "password")}
|
2017-10-11 19:56:17 +03:00
|
|
|
placeholder={_t('New password')} />
|
2016-01-12 20:20:16 +03:00
|
|
|
<br />
|
|
|
|
<input className="mx_Login_field" ref="pass" type="password"
|
2016-10-14 17:34:44 +03:00
|
|
|
name="reset_password_confirm"
|
2016-01-12 20:20:16 +03:00
|
|
|
value={this.state.password2}
|
|
|
|
onChange={this.onInputChanged.bind(this, "password2")}
|
2017-10-11 19:56:17 +03:00
|
|
|
placeholder={_t('Confirm your new password')} />
|
2016-01-12 20:20:16 +03:00
|
|
|
<br />
|
2017-10-11 19:56:17 +03:00
|
|
|
<input className="mx_Login_submit" type="submit" value={_t('Send Reset Email')} />
|
2016-01-12 20:20:16 +03:00
|
|
|
</form>
|
2017-10-27 03:23:50 +03:00
|
|
|
{ serverConfigSection }
|
2018-12-05 09:34:57 +03:00
|
|
|
{ errorText }
|
Fix browser navigation not working between /home, /login, /register, etc
All of the anchors were pointed at `#` which, when clicked, would trigger a hash change in the browser. This change races the change made by the screen handling where the screen handling ends up losing. Because the hash is then tracked as empty rather than `#/login` (for example), the state machine considers future changes as no-ops and doesn't do anything with them.
By using `preventDefault` and `stopPropagation` on the anchor click events, we prevent the browser from automatically going to an empty hash, which then means the screen handling isn't racing the browser, and the hash change state machine doesn't no-op.
After applying that fix, going between pages worked great unless you were going from /login to /home. This is because the MatrixChat state machine was now out of sync (a `view` of `LOGIN` but a `page` of `HomePage` - an invalid state). All we have to do here is ensure the right view is used when navigating to the homepage.
Fixes https://github.com/vector-im/riot-web/issues/4061
Note: the concerns in 4061 about logging out upon entering the view appear to have been solved. Navigating to the login page doesn't obliterate your session, at least in my testing.
2018-12-21 03:26:13 +03:00
|
|
|
<a className="mx_Login_create" onClick={this.onLoginClick} href="#">
|
2017-10-11 19:56:17 +03:00
|
|
|
{ _t('Return to login screen') }
|
2016-03-06 22:33:36 +03:00
|
|
|
</a>
|
Fix browser navigation not working between /home, /login, /register, etc
All of the anchors were pointed at `#` which, when clicked, would trigger a hash change in the browser. This change races the change made by the screen handling where the screen handling ends up losing. Because the hash is then tracked as empty rather than `#/login` (for example), the state machine considers future changes as no-ops and doesn't do anything with them.
By using `preventDefault` and `stopPropagation` on the anchor click events, we prevent the browser from automatically going to an empty hash, which then means the screen handling isn't racing the browser, and the hash change state machine doesn't no-op.
After applying that fix, going between pages worked great unless you were going from /login to /home. This is because the MatrixChat state machine was now out of sync (a `view` of `LOGIN` but a `page` of `HomePage` - an invalid state). All we have to do here is ensure the right view is used when navigating to the homepage.
Fixes https://github.com/vector-im/riot-web/issues/4061
Note: the concerns in 4061 about logging out upon entering the view appear to have been solved. Navigating to the login page doesn't obliterate your session, at least in my testing.
2018-12-21 03:26:13 +03:00
|
|
|
<a className="mx_Login_create" onClick={this.onRegisterClick} href="#">
|
2017-05-23 17:16:31 +03:00
|
|
|
{ _t('Create an account') }
|
2016-03-06 22:33:36 +03:00
|
|
|
</a>
|
2016-01-12 20:20:16 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2019-01-22 03:33:17 +03:00
|
|
|
<AuthPage>
|
2019-01-22 03:49:28 +03:00
|
|
|
<AuthHeader />
|
2019-01-23 04:28:23 +03:00
|
|
|
<AuthBody>
|
|
|
|
{resetPasswordJsx}
|
|
|
|
</AuthBody>
|
2019-01-22 03:33:17 +03:00
|
|
|
</AuthPage>
|
2016-01-12 20:20:16 +03:00
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
},
|
2016-01-12 20:20:16 +03:00
|
|
|
});
|