From 4e0889454a5d349a375606c2d98b29c558b1bea0 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 30 Jan 2017 15:50:31 +0000 Subject: [PATCH 1/6] GET /teams from RTS instead of config.json Now that the RTS contains config for teams, use GET /teams to get that information so that users will see be able to register as a team (but not yet auto-join rooms, be sent to welcome page or be tracked as a referral). --- src/RtsClient.js | 15 ++++++ src/components/structures/MatrixChat.js | 2 +- .../structures/login/Registration.js | 49 ++++++++++++------- 3 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 src/RtsClient.js diff --git a/src/RtsClient.js b/src/RtsClient.js new file mode 100644 index 0000000000..25ed71b72b --- /dev/null +++ b/src/RtsClient.js @@ -0,0 +1,15 @@ +const q = require('q'); +const request = q.nfbind(require('browser-request')); + +export default class RtsClient { + constructor(url) { + this._url = url; + } + + getTeamsConfig() { + return request({ + url: this._url + '/teams', + json: true, + }); + } +} diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index cb61041d48..989ae5aace 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -1060,7 +1060,7 @@ module.exports = React.createClass({ defaultHsUrl={this.getDefaultHsUrl()} defaultIsUrl={this.getDefaultIsUrl()} brand={this.props.config.brand} - teamsConfig={this.props.config.teamsConfig} + teamServerConfig={this.props.config.teamServerConfig} customHsUrl={this.getCurrentHsUrl()} customIsUrl={this.getCurrentIsUrl()} registrationUrl={this.props.registrationUrl} diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index 20c26c6b22..e34007ef42 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -25,6 +25,7 @@ var ServerConfig = require("../../views/login/ServerConfig"); var MatrixClientPeg = require("../../../MatrixClientPeg"); var RegistrationForm = require("../../views/login/RegistrationForm"); var CaptchaForm = require("../../views/login/CaptchaForm"); +var RtsClient = require("../../../RtsClient"); var MIN_PASSWORD_LENGTH = 6; @@ -49,20 +50,11 @@ module.exports = React.createClass({ email: React.PropTypes.string, username: React.PropTypes.string, guestAccessToken: React.PropTypes.string, - teamsConfig: React.PropTypes.shape({ + teamServerConfig: React.PropTypes.shape({ // Email address to request new teams - supportEmail: React.PropTypes.string, - teams: React.PropTypes.arrayOf(React.PropTypes.shape({ - // The displayed name of the team - "name": React.PropTypes.string, - // The suffix with which every team email address ends - "emailSuffix": React.PropTypes.string, - // The rooms to use during auto-join - "rooms": React.PropTypes.arrayOf(React.PropTypes.shape({ - "id": React.PropTypes.string, - "autoJoin": React.PropTypes.bool, - })), - })).required, + supportEmail: React.PropTypes.string.isRequired, + // URL of the riot-team-server to get team configurations and track referrals + teamServerURL: React.PropTypes.string.isRequired, }), defaultDeviceDisplayName: React.PropTypes.string, @@ -104,6 +96,27 @@ module.exports = React.createClass({ this.registerLogic.setIdSid(this.props.idSid); this.registerLogic.setGuestAccessToken(this.props.guestAccessToken); this.registerLogic.recheckState(); + + if (this.props.teamServerConfig && + this.props.teamServerConfig.teamServerURL && + !this._rtsClient) { + this._rtsClient = new RtsClient(this.props.teamServerConfig.teamServerURL); + + // GET team configurations including domains, names and icons + this._rtsClient.getTeamsConfig().done((args) => { + // args = [$request, $body] + const teamsConfig = { + teams: args[1], + supportEmail: this.props.teamServerConfig.supportEmail, + }; + console.log('Setting teams config to ', teamsConfig); + this.setState({ + teamsConfig: teamsConfig, + }); + }, (err) => { + console.error('Error retrieving config for teams', err); + }); + } }, componentWillUnmount: function() { @@ -187,10 +200,10 @@ module.exports = React.createClass({ }); // Auto-join rooms - if (self.props.teamsConfig && self.props.teamsConfig.teams) { - for (let i = 0; i < self.props.teamsConfig.teams.length; i++) { - let team = self.props.teamsConfig.teams[i]; - if (self.state.formVals.email.endsWith(team.emailSuffix)) { + if (self.state.teamsConfig && self.state.teamsConfig.teams) { + for (let i = 0; i < self.state.teamsConfig.teams.length; i++) { + let team = self.state.teamsConfig.teams[i]; + if (self.state.formVals.email.endsWith(team.domain)) { console.log("User successfully registered with team " + team.name); if (!team.rooms) { break; @@ -299,7 +312,7 @@ module.exports = React.createClass({ defaultUsername={this.state.formVals.username} defaultEmail={this.state.formVals.email} defaultPassword={this.state.formVals.password} - teamsConfig={this.props.teamsConfig} + teamsConfig={this.state.teamsConfig} guestUsername={this.props.username} minPasswordLength={MIN_PASSWORD_LENGTH} onError={this.onFormValidationFailed} From 318d8710977b99a4b61799625c2620ac3afa105e Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 30 Jan 2017 16:13:57 +0000 Subject: [PATCH 2/6] Formatting --- src/components/structures/login/Registration.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index e34007ef42..f1085f2e07 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -97,9 +97,11 @@ module.exports = React.createClass({ this.registerLogic.setGuestAccessToken(this.props.guestAccessToken); this.registerLogic.recheckState(); - if (this.props.teamServerConfig && - this.props.teamServerConfig.teamServerURL && - !this._rtsClient) { + if ( + this.props.teamServerConfig && + this.props.teamServerConfig.teamServerURL && + !this._rtsClient + ) { this._rtsClient = new RtsClient(this.props.teamServerConfig.teamServerURL); // GET team configurations including domains, names and icons From eb4d7f04e79fb4ecea156eb83edb94919b53519f Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 30 Jan 2017 16:23:52 +0000 Subject: [PATCH 3/6] Use busy spinner when requesting teams --- src/components/structures/login/Registration.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index f1085f2e07..1456b666f4 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -67,6 +67,7 @@ module.exports = React.createClass({ getInitialState: function() { return { busy: false, + teamServerBusy: false, errorText: null, // We remember the values entered by the user because // the registration form will be unmounted during the @@ -104,8 +105,11 @@ module.exports = React.createClass({ ) { this._rtsClient = new RtsClient(this.props.teamServerConfig.teamServerURL); + this.setState({ + teamServerBusy: true, + }); // GET team configurations including domains, names and icons - this._rtsClient.getTeamsConfig().done((args) => { + this._rtsClient.getTeamsConfig().then((args) => { // args = [$request, $body] const teamsConfig = { teams: args[1], @@ -117,6 +121,10 @@ module.exports = React.createClass({ }); }, (err) => { console.error('Error retrieving config for teams', err); + }).finally(() => { + this.setState({ + teamServerBusy: false, + }); }); } }, @@ -299,6 +307,8 @@ module.exports = React.createClass({ }, _getRegisterContentJsx: function() { + var Spinner = sdk.getComponent("elements.Spinner"); + var currStep = this.registerLogic.getStep(); var registerStep; switch (currStep) { @@ -308,6 +318,10 @@ module.exports = React.createClass({ case "Register.STEP_m.login.dummy": // NB. Our 'username' prop is specifically for upgrading // a guest account + if (this.state.teamServerBusy) { + registerStep = ; + break; + } registerStep = ( Date: Mon, 30 Jan 2017 16:33:16 +0000 Subject: [PATCH 4/6] Use const, not var --- src/components/structures/login/Registration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index 1456b666f4..eed370a7ac 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -307,7 +307,7 @@ module.exports = React.createClass({ }, _getRegisterContentJsx: function() { - var Spinner = sdk.getComponent("elements.Spinner"); + const Spinner = sdk.getComponent("elements.Spinner"); var currStep = this.registerLogic.getStep(); var registerStep; From 1e279d23354387ec585fd9e4f9d34d0c3a98cb4b Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 30 Jan 2017 16:35:34 +0000 Subject: [PATCH 5/6] Finish with .done() --- src/components/structures/login/Registration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index eed370a7ac..a4dcd63d9d 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -125,7 +125,7 @@ module.exports = React.createClass({ this.setState({ teamServerBusy: false, }); - }); + }).done(); } }, From 4e9229e936a1d0991f4e958eb800e1d297658c9f Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 30 Jan 2017 16:37:16 +0000 Subject: [PATCH 6/6] Get rid of dupl. declaration --- src/components/structures/login/Registration.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index a4dcd63d9d..730f31c8ad 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -363,7 +363,6 @@ module.exports = React.createClass({ } var busySpinner; if (this.state.busy) { - var Spinner = sdk.getComponent("elements.Spinner"); busySpinner = ( );