Put back server picker for registration
* Also fix bug where you couldn't picxk a different server if you were already registered as a guest (because it still sent the access token which the new server rejected) * Propagate errors from UI auth back to registration so it goes back to the registration screen
This commit is contained in:
parent
454aa0757a
commit
e5853a6571
2 changed files with 75 additions and 24 deletions
|
@ -91,6 +91,7 @@ export default React.createClass({
|
||||||
this._authLogic.attemptAuth().then((result) => {
|
this._authLogic.attemptAuth().then((result) => {
|
||||||
this.props.onFinished(true, result);
|
this.props.onFinished(true, result);
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
|
this.props.onFinished(false, error);
|
||||||
console.error("Error during user-interactive auth:", error);
|
console.error("Error during user-interactive auth:", error);
|
||||||
if (this._unmounted) {
|
if (this._unmounted) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -20,7 +20,6 @@ import Matrix from 'matrix-js-sdk';
|
||||||
var React = require('react');
|
var React = require('react');
|
||||||
|
|
||||||
var sdk = require('../../../index');
|
var sdk = require('../../../index');
|
||||||
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");
|
||||||
|
@ -86,14 +85,14 @@ module.exports = React.createClass({
|
||||||
// If we've been given a session ID, we're resuming
|
// If we've been given a session ID, we're resuming
|
||||||
// straight back into UI auth
|
// straight back into UI auth
|
||||||
doingUIAuth: Boolean(this.props.sessionId),
|
doingUIAuth: Boolean(this.props.sessionId),
|
||||||
|
hsUrl: this.props.customHsUrl,
|
||||||
|
isUrl: this.props.customIsUrl,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
this._unmounted = false;
|
this._unmounted = false;
|
||||||
|
|
||||||
this._hsUrl = this.props.customHsUrl;
|
|
||||||
this._isUrl = this.props.customIsUrl;
|
|
||||||
this._replaceClient();
|
this._replaceClient();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -127,24 +126,27 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
onHsUrlChanged: function(newHsUrl) {
|
onHsUrlChanged: function(newHsUrl) {
|
||||||
this._hsUrl = newHsUrl;
|
this.setState({
|
||||||
|
hsUrl: newHsUrl,
|
||||||
|
});
|
||||||
this._replaceClient();
|
this._replaceClient();
|
||||||
},
|
},
|
||||||
|
|
||||||
onIsUrlChanged: function(newIsUrl) {
|
onIsUrlChanged: function(newIsUrl) {
|
||||||
this._isUrl = newIsUrl;
|
this.setState({
|
||||||
|
isUrl: newIsUrl,
|
||||||
|
});
|
||||||
this._replaceClient();
|
this._replaceClient();
|
||||||
},
|
},
|
||||||
|
|
||||||
_replaceClient: function() {
|
_replaceClient: function() {
|
||||||
this._matrixClient = Matrix.createClient({
|
this._matrixClient = Matrix.createClient({
|
||||||
baseUrl: this._hsUrl,
|
baseUrl: this.state.hsUrl,
|
||||||
idBaseUrl: this._isUrl,
|
idBaseUrl: this.state.isUrl,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onFormSubmit: function(formVals) {
|
onFormSubmit: function(formVals) {
|
||||||
var self = this;
|
|
||||||
this.setState({
|
this.setState({
|
||||||
errorText: "",
|
errorText: "",
|
||||||
busy: true,
|
busy: true,
|
||||||
|
@ -153,7 +155,16 @@ module.exports = React.createClass({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_onRegistered: function(success, response) {
|
_onUIAuthFinished: function(success, response) {
|
||||||
|
if (!success) {
|
||||||
|
this.setState({
|
||||||
|
busy: false,
|
||||||
|
doingUIAuth: false,
|
||||||
|
errorText: response.message || response.toString(),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
// we're still busy until we get unmounted: don't show the registration form again
|
// we're still busy until we get unmounted: don't show the registration form again
|
||||||
busy: true,
|
busy: true,
|
||||||
|
@ -162,8 +173,8 @@ module.exports = React.createClass({
|
||||||
this.props.onLoggedIn({
|
this.props.onLoggedIn({
|
||||||
userId: response.user_id,
|
userId: response.user_id,
|
||||||
deviceId: response.device_id,
|
deviceId: response.device_id,
|
||||||
homeserverUrl: this._hsUrl,
|
homeserverUrl: this.state.hsUrl,
|
||||||
identityServerUrl: this._isUrl,
|
identityServerUrl: this.state.isUrl,
|
||||||
accessToken: response.access_token,
|
accessToken: response.access_token,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -267,8 +278,12 @@ module.exports = React.createClass({
|
||||||
_makeRegisterRequest: function(auth) {
|
_makeRegisterRequest: function(auth) {
|
||||||
let guestAccessToken = this.props.guestAccessToken;
|
let guestAccessToken = this.props.guestAccessToken;
|
||||||
|
|
||||||
if (this.state.formVals.username !== this.props.username) {
|
if (
|
||||||
|
this.state.formVals.username !== this.props.username ||
|
||||||
|
this.state.hsUrl != this.props.defaultHsUrl
|
||||||
|
) {
|
||||||
// don't try to upgrade if we changed our username
|
// don't try to upgrade if we changed our username
|
||||||
|
// or are registering on a different HS
|
||||||
guestAccessToken = null;
|
guestAccessToken = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,6 +313,7 @@ module.exports = React.createClass({
|
||||||
const LoginFooter = sdk.getComponent('login.LoginFooter');
|
const LoginFooter = sdk.getComponent('login.LoginFooter');
|
||||||
const InteractiveAuth = sdk.getComponent('structures.InteractiveAuth');
|
const InteractiveAuth = sdk.getComponent('structures.InteractiveAuth');
|
||||||
const Spinner = sdk.getComponent("elements.Spinner");
|
const Spinner = sdk.getComponent("elements.Spinner");
|
||||||
|
const ServerConfig = sdk.getComponent('views.login.ServerConfig');
|
||||||
|
|
||||||
let registerBody;
|
let registerBody;
|
||||||
if (this.state.doingUIAuth) {
|
if (this.state.doingUIAuth) {
|
||||||
|
@ -305,7 +321,7 @@ module.exports = React.createClass({
|
||||||
<InteractiveAuth
|
<InteractiveAuth
|
||||||
matrixClient={this._matrixClient}
|
matrixClient={this._matrixClient}
|
||||||
makeRequest={this._makeRegisterRequest}
|
makeRequest={this._makeRegisterRequest}
|
||||||
onFinished={this._onRegistered}
|
onFinished={this._onUIAuthFinished}
|
||||||
inputs={this._getUIAuthInputs()}
|
inputs={this._getUIAuthInputs()}
|
||||||
makeRegistrationUrl={this.props.makeRegistrationUrl}
|
makeRegistrationUrl={this.props.makeRegistrationUrl}
|
||||||
sessionId={this.props.sessionId}
|
sessionId={this.props.sessionId}
|
||||||
|
@ -317,21 +333,50 @@ module.exports = React.createClass({
|
||||||
} else if (this.state.busy || this.state.teamServerBusy) {
|
} else if (this.state.busy || this.state.teamServerBusy) {
|
||||||
registerBody = <Spinner />;
|
registerBody = <Spinner />;
|
||||||
} else {
|
} else {
|
||||||
|
let guestUsername = this.props.username;
|
||||||
|
if (this.state.hsUrl != this.props.defaultHsUrl) {
|
||||||
|
guestUsername = null;
|
||||||
|
}
|
||||||
|
let errorSection;
|
||||||
|
if (this.state.errorText) {
|
||||||
|
errorSection = <div className="mx_Login_error">{this.state.errorText}</div>;
|
||||||
|
}
|
||||||
registerBody = (
|
registerBody = (
|
||||||
<RegistrationForm
|
<div>
|
||||||
defaultUsername={this.state.formVals.username}
|
<RegistrationForm
|
||||||
defaultEmail={this.state.formVals.email}
|
defaultUsername={this.state.formVals.username}
|
||||||
defaultPassword={this.state.formVals.password}
|
defaultEmail={this.state.formVals.email}
|
||||||
teamsConfig={this.state.teamsConfig}
|
defaultPassword={this.state.formVals.password}
|
||||||
guestUsername={this.props.username}
|
teamsConfig={this.state.teamsConfig}
|
||||||
minPasswordLength={MIN_PASSWORD_LENGTH}
|
guestUsername={guestUsername}
|
||||||
onError={this.onFormValidationFailed}
|
minPasswordLength={MIN_PASSWORD_LENGTH}
|
||||||
onRegisterClick={this.onFormSubmit}
|
onError={this.onFormValidationFailed}
|
||||||
onTeamSelected={this.onTeamSelected}
|
onRegisterClick={this.onFormSubmit}
|
||||||
/>
|
onTeamSelected={this.onTeamSelected}
|
||||||
|
/>
|
||||||
|
{errorSection}
|
||||||
|
<ServerConfig ref="serverConfig"
|
||||||
|
withToggleButton={true}
|
||||||
|
customHsUrl={this.props.customHsUrl}
|
||||||
|
customIsUrl={this.props.customIsUrl}
|
||||||
|
defaultHsUrl={this.props.defaultHsUrl}
|
||||||
|
defaultIsUrl={this.props.defaultIsUrl}
|
||||||
|
onHsUrlChanged={this.onHsUrlChanged}
|
||||||
|
onIsUrlChanged={this.onIsUrlChanged}
|
||||||
|
delayTimeMs={1000}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let returnToAppJsx;
|
||||||
|
if (this.props.onCancelClick) {
|
||||||
|
returnToAppJsx = (
|
||||||
|
<a className="mx_Login_create" onClick={this.props.onCancelClick} href="#">
|
||||||
|
Return to app
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="mx_Login">
|
<div className="mx_Login">
|
||||||
<div className="mx_Login_box">
|
<div className="mx_Login_box">
|
||||||
|
@ -341,7 +386,12 @@ module.exports = React.createClass({
|
||||||
this.state.teamSelected.domain + "/icon.png" :
|
this.state.teamSelected.domain + "/icon.png" :
|
||||||
null}
|
null}
|
||||||
/>
|
/>
|
||||||
|
<h2>Create an account</h2>
|
||||||
{registerBody}
|
{registerBody}
|
||||||
|
<a className="mx_Login_create" onClick={this.props.onLoginClick} href="#">
|
||||||
|
I already have an account
|
||||||
|
</a>
|
||||||
|
{returnToAppJsx}
|
||||||
<LoginFooter />
|
<LoginFooter />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue