This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 827
allow registration and login from guest to be cancellable #220
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,10 +226,14 @@ module.exports = React.createClass({ | |
switch (payload.action) { | ||
case 'logout': | ||
if (window.localStorage) { | ||
var hsUrl = this.getCurrentHsUrl(); | ||
var isUrl = this.getCurrentIsUrl(); | ||
window.localStorage.clear(); | ||
// preserve our HS & IS URLs for convenience | ||
window.localStorage.setItem("mx_hs_url", this.getCurrentHsUrl()); | ||
window.localStorage.setItem("mx_is_url", this.getCurrentIsUrl()); | ||
// N.B. we cache them in hsUrl/isUrl and can't really inline them | ||
// as getCurrentHsUrl() may call through to localStorage. | ||
window.localStorage.setItem("mx_hs_url", hsUrl); | ||
window.localStorage.setItem("mx_is_url", isUrl); | ||
} | ||
Notifier.stop(); | ||
UserActivity.stop(); | ||
|
@@ -275,11 +279,31 @@ module.exports = React.createClass({ | |
screen: 'post_registration' | ||
}); | ||
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': | ||
this.replaceState({ | ||
screen: "register", | ||
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'); | ||
break; | ||
|
@@ -858,6 +882,11 @@ module.exports = React.createClass({ | |
this.showScreen("forgot_password"); | ||
}, | ||
|
||
onReturnToGuestClick: function() { | ||
// reanimate our guest login | ||
this.onLoggedIn(this.state.guestCreds); | ||
}, | ||
|
||
onRegistered: function(credentials) { | ||
this.onLoggedIn(credentials); | ||
// do post-registration stuff | ||
|
@@ -1042,7 +1071,9 @@ module.exports = React.createClass({ | |
registrationUrl={this.props.registrationUrl} | ||
onLoggedIn={this.onRegistered} | ||
onLoginClick={this.onLoginClick} | ||
onRegisterClick={this.onRegisterClick} /> | ||
onRegisterClick={this.onRegisterClick} | ||
onCancelClick={ MatrixClientPeg.get() && MatrixClientPeg.get().isGuest() ? this.onReturnToGuestClick : null } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this work? Will this not hide the back-to-app div if the user does anything to cause the matrix client to be replaced, like changing home servers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops, good catch. fixed. |
||
/> | ||
); | ||
} else if (this.state.screen == 'forgot_password') { | ||
return ( | ||
|
@@ -1065,6 +1096,7 @@ module.exports = React.createClass({ | |
customIsUrl={this.getCurrentIsUrl()} | ||
onForgotPasswordClick={this.onForgotPasswordClick} | ||
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 } | ||
/> | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be a separate thing? ie. could start_login just do
if (MatrixClientPeg.get().isGuest()) {...
and if something explicitly wants to log out first, it can just post thelogout
action first?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, it could be combined together. i guess it was a choice of separating the two flows with an isGuest() or adding a different dispatch target. keeping it separate gives us the option of logging in without preserving the guest details if desired (e.g. if you explicitly wanted to replace your current session with a new login). i'm not sure that one is a huge win over the other, but yell if you feel strongly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, I don't really feel strongly.