Fix the team server registration

Pass extra info from the UI auth process as a second parameter to
onAuthFinished. Allows the email sid & client secret to be used
outside of the UI auth process.
pull/21833/head
David Baker 2017-03-06 17:31:21 +00:00
parent 49c66d8645
commit 341f978743
2 changed files with 21 additions and 17 deletions

View File

@ -45,7 +45,14 @@ export default React.createClass({
// successfully or unsuccessfully.
// @param {bool} status True if the operation requiring
// auth was completed sucessfully, false if canceled.
// @param result The result of the authenticated call
// @param {object} result The result of the authenticated call
// if successful, otherwise the error object
// @param {object} extra Additional information about the UI Auth
// process:
// * emailSid {string} If email auth was performed, the sid of
// the auth session.
// * clientSecret {string} The client secret used in auth
// sessions with the ID server.
onAuthFinished: React.PropTypes.func.isRequired,
// Inputs provided by the user to the auth process
@ -88,7 +95,11 @@ export default React.createClass({
});
this._authLogic.attemptAuth().then((result) => {
this.props.onAuthFinished(true, result);
const extra = {
emailSid: this._authLogic.getEmailSid(),
clientSecret: this._authLogic.getClientSecret(),
};
this.props.onAuthFinished(true, result, extra);
}).catch((error) => {
this.props.onAuthFinished(false, error);
console.error("Error during user-interactive auth:", error);

View File

@ -153,7 +153,7 @@ module.exports = React.createClass({
});
},
_onUIAuthFinished: function(success, response) {
_onUIAuthFinished: function(success, response, extra) {
if (!success) {
this.setState({
busy: false,
@ -168,26 +168,19 @@ module.exports = React.createClass({
busy: true,
doingUIAuth: false,
});
this.props.onLoggedIn({
userId: response.user_id,
deviceId: response.device_id,
homeserverUrl: this.state.hsUrl,
identityServerUrl: this.state.isUrl,
accessToken: response.access_token,
});
// 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).
let trackPromise = q(null);
if (this._rtsClient) {
if (this._rtsClient && extra.emailSid) {
// Track referral if this.props.referrer set, get team_token in order to
// retrieve team config and see welcome page etc.
trackPromise = this._rtsClient.trackReferral(
this.props.referrer || '', // Default to empty string = not referred
this.registerLogic.params.idSid,
this.registerLogic.params.clientSecret
extra.emailSid,
extra.clientSecret,
).then((data) => {
const teamToken = data.team_token;
// Store for use /w welcome pages
@ -223,13 +216,13 @@ module.exports = React.createClass({
this.props.onLoggedIn({
userId: response.user_id,
deviceId: response.device_id,
homeserverUrl: this.registerLogic.getHomeserverUrl(),
identityServerUrl: this.registerLogic.getIdentityServerUrl(),
homeserverUrl: this._matrixClient.getHomeserverUrl(),
identityServerUrl: this._matrixClient.getIdentityServerUrl(),
accessToken: response.access_token
}, teamToken);
}).then(() => {
return this._setupPushers();
}).done();
});
},
_setupPushers: function() {
@ -316,7 +309,7 @@ module.exports = React.createClass({
);
},
_getUIAuthInputs() {
_getUIAuthInputs: function() {
return {
emailAddress: this.state.formVals.email,
phoneCountry: this.state.formVals.phoneCountry,