allow registration and login from guest to be cancellable
This commit is contained in:
parent
f66dd69710
commit
b7726d34d5
3 changed files with 59 additions and 5 deletions
|
@ -226,10 +226,14 @@ module.exports = React.createClass({
|
||||||
switch (payload.action) {
|
switch (payload.action) {
|
||||||
case 'logout':
|
case 'logout':
|
||||||
if (window.localStorage) {
|
if (window.localStorage) {
|
||||||
|
var hsUrl = this.getCurrentHsUrl();
|
||||||
|
var isUrl = this.getCurrentIsUrl();
|
||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
// preserve our HS & IS URLs for convenience
|
// preserve our HS & IS URLs for convenience
|
||||||
window.localStorage.setItem("mx_hs_url", this.getCurrentHsUrl());
|
// N.B. we cache them in hsUrl/isUrl and can't really inline them
|
||||||
window.localStorage.setItem("mx_is_url", this.getCurrentIsUrl());
|
// as getCurrentHsUrl() may call through to localStorage.
|
||||||
|
window.localStorage.setItem("mx_hs_url", hsUrl);
|
||||||
|
window.localStorage.setItem("mx_is_url", isUrl);
|
||||||
}
|
}
|
||||||
Notifier.stop();
|
Notifier.stop();
|
||||||
UserActivity.stop();
|
UserActivity.stop();
|
||||||
|
@ -275,11 +279,31 @@ module.exports = React.createClass({
|
||||||
screen: 'post_registration'
|
screen: 'post_registration'
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case 'start_login_from_guest':
|
||||||
|
this.replaceState({
|
||||||
|
screen: 'login',
|
||||||
|
guestCreds: { // stash our guest creds so we can backout if needed
|
||||||
|
userId: MatrixClientPeg.get().credentials.userId,
|
||||||
|
accessToken: MatrixClientPeg.get().getAccessToken(),
|
||||||
|
homeserverUrl: MatrixClientPeg.get().getHomeserverUrl(),
|
||||||
|
identityServerUrl: MatrixClientPeg.get().getIdentityServerUrl(),
|
||||||
|
guest: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.notifyNewScreen('login');
|
||||||
|
break;
|
||||||
case 'start_upgrade_registration':
|
case 'start_upgrade_registration':
|
||||||
this.replaceState({
|
this.replaceState({
|
||||||
screen: "register",
|
screen: "register",
|
||||||
upgradeUsername: MatrixClientPeg.get().getUserIdLocalpart(),
|
upgradeUsername: MatrixClientPeg.get().getUserIdLocalpart(),
|
||||||
guestAccessToken: MatrixClientPeg.get().getAccessToken()
|
guestAccessToken: MatrixClientPeg.get().getAccessToken(),
|
||||||
|
guestCreds: { // stash our guest creds so we can backout if needed
|
||||||
|
userId: MatrixClientPeg.get().credentials.userId,
|
||||||
|
accessToken: MatrixClientPeg.get().getAccessToken(),
|
||||||
|
homeserverUrl: MatrixClientPeg.get().getHomeserverUrl(),
|
||||||
|
identityServerUrl: MatrixClientPeg.get().getIdentityServerUrl(),
|
||||||
|
guest: true
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.notifyNewScreen('register');
|
this.notifyNewScreen('register');
|
||||||
break;
|
break;
|
||||||
|
@ -858,6 +882,11 @@ module.exports = React.createClass({
|
||||||
this.showScreen("forgot_password");
|
this.showScreen("forgot_password");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onReturnToGuestClick: function() {
|
||||||
|
// reanimate our guest login
|
||||||
|
this.onLoggedIn(this.state.guestCreds);
|
||||||
|
},
|
||||||
|
|
||||||
onRegistered: function(credentials) {
|
onRegistered: function(credentials) {
|
||||||
this.onLoggedIn(credentials);
|
this.onLoggedIn(credentials);
|
||||||
// do post-registration stuff
|
// do post-registration stuff
|
||||||
|
@ -1042,7 +1071,9 @@ module.exports = React.createClass({
|
||||||
registrationUrl={this.props.registrationUrl}
|
registrationUrl={this.props.registrationUrl}
|
||||||
onLoggedIn={this.onRegistered}
|
onLoggedIn={this.onRegistered}
|
||||||
onLoginClick={this.onLoginClick}
|
onLoginClick={this.onLoginClick}
|
||||||
onRegisterClick={this.onRegisterClick} />
|
onRegisterClick={this.onRegisterClick}
|
||||||
|
onCancelClick={ MatrixClientPeg.get() && MatrixClientPeg.get().isGuest() ? this.onReturnToGuestClick : null }
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
} else if (this.state.screen == 'forgot_password') {
|
} else if (this.state.screen == 'forgot_password') {
|
||||||
return (
|
return (
|
||||||
|
@ -1065,6 +1096,7 @@ module.exports = React.createClass({
|
||||||
customIsUrl={this.getCurrentIsUrl()}
|
customIsUrl={this.getCurrentIsUrl()}
|
||||||
onForgotPasswordClick={this.onForgotPasswordClick}
|
onForgotPasswordClick={this.onForgotPasswordClick}
|
||||||
onLoginAsGuestClick={this.props.enableGuest && this.props.config && this.props.config.default_hs_url ? this._registerAsGuest: undefined}
|
onLoginAsGuestClick={this.props.enableGuest && this.props.config && this.props.config.default_hs_url ? this._registerAsGuest: undefined}
|
||||||
|
onCancelClick={ MatrixClientPeg.get() && MatrixClientPeg.get().isGuest() ? this.onReturnToGuestClick : null }
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ module.exports = React.createClass({displayName: 'Login',
|
||||||
// login shouldn't care how password recovery is done.
|
// login shouldn't care how password recovery is done.
|
||||||
onForgotPasswordClick: React.PropTypes.func,
|
onForgotPasswordClick: React.PropTypes.func,
|
||||||
onLoginAsGuestClick: React.PropTypes.func,
|
onLoginAsGuestClick: React.PropTypes.func,
|
||||||
|
onCancelClick: React.PropTypes.func,
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
|
@ -211,6 +212,15 @@ module.exports = React.createClass({displayName: 'Login',
|
||||||
Login as guest
|
Login as guest
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var 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">
|
||||||
|
@ -235,6 +245,7 @@ module.exports = React.createClass({displayName: 'Login',
|
||||||
Create a new account
|
Create a new account
|
||||||
</a>
|
</a>
|
||||||
{ loginAsGuestJsx }
|
{ loginAsGuestJsx }
|
||||||
|
{ returnToAppJsx }
|
||||||
<LoginFooter />
|
<LoginFooter />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -45,7 +45,8 @@ module.exports = React.createClass({
|
||||||
guestAccessToken: React.PropTypes.string,
|
guestAccessToken: React.PropTypes.string,
|
||||||
disableUsernameChanges: React.PropTypes.bool,
|
disableUsernameChanges: React.PropTypes.bool,
|
||||||
// registration shouldn't know or care how login is done.
|
// registration shouldn't know or care how login is done.
|
||||||
onLoginClick: React.PropTypes.func.isRequired
|
onLoginClick: React.PropTypes.func.isRequired,
|
||||||
|
onCancelClick: React.PropTypes.func
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
|
@ -234,6 +235,15 @@ module.exports = React.createClass({
|
||||||
<Spinner />
|
<Spinner />
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var returnToAppJsx;
|
||||||
|
if (this.props.onCancelClick) {
|
||||||
|
returnToAppJsx =
|
||||||
|
<a className="mx_Login_create" onClick={this.props.onCancelClick} href="#">
|
||||||
|
Return to app
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2>Create an account</h2>
|
<h2>Create an account</h2>
|
||||||
|
@ -254,6 +264,7 @@ module.exports = React.createClass({
|
||||||
<a className="mx_Login_create" onClick={this.props.onLoginClick} href="#">
|
<a className="mx_Login_create" onClick={this.props.onLoginClick} href="#">
|
||||||
I already have an account
|
I already have an account
|
||||||
</a>
|
</a>
|
||||||
|
{ returnToAppJsx }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue