From d9a8acd431acba65b3624055753cfba5b4d2b237 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 27 Jan 2017 16:31:36 +0000 Subject: [PATCH] Redo team-based registration (#657) For compatibility with referral campaign flows, re-implement team registration such that the team is selected through providing an email with a known team domain. The support email is now only shown when an email that _looks_ like a UK/US university email address, but is not known. --- .../structures/login/Registration.js | 16 ++- .../views/login/RegistrationForm.js | 127 +++++++----------- 2 files changed, 60 insertions(+), 83 deletions(-) diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index 90140b3280..20c26c6b22 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -90,6 +90,7 @@ module.exports = React.createClass({ }, componentWillMount: function() { + this._unmounted = false; this.dispatcherRef = dis.register(this.onAction); // attach this to the instance rather than this.state since it isn't UI this.registerLogic = new Signup.Register( @@ -107,6 +108,7 @@ module.exports = React.createClass({ componentWillUnmount: function() { dis.unregister(this.dispatcherRef); + this._unmounted = true; }, componentDidMount: function() { @@ -273,6 +275,14 @@ module.exports = React.createClass({ }); }, + onTeamSelected: function(team) { + if (!this._unmounted) { + this.setState({ + teamIcon: team ? team.icon : null, + }); + } + }, + _getRegisterContentJsx: function() { var currStep = this.registerLogic.getStep(); var registerStep; @@ -293,7 +303,9 @@ module.exports = React.createClass({ guestUsername={this.props.username} minPasswordLength={MIN_PASSWORD_LENGTH} onError={this.onFormValidationFailed} - onRegisterClick={this.onFormSubmit} /> + onRegisterClick={this.onFormSubmit} + onTeamSelected={this.onTeamSelected} + /> ); break; case "Register.STEP_m.login.email.identity": @@ -367,7 +379,7 @@ module.exports = React.createClass({ return (
- + {this._getRegisterContentJsx()}
diff --git a/src/components/views/login/RegistrationForm.js b/src/components/views/login/RegistrationForm.js index f8a0863f70..1cb8253812 100644 --- a/src/components/views/login/RegistrationForm.js +++ b/src/components/views/login/RegistrationForm.js @@ -44,8 +44,8 @@ module.exports = React.createClass({ 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 domain of team email addresses + "domain": React.PropTypes.string, })).required, }), @@ -117,9 +117,6 @@ module.exports = React.createClass({ _doSubmit: function() { let email = this.refs.email.value.trim(); - if (this.state.selectedTeam) { - email += "@" + this.state.selectedTeam.emailSuffix; - } var promise = this.props.onRegisterClick({ username: this.refs.username.value.trim() || this.props.guestUsername, password: this.refs.password.value.trim(), @@ -134,25 +131,6 @@ module.exports = React.createClass({ } }, - onSelectTeam: function(teamIndex) { - let team = this._getSelectedTeam(teamIndex); - if (team) { - this.refs.email.value = this.refs.email.value.split("@")[0]; - } - this.setState({ - selectedTeam: team, - showSupportEmail: teamIndex === "other", - }); - }, - - _getSelectedTeam: function(teamIndex) { - if (this.props.teamsConfig && - this.props.teamsConfig.teams[teamIndex]) { - return this.props.teamsConfig.teams[teamIndex]; - } - return null; - }, - /** * Returns true if all fields were valid last time * they were validated. @@ -167,20 +145,36 @@ module.exports = React.createClass({ return true; }, + _isUniEmail: function(email) { + return email.endsWith('.ac.uk') || email.endsWith('.edu'); + }, + validateField: function(field_id) { var pwd1 = this.refs.password.value.trim(); var pwd2 = this.refs.passwordConfirm.value.trim(); switch (field_id) { case FIELD_EMAIL: - let email = this.refs.email.value; - if (this.props.teamsConfig) { - let team = this.state.selectedTeam; - if (team) { - email = email + "@" + team.emailSuffix; - } + const email = this.refs.email.value; + if (this.props.teamsConfig && this._isUniEmail(email)) { + const matchingTeam = this.props.teamsConfig.teams.find( + (team) => { + return email.split('@').pop() === team.domain; + } + ) || null; + this.setState({ + selectedTeam: matchingTeam, + showSupportEmail: !matchingTeam, + }); + this.props.onTeamSelected(matchingTeam); + } else { + this.props.onTeamSelected(null); + this.setState({ + selectedTeam: null, + showSupportEmail: false, + }); } - let valid = email === '' || Email.looksValid(email); + const valid = email === '' || Email.looksValid(email); this.markFieldValid(field_id, valid, "RegistrationForm.ERR_EMAIL_INVALID"); break; case FIELD_USERNAME: @@ -260,61 +254,35 @@ module.exports = React.createClass({ return cls; }, - _renderEmailInputSuffix: function() { - let suffix = null; - if (!this.state.selectedTeam) { - return suffix; - } - let team = this.state.selectedTeam; - if (team) { - suffix = "@" + team.emailSuffix; - } - return suffix; - }, - render: function() { var self = this; - var emailSection, teamSection, teamAdditionSupport, registerButton; + var emailSection, belowEmailSection, registerButton; if (this.props.showEmail) { - let emailSuffix = this._renderEmailInputSuffix(); emailSection = ( -
- - {emailSuffix ? : null } -
+ ); if (this.props.teamsConfig) { - teamSection = ( - - ); if (this.props.teamsConfig.supportEmail && this.state.showSupportEmail) { - teamAdditionSupport = ( - - If your team is not listed, email  + belowEmailSection = ( +

+ Sorry, but your university is not registered with us just yet.  + Email us on  {this.props.teamsConfig.supportEmail} - - +   + to get your university signed up. Or continue to register with Riot to enjoy our open source platform. +

+ ); + } else if (this.state.selectedTeam) { + belowEmailSection = ( +

+ You are registering with {this.state.selectedTeam.name} +

); } } @@ -333,11 +301,8 @@ module.exports = React.createClass({ return (
- {teamSection} - {teamAdditionSupport} -
{emailSection} -
+ {belowEmailSection}