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).
This commit is contained in:
Luke Barnard 2017-01-30 15:50:31 +00:00
parent f5458d34aa
commit 4e0889454a
3 changed files with 47 additions and 19 deletions

15
src/RtsClient.js Normal file
View file

@ -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,
});
}
}

View file

@ -1060,7 +1060,7 @@ module.exports = React.createClass({
defaultHsUrl={this.getDefaultHsUrl()} defaultHsUrl={this.getDefaultHsUrl()}
defaultIsUrl={this.getDefaultIsUrl()} defaultIsUrl={this.getDefaultIsUrl()}
brand={this.props.config.brand} brand={this.props.config.brand}
teamsConfig={this.props.config.teamsConfig} teamServerConfig={this.props.config.teamServerConfig}
customHsUrl={this.getCurrentHsUrl()} customHsUrl={this.getCurrentHsUrl()}
customIsUrl={this.getCurrentIsUrl()} customIsUrl={this.getCurrentIsUrl()}
registrationUrl={this.props.registrationUrl} registrationUrl={this.props.registrationUrl}

View file

@ -25,6 +25,7 @@ var ServerConfig = require("../../views/login/ServerConfig");
var MatrixClientPeg = require("../../../MatrixClientPeg"); var MatrixClientPeg = require("../../../MatrixClientPeg");
var RegistrationForm = require("../../views/login/RegistrationForm"); var RegistrationForm = require("../../views/login/RegistrationForm");
var CaptchaForm = require("../../views/login/CaptchaForm"); var CaptchaForm = require("../../views/login/CaptchaForm");
var RtsClient = require("../../../RtsClient");
var MIN_PASSWORD_LENGTH = 6; var MIN_PASSWORD_LENGTH = 6;
@ -49,20 +50,11 @@ module.exports = React.createClass({
email: React.PropTypes.string, email: React.PropTypes.string,
username: React.PropTypes.string, username: React.PropTypes.string,
guestAccessToken: React.PropTypes.string, guestAccessToken: React.PropTypes.string,
teamsConfig: React.PropTypes.shape({ teamServerConfig: React.PropTypes.shape({
// Email address to request new teams // Email address to request new teams
supportEmail: React.PropTypes.string, supportEmail: React.PropTypes.string.isRequired,
teams: React.PropTypes.arrayOf(React.PropTypes.shape({ // URL of the riot-team-server to get team configurations and track referrals
// The displayed name of the team teamServerURL: React.PropTypes.string.isRequired,
"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,
}), }),
defaultDeviceDisplayName: React.PropTypes.string, defaultDeviceDisplayName: React.PropTypes.string,
@ -104,6 +96,27 @@ module.exports = React.createClass({
this.registerLogic.setIdSid(this.props.idSid); this.registerLogic.setIdSid(this.props.idSid);
this.registerLogic.setGuestAccessToken(this.props.guestAccessToken); this.registerLogic.setGuestAccessToken(this.props.guestAccessToken);
this.registerLogic.recheckState(); 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() { componentWillUnmount: function() {
@ -187,10 +200,10 @@ module.exports = React.createClass({
}); });
// Auto-join rooms // Auto-join rooms
if (self.props.teamsConfig && self.props.teamsConfig.teams) { if (self.state.teamsConfig && self.state.teamsConfig.teams) {
for (let i = 0; i < self.props.teamsConfig.teams.length; i++) { for (let i = 0; i < self.state.teamsConfig.teams.length; i++) {
let team = self.props.teamsConfig.teams[i]; let team = self.state.teamsConfig.teams[i];
if (self.state.formVals.email.endsWith(team.emailSuffix)) { if (self.state.formVals.email.endsWith(team.domain)) {
console.log("User successfully registered with team " + team.name); console.log("User successfully registered with team " + team.name);
if (!team.rooms) { if (!team.rooms) {
break; break;
@ -299,7 +312,7 @@ module.exports = React.createClass({
defaultUsername={this.state.formVals.username} defaultUsername={this.state.formVals.username}
defaultEmail={this.state.formVals.email} defaultEmail={this.state.formVals.email}
defaultPassword={this.state.formVals.password} defaultPassword={this.state.formVals.password}
teamsConfig={this.props.teamsConfig} teamsConfig={this.state.teamsConfig}
guestUsername={this.props.username} guestUsername={this.props.username}
minPasswordLength={MIN_PASSWORD_LENGTH} minPasswordLength={MIN_PASSWORD_LENGTH}
onError={this.onFormValidationFailed} onError={this.onFormValidationFailed}