2015-11-30 21:11:04 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-02-24 14:41:23 +03:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2018-06-21 15:51:39 +03:00
|
|
|
Copyright 2018 New Vector Ltd
|
2015-11-30 21:11:04 +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-02-24 14:41:23 +03:00
|
|
|
import Matrix from 'matrix-js-sdk';
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2017-07-12 15:58:14 +03:00
|
|
|
import Promise from 'bluebird';
|
2017-02-28 18:05:49 +03:00
|
|
|
import React from 'react';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2017-02-28 18:05:49 +03:00
|
|
|
import sdk from '../../../index';
|
|
|
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
|
|
|
import RegistrationForm from '../../views/login/RegistrationForm';
|
|
|
|
import RtsClient from '../../../RtsClient';
|
2018-08-16 15:31:17 +03:00
|
|
|
import { _t, _td } from '../../../languageHandler';
|
2017-11-12 02:46:43 +03:00
|
|
|
import SdkConfig from '../../../SdkConfig';
|
2017-11-13 23:14:00 +03:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2018-08-16 15:31:17 +03:00
|
|
|
import { messageForResourceLimitError } from '../../../utils/ErrorUtils';
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2017-02-28 18:05:49 +03:00
|
|
|
const MIN_PASSWORD_LENGTH = 6;
|
2015-11-30 21:11:04 +03:00
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'Registration',
|
|
|
|
|
|
|
|
propTypes: {
|
2017-12-26 04:03:18 +03:00
|
|
|
onLoggedIn: PropTypes.func.isRequired,
|
|
|
|
clientSecret: PropTypes.string,
|
|
|
|
sessionId: PropTypes.string,
|
|
|
|
makeRegistrationUrl: PropTypes.func.isRequired,
|
|
|
|
idSid: PropTypes.string,
|
|
|
|
customHsUrl: PropTypes.string,
|
|
|
|
customIsUrl: PropTypes.string,
|
|
|
|
defaultHsUrl: PropTypes.string,
|
|
|
|
defaultIsUrl: PropTypes.string,
|
|
|
|
brand: PropTypes.string,
|
|
|
|
email: PropTypes.string,
|
|
|
|
referrer: PropTypes.string,
|
|
|
|
teamServerConfig: PropTypes.shape({
|
2017-01-18 14:48:28 +03:00
|
|
|
// Email address to request new teams
|
2017-12-26 04:03:18 +03:00
|
|
|
supportEmail: PropTypes.string.isRequired,
|
2017-01-30 18:50:31 +03:00
|
|
|
// URL of the riot-team-server to get team configurations and track referrals
|
2017-12-26 04:03:18 +03:00
|
|
|
teamServerURL: PropTypes.string.isRequired,
|
2017-01-18 14:48:28 +03:00
|
|
|
}),
|
2017-12-26 04:03:18 +03:00
|
|
|
teamSelected: PropTypes.object,
|
2016-08-11 18:15:42 +03:00
|
|
|
|
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,
|
|
|
|
|
2017-12-26 04:03:18 +03:00
|
|
|
defaultDeviceDisplayName: PropTypes.string,
|
2016-08-11 18:15:42 +03:00
|
|
|
|
2015-11-30 21:11:04 +03:00
|
|
|
// registration shouldn't know or care how login is done.
|
2017-12-26 04:03:18 +03:00
|
|
|
onLoginClick: PropTypes.func.isRequired,
|
|
|
|
onCancelClick: PropTypes.func,
|
2018-02-07 18:51:03 +03:00
|
|
|
onServerConfigChange: PropTypes.func.isRequired,
|
2018-06-21 16:04:08 +03:00
|
|
|
|
|
|
|
rtsClient: PropTypes.shape({
|
|
|
|
getTeamsConfig: PropTypes.func.isRequired,
|
|
|
|
trackReferral: PropTypes.func.isRequired,
|
|
|
|
getTeam: PropTypes.func.isRequired,
|
|
|
|
}),
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
busy: false,
|
2017-01-30 19:23:52 +03:00
|
|
|
teamServerBusy: false,
|
2015-11-30 21:11:04 +03:00
|
|
|
errorText: null,
|
2016-07-07 13:26:35 +03:00
|
|
|
// We remember the values entered by the user because
|
|
|
|
// the registration form will be unmounted during the
|
|
|
|
// course of registration, but if there's an error we
|
|
|
|
// want to bring back the registration form with the
|
2016-07-07 15:03:27 +03:00
|
|
|
// values the user entered still in it. We can keep
|
2016-07-07 13:26:35 +03:00
|
|
|
// them in this component's state since this component
|
|
|
|
// persist for the duration of the registration process.
|
2016-07-06 17:22:06 +03:00
|
|
|
formVals: {
|
|
|
|
email: this.props.email,
|
|
|
|
},
|
2017-02-24 14:41:23 +03:00
|
|
|
// true if we're waiting for the user to complete
|
|
|
|
// user-interactive auth
|
|
|
|
// If we've been given a session ID, we're resuming
|
|
|
|
// straight back into UI auth
|
|
|
|
doingUIAuth: Boolean(this.props.sessionId),
|
2017-02-27 20:24:28 +03:00
|
|
|
hsUrl: this.props.customHsUrl,
|
|
|
|
isUrl: this.props.customIsUrl,
|
2018-09-04 20:26:09 +03:00
|
|
|
flows: null,
|
2015-11-30 21:11:04 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
2017-01-27 19:31:36 +03:00
|
|
|
this._unmounted = false;
|
2017-02-24 14:41:23 +03:00
|
|
|
|
|
|
|
this._replaceClient();
|
2017-01-30 18:50:31 +03:00
|
|
|
|
2017-01-30 19:13:57 +03:00
|
|
|
if (
|
|
|
|
this.props.teamServerConfig &&
|
|
|
|
this.props.teamServerConfig.teamServerURL &&
|
|
|
|
!this._rtsClient
|
|
|
|
) {
|
2017-05-17 11:46:17 +03:00
|
|
|
this._rtsClient = this.props.rtsClient || new RtsClient(this.props.teamServerConfig.teamServerURL);
|
2017-01-30 18:50:31 +03:00
|
|
|
|
2017-01-30 19:23:52 +03:00
|
|
|
this.setState({
|
|
|
|
teamServerBusy: true,
|
|
|
|
});
|
2017-01-30 18:50:31 +03:00
|
|
|
// GET team configurations including domains, names and icons
|
2017-02-01 13:39:52 +03:00
|
|
|
this._rtsClient.getTeamsConfig().then((data) => {
|
2017-01-30 18:50:31 +03:00
|
|
|
const teamsConfig = {
|
2017-02-01 13:39:52 +03:00
|
|
|
teams: data,
|
2017-01-30 18:50:31 +03:00
|
|
|
supportEmail: this.props.teamServerConfig.supportEmail,
|
|
|
|
};
|
|
|
|
console.log('Setting teams config to ', teamsConfig);
|
|
|
|
this.setState({
|
|
|
|
teamsConfig: teamsConfig,
|
2017-02-01 13:39:52 +03:00
|
|
|
teamServerBusy: false,
|
2017-01-30 18:50:31 +03:00
|
|
|
});
|
|
|
|
}, (err) => {
|
|
|
|
console.error('Error retrieving config for teams', err);
|
2017-01-30 19:23:52 +03:00
|
|
|
this.setState({
|
|
|
|
teamServerBusy: false,
|
|
|
|
});
|
2017-02-01 13:39:52 +03:00
|
|
|
});
|
2017-01-30 18:50:31 +03:00
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
|
|
|
|
2017-04-25 21:21:09 +03:00
|
|
|
onServerConfigChange: function(config) {
|
2017-10-11 19:56:17 +03:00
|
|
|
const newState = {};
|
2017-04-25 21:21:09 +03:00
|
|
|
if (config.hsUrl !== undefined) {
|
|
|
|
newState.hsUrl = config.hsUrl;
|
|
|
|
}
|
|
|
|
if (config.isUrl !== undefined) {
|
|
|
|
newState.isUrl = config.isUrl;
|
|
|
|
}
|
2018-02-07 18:51:03 +03:00
|
|
|
this.props.onServerConfigChange(config);
|
2018-06-21 16:04:08 +03:00
|
|
|
this.setState(newState, () => {
|
2017-04-25 21:21:09 +03:00
|
|
|
this._replaceClient();
|
2017-02-27 20:24:28 +03:00
|
|
|
});
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
|
|
|
|
2018-09-04 20:26:09 +03:00
|
|
|
_replaceClient: async function() {
|
2017-02-24 14:41:23 +03:00
|
|
|
this._matrixClient = Matrix.createClient({
|
2017-02-27 20:24:28 +03:00
|
|
|
baseUrl: this.state.hsUrl,
|
|
|
|
idBaseUrl: this.state.isUrl,
|
2016-01-27 18:44:12 +03:00
|
|
|
});
|
2018-09-04 20:26:09 +03:00
|
|
|
try {
|
2018-09-04 20:51:24 +03:00
|
|
|
await this._makeRegisterRequest({});
|
2018-09-04 20:26:09 +03:00
|
|
|
// This should never succeed since we specified an empty
|
|
|
|
// auth object.
|
|
|
|
console.log("Expecting 401 from register request but got success!");
|
|
|
|
} catch (e) {
|
|
|
|
if (e.httpStatus === 401) {
|
|
|
|
this.setState({
|
|
|
|
flows: e.data.flows,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
errorText: _t("Unable to query for supported registration methods"),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onFormSubmit: function(formVals) {
|
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;
|
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
this.setState({
|
|
|
|
errorText: "",
|
2016-07-06 17:22:06 +03:00
|
|
|
busy: true,
|
|
|
|
formVals: formVals,
|
2017-02-24 14:41:23 +03:00
|
|
|
doingUIAuth: true,
|
2015-11-30 21:11:04 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-03-06 20:31:21 +03:00
|
|
|
_onUIAuthFinished: function(success, response, extra) {
|
2017-02-27 20:24:28 +03:00
|
|
|
if (!success) {
|
2017-03-15 19:44:56 +03:00
|
|
|
let msg = response.message || response.toString();
|
|
|
|
// can we give a better error message?
|
2018-08-15 19:03:54 +03:00
|
|
|
if (response.errcode == 'M_RESOURCE_LIMIT_EXCEEDED') {
|
2018-08-16 15:31:17 +03:00
|
|
|
const errorTop = messageForResourceLimitError(
|
|
|
|
response.data.limit_type,
|
|
|
|
response.data.admin_contact, {
|
|
|
|
'monthly_active_user': _td(
|
|
|
|
"This homeserver has hit its Monthly Active User limit.",
|
|
|
|
),
|
|
|
|
'': _td(
|
|
|
|
"This homeserver has exceeded one of its resource limits.",
|
|
|
|
),
|
|
|
|
});
|
|
|
|
const errorDetail = messageForResourceLimitError(
|
|
|
|
response.data.limit_type,
|
|
|
|
response.data.admin_contact, {
|
|
|
|
'': _td(
|
2018-08-15 19:03:54 +03:00
|
|
|
"Please <a>contact your service administrator</a> to continue using this service.",
|
2018-08-16 15:31:17 +03:00
|
|
|
),
|
|
|
|
});
|
|
|
|
msg = <div>
|
|
|
|
<p>{errorTop}</p>
|
|
|
|
<p>{errorDetail}</p>
|
2018-08-02 18:09:57 +03:00
|
|
|
</div>;
|
|
|
|
} else if (response.required_stages && response.required_stages.indexOf('m.login.msisdn') > -1) {
|
2018-06-21 16:04:08 +03:00
|
|
|
let msisdnAvailable = false;
|
2017-03-15 19:44:56 +03:00
|
|
|
for (const flow of response.available_flows) {
|
2018-06-21 16:04:08 +03:00
|
|
|
msisdnAvailable |= flow.stages.indexOf('m.login.msisdn') > -1;
|
2017-03-15 19:44:56 +03:00
|
|
|
}
|
2018-06-21 16:04:08 +03:00
|
|
|
if (!msisdnAvailable) {
|
2017-05-23 17:16:31 +03:00
|
|
|
msg = _t('This server does not support authentication with a phone number.');
|
2017-03-15 19:44:56 +03:00
|
|
|
}
|
|
|
|
}
|
2017-02-27 20:24:28 +03:00
|
|
|
this.setState({
|
|
|
|
busy: false,
|
|
|
|
doingUIAuth: false,
|
2017-03-15 19:44:56 +03:00
|
|
|
errorText: msg,
|
2017-02-27 20:24:28 +03:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-24 14:41:23 +03:00
|
|
|
this.setState({
|
|
|
|
// we're still busy until we get unmounted: don't show the registration form again
|
|
|
|
busy: true,
|
|
|
|
doingUIAuth: false,
|
|
|
|
});
|
2016-06-02 15:14:52 +03:00
|
|
|
|
2017-02-24 14:41:23 +03:00
|
|
|
// Done regardless of `teamSelected`. People registering with non-team emails
|
|
|
|
// will just nop. The point of this being we might not have the email address
|
|
|
|
// that the user registered with at this stage (depending on whether this
|
|
|
|
// is the client they initiated registration).
|
2017-07-12 16:02:00 +03:00
|
|
|
let trackPromise = Promise.resolve(null);
|
2017-03-06 20:31:21 +03:00
|
|
|
if (this._rtsClient && extra.emailSid) {
|
2017-03-01 13:45:17 +03:00
|
|
|
// Track referral if this.props.referrer set, get team_token in order to
|
2017-02-24 14:41:23 +03:00
|
|
|
// retrieve team config and see welcome page etc.
|
2017-03-02 18:08:15 +03:00
|
|
|
trackPromise = this._rtsClient.trackReferral(
|
2017-03-01 13:45:17 +03:00
|
|
|
this.props.referrer || '', // Default to empty string = not referred
|
2017-03-06 20:31:21 +03:00
|
|
|
extra.emailSid,
|
|
|
|
extra.clientSecret,
|
2017-02-24 14:41:23 +03:00
|
|
|
).then((data) => {
|
|
|
|
const teamToken = data.team_token;
|
|
|
|
// Store for use /w welcome pages
|
|
|
|
window.localStorage.setItem('mx_team_token', teamToken);
|
|
|
|
|
2017-03-01 13:45:17 +03:00
|
|
|
this._rtsClient.getTeam(teamToken).then((team) => {
|
2017-02-24 14:41:23 +03:00
|
|
|
console.log(
|
2017-10-11 19:56:17 +03:00
|
|
|
`User successfully registered with team ${team.name}`,
|
2017-02-24 14:41:23 +03:00
|
|
|
);
|
|
|
|
if (!team.rooms) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Auto-join rooms
|
|
|
|
team.rooms.forEach((room) => {
|
|
|
|
if (room.auto_join && room.room_id) {
|
|
|
|
console.log(`Auto-joining ${room.room_id}`);
|
|
|
|
MatrixClientPeg.get().joinRoom(room.room_id);
|
2017-01-19 13:05:08 +03:00
|
|
|
}
|
2017-01-31 14:13:05 +03:00
|
|
|
});
|
|
|
|
}, (err) => {
|
2017-02-24 14:41:23 +03:00
|
|
|
console.error('Error getting team config', err);
|
2017-01-31 14:13:05 +03:00
|
|
|
});
|
2017-03-03 13:28:10 +03:00
|
|
|
|
|
|
|
return teamToken;
|
2017-02-24 14:41:23 +03:00
|
|
|
}, (err) => {
|
|
|
|
console.error('Error tracking referral', err);
|
|
|
|
});
|
|
|
|
}
|
2016-06-02 15:14:52 +03:00
|
|
|
|
2017-03-01 13:45:17 +03:00
|
|
|
trackPromise.then((teamToken) => {
|
2017-06-19 12:22:18 +03:00
|
|
|
return this.props.onLoggedIn({
|
2017-03-01 13:45:17 +03:00
|
|
|
userId: response.user_id,
|
|
|
|
deviceId: response.device_id,
|
2017-03-06 20:31:21 +03:00
|
|
|
homeserverUrl: this._matrixClient.getHomeserverUrl(),
|
|
|
|
identityServerUrl: this._matrixClient.getIdentityServerUrl(),
|
2017-10-11 19:56:17 +03:00
|
|
|
accessToken: response.access_token,
|
2017-03-01 13:45:17 +03:00
|
|
|
}, teamToken);
|
2017-06-19 12:22:18 +03:00
|
|
|
}).then((cli) => {
|
|
|
|
return this._setupPushers(cli);
|
2017-03-06 20:31:21 +03:00
|
|
|
});
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
|
|
|
|
2017-06-19 12:22:18 +03:00
|
|
|
_setupPushers: function(matrixClient) {
|
2017-02-28 18:18:00 +03:00
|
|
|
if (!this.props.brand) {
|
2017-07-12 16:02:00 +03:00
|
|
|
return Promise.resolve();
|
2017-02-24 14:41:23 +03:00
|
|
|
}
|
2017-06-19 12:22:18 +03:00
|
|
|
return matrixClient.getPushers().then((resp)=>{
|
2017-03-01 13:45:17 +03:00
|
|
|
const pushers = resp.pushers;
|
|
|
|
for (let i = 0; i < pushers.length; ++i) {
|
2018-06-21 16:04:08 +03:00
|
|
|
if (pushers[i].kind === 'email') {
|
2017-03-01 13:45:17 +03:00
|
|
|
const emailPusher = pushers[i];
|
2017-02-28 18:18:00 +03:00
|
|
|
emailPusher.data = { brand: this.props.brand };
|
2017-06-19 12:22:18 +03:00
|
|
|
matrixClient.setPusher(emailPusher).done(() => {
|
2017-02-28 18:18:00 +03:00
|
|
|
console.log("Set email branding to " + this.props.brand);
|
2017-02-28 18:05:49 +03:00
|
|
|
}, (error) => {
|
|
|
|
console.error("Couldn't set email branding: " + error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, (error) => {
|
|
|
|
console.error("Couldn't get pushers: " + error);
|
|
|
|
});
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onFormValidationFailed: function(errCode) {
|
2017-10-11 19:56:17 +03:00
|
|
|
let errMsg;
|
2015-11-30 21:11:04 +03:00
|
|
|
switch (errCode) {
|
|
|
|
case "RegistrationForm.ERR_PASSWORD_MISSING":
|
2017-05-23 17:16:31 +03:00
|
|
|
errMsg = _t('Missing password.');
|
2015-11-30 21:11:04 +03:00
|
|
|
break;
|
|
|
|
case "RegistrationForm.ERR_PASSWORD_MISMATCH":
|
2017-05-23 17:16:31 +03:00
|
|
|
errMsg = _t('Passwords don\'t match.');
|
2015-11-30 21:11:04 +03:00
|
|
|
break;
|
|
|
|
case "RegistrationForm.ERR_PASSWORD_LENGTH":
|
2018-06-21 16:04:08 +03:00
|
|
|
errMsg = _t('Password too short (min %(MIN_PASSWORD_LENGTH)s).', {MIN_PASSWORD_LENGTH});
|
2015-11-30 21:11:04 +03:00
|
|
|
break;
|
2016-01-15 16:31:41 +03:00
|
|
|
case "RegistrationForm.ERR_EMAIL_INVALID":
|
2017-05-23 17:16:31 +03:00
|
|
|
errMsg = _t('This doesn\'t look like a valid email address.');
|
2016-01-15 16:31:41 +03:00
|
|
|
break;
|
2017-03-14 14:50:13 +03:00
|
|
|
case "RegistrationForm.ERR_PHONE_NUMBER_INVALID":
|
2017-05-23 17:16:31 +03:00
|
|
|
errMsg = _t('This doesn\'t look like a valid phone number.');
|
2017-03-14 14:50:13 +03:00
|
|
|
break;
|
2018-09-27 20:53:45 +03:00
|
|
|
case "RegistrationForm.ERR_MISSING_EMAIL":
|
|
|
|
errMsg = _t('An email address is required to register on this homeserver.');
|
|
|
|
break;
|
|
|
|
case "RegistrationForm.ERR_MISSING_PHONE_NUMBER":
|
|
|
|
errMsg = _t('A phone number is required to register on this homeserver.');
|
|
|
|
break;
|
2016-01-15 16:31:41 +03:00
|
|
|
case "RegistrationForm.ERR_USERNAME_INVALID":
|
2018-12-14 02:05:34 +03:00
|
|
|
errMsg = _t("Only use lower case letters, numbers and '=_-./'");
|
2016-01-15 16:31:41 +03:00
|
|
|
break;
|
|
|
|
case "RegistrationForm.ERR_USERNAME_BLANK":
|
2017-05-23 17:16:31 +03:00
|
|
|
errMsg = _t('You need to enter a user name.');
|
2016-01-15 16:31:41 +03:00
|
|
|
break;
|
2015-11-30 21:11:04 +03:00
|
|
|
default:
|
|
|
|
console.error("Unknown error code: %s", errCode);
|
2017-05-23 17:16:31 +03:00
|
|
|
errMsg = _t('An unknown error occurred.');
|
2015-11-30 21:11:04 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.setState({
|
2017-10-11 19:56:17 +03:00
|
|
|
errorText: errMsg,
|
2015-11-30 21:11:04 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-01-31 14:13:05 +03:00
|
|
|
onTeamSelected: function(teamSelected) {
|
2017-01-27 19:31:36 +03:00
|
|
|
if (!this._unmounted) {
|
2017-01-31 14:13:05 +03:00
|
|
|
this.setState({ teamSelected });
|
2017-01-27 19:31:36 +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();
|
|
|
|
},
|
|
|
|
|
2017-02-24 14:41:23 +03:00
|
|
|
_makeRegisterRequest: function(auth) {
|
2017-03-14 14:50:13 +03:00
|
|
|
// Only send the bind params if we're sending username / pw params
|
|
|
|
// (Since we need to send no params at all to use the ones saved in the
|
|
|
|
// session).
|
|
|
|
const bindThreepids = this.state.formVals.password ? {
|
|
|
|
email: true,
|
|
|
|
msisdn: true,
|
|
|
|
} : {};
|
|
|
|
|
2017-02-24 14:41:23 +03:00
|
|
|
return this._matrixClient.register(
|
2017-11-11 18:59:43 +03:00
|
|
|
this.state.formVals.username,
|
2017-02-24 14:41:23 +03:00
|
|
|
this.state.formVals.password,
|
|
|
|
undefined, // session id: included in the auth dict already
|
|
|
|
auth,
|
2017-03-14 14:50:13 +03:00
|
|
|
bindThreepids,
|
2017-06-08 22:57:05 +03:00
|
|
|
null,
|
2015-11-30 21:11:04 +03:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2017-03-06 20:31:21 +03:00
|
|
|
_getUIAuthInputs: function() {
|
2017-02-24 14:41:23 +03:00
|
|
|
return {
|
|
|
|
emailAddress: this.state.formVals.email,
|
|
|
|
phoneCountry: this.state.formVals.phoneCountry,
|
|
|
|
phoneNumber: this.state.formVals.phoneNumber,
|
2017-10-11 19:56:17 +03:00
|
|
|
};
|
2017-02-24 14:41:23 +03:00
|
|
|
},
|
|
|
|
|
2015-11-30 21:11:04 +03:00
|
|
|
render: function() {
|
2017-02-24 14:41:23 +03:00
|
|
|
const LoginHeader = sdk.getComponent('login.LoginHeader');
|
|
|
|
const LoginFooter = sdk.getComponent('login.LoginFooter');
|
2017-10-25 01:37:26 +03:00
|
|
|
const LoginPage = sdk.getComponent('login.LoginPage');
|
2017-02-24 14:41:23 +03:00
|
|
|
const InteractiveAuth = sdk.getComponent('structures.InteractiveAuth');
|
|
|
|
const Spinner = sdk.getComponent("elements.Spinner");
|
2017-02-27 20:24:28 +03:00
|
|
|
const ServerConfig = sdk.getComponent('views.login.ServerConfig');
|
2017-02-24 14:41:23 +03:00
|
|
|
|
2017-11-13 23:14:00 +03:00
|
|
|
const theme = SettingsStore.getValue("theme");
|
2017-10-25 04:04:02 +03:00
|
|
|
|
2017-02-24 14:41:23 +03:00
|
|
|
let registerBody;
|
|
|
|
if (this.state.doingUIAuth) {
|
|
|
|
registerBody = (
|
|
|
|
<InteractiveAuth
|
|
|
|
matrixClient={this._matrixClient}
|
|
|
|
makeRequest={this._makeRegisterRequest}
|
2017-03-03 15:08:26 +03:00
|
|
|
onAuthFinished={this._onUIAuthFinished}
|
2017-02-24 14:41:23 +03:00
|
|
|
inputs={this._getUIAuthInputs()}
|
|
|
|
makeRegistrationUrl={this.props.makeRegistrationUrl}
|
|
|
|
sessionId={this.props.sessionId}
|
|
|
|
clientSecret={this.props.clientSecret}
|
|
|
|
emailSid={this.props.idSid}
|
2017-02-24 20:24:10 +03:00
|
|
|
poll={true}
|
2017-02-24 14:41:23 +03:00
|
|
|
/>
|
|
|
|
);
|
2018-09-04 20:26:09 +03:00
|
|
|
} else if (this.state.busy || this.state.teamServerBusy || !this.state.flows) {
|
2017-02-24 14:41:23 +03:00
|
|
|
registerBody = <Spinner />;
|
|
|
|
} else {
|
2017-10-25 04:04:02 +03:00
|
|
|
let serverConfigSection;
|
2018-06-21 16:04:08 +03:00
|
|
|
if (!SdkConfig.get()['disable_custom_urls']) {
|
2017-10-25 04:04:02 +03:00
|
|
|
serverConfigSection = (
|
|
|
|
<ServerConfig ref="serverConfig"
|
|
|
|
withToggleButton={true}
|
|
|
|
customHsUrl={this.props.customHsUrl}
|
|
|
|
customIsUrl={this.props.customIsUrl}
|
|
|
|
defaultHsUrl={this.props.defaultHsUrl}
|
|
|
|
defaultIsUrl={this.props.defaultIsUrl}
|
|
|
|
onServerConfigChange={this.onServerConfigChange}
|
|
|
|
delayTimeMs={1000}
|
|
|
|
/>
|
|
|
|
);
|
2017-02-27 20:24:28 +03:00
|
|
|
}
|
2017-02-24 14:41:23 +03:00
|
|
|
registerBody = (
|
2017-02-27 20:24:28 +03:00
|
|
|
<div>
|
|
|
|
<RegistrationForm
|
|
|
|
defaultUsername={this.state.formVals.username}
|
|
|
|
defaultEmail={this.state.formVals.email}
|
2017-03-14 14:50:13 +03:00
|
|
|
defaultPhoneCountry={this.state.formVals.phoneCountry}
|
|
|
|
defaultPhoneNumber={this.state.formVals.phoneNumber}
|
2017-02-27 20:24:28 +03:00
|
|
|
defaultPassword={this.state.formVals.password}
|
|
|
|
teamsConfig={this.state.teamsConfig}
|
|
|
|
minPasswordLength={MIN_PASSWORD_LENGTH}
|
|
|
|
onError={this.onFormValidationFailed}
|
|
|
|
onRegisterClick={this.onFormSubmit}
|
|
|
|
onTeamSelected={this.onTeamSelected}
|
2018-09-04 20:26:09 +03:00
|
|
|
flows={this.state.flows}
|
2017-02-27 20:24:28 +03:00
|
|
|
/>
|
2017-10-25 04:04:02 +03:00
|
|
|
{ serverConfigSection }
|
2017-02-27 20:24:28 +03:00
|
|
|
</div>
|
2017-02-24 14:41:23 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-10-25 04:04:02 +03:00
|
|
|
let header;
|
|
|
|
let errorText;
|
2017-11-12 02:46:43 +03:00
|
|
|
// FIXME: remove hardcoded Status team tweaks at some point
|
2018-12-05 09:34:57 +03:00
|
|
|
const err = this.state.errorText || this.props.defaultServerDiscoveryError;
|
|
|
|
if (theme === 'status' && err) {
|
|
|
|
header = <div className="mx_Login_error">{ err }</div>;
|
2017-11-16 16:19:36 +03:00
|
|
|
} else {
|
2017-10-25 04:04:02 +03:00
|
|
|
header = <h2>{ _t('Create an account') }</h2>;
|
2018-12-05 09:34:57 +03:00
|
|
|
if (err) {
|
|
|
|
errorText = <div className="mx_Login_error">{ err }</div>;
|
2017-10-25 04:18:14 +03:00
|
|
|
}
|
2017-10-25 04:04:02 +03:00
|
|
|
}
|
|
|
|
|
2017-10-26 19:57:49 +03:00
|
|
|
let signIn;
|
|
|
|
if (!this.state.doingUIAuth) {
|
|
|
|
signIn = (
|
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-26 19:57:49 +03:00
|
|
|
{ theme === 'status' ? _t('Sign in') : _t('I already have an account') }
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-06-22 16:47:57 +03:00
|
|
|
const LanguageSelector = sdk.getComponent('structures.login.LanguageSelector');
|
|
|
|
|
2015-11-30 21:11:04 +03:00
|
|
|
return (
|
2017-10-25 01:37:26 +03:00
|
|
|
<LoginPage>
|
2015-11-30 21:11:04 +03:00
|
|
|
<div className="mx_Login_box">
|
2017-02-09 12:24:46 +03:00
|
|
|
<LoginHeader
|
|
|
|
icon={this.state.teamSelected ?
|
2017-02-09 16:16:46 +03:00
|
|
|
this.props.teamServerConfig.teamServerURL + "/static/common/" +
|
2017-02-09 12:24:46 +03:00
|
|
|
this.state.teamSelected.domain + "/icon.png" :
|
|
|
|
null}
|
|
|
|
/>
|
2017-10-25 04:04:02 +03:00
|
|
|
{ header }
|
2017-10-11 19:56:17 +03:00
|
|
|
{ registerBody }
|
2017-10-26 19:57:49 +03:00
|
|
|
{ signIn }
|
2017-10-25 04:04:02 +03:00
|
|
|
{ errorText }
|
2018-06-22 16:47:57 +03:00
|
|
|
<LanguageSelector />
|
2016-03-06 22:33:36 +03:00
|
|
|
<LoginFooter />
|
2015-11-30 21:11:04 +03:00
|
|
|
</div>
|
2017-10-25 01:37:26 +03:00
|
|
|
</LoginPage>
|
2015-11-30 21:11:04 +03:00
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
},
|
2015-11-30 21:11:04 +03:00
|
|
|
});
|