-
-
Notifications
You must be signed in to change notification settings - Fork 832
Bring back lost functionality on login/register/password-reset screens #200
Changes from 2 commits
0bb58dd
a82d371
893e338
438558d
59866a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ var matrixClient = null; | |
var localStorage = window.localStorage; | ||
|
||
function deviceId() { | ||
// XXX: is Math.random()'s deterministicity a problem here? | ||
var id = Math.floor(Math.random()*16777215).toString(16); | ||
id = "W" + "000000".substring(id.length) + id; | ||
if (localStorage) { | ||
|
@@ -101,10 +102,12 @@ class MatrixClient { | |
// -matthew | ||
|
||
replaceUsingUrls(hs_url, is_url) { | ||
// ...not to be confused with MatrixClientPeg's createClient... | ||
matrixClient = Matrix.createClient({ | ||
baseUrl: hs_url, | ||
idBaseUrl: is_url | ||
}); | ||
|
||
// XXX: factor this out with the localStorage setting in replaceUsingAccessToken | ||
if (localStorage) { | ||
try { | ||
|
@@ -115,18 +118,19 @@ class MatrixClient { | |
} | ||
} else { | ||
console.warn("No local storage available: can't persist HS/IS URLs!"); | ||
} | ||
} | ||
} | ||
|
||
replaceUsingAccessToken(hs_url, is_url, user_id, access_token, isGuest) { | ||
if (localStorage) { | ||
try { | ||
localStorage.clear(); | ||
} catch (e) { | ||
console.warn("Error using local storage"); | ||
console.warn("Error clearing local storage", e); | ||
} | ||
} | ||
this.guestAccess.markAsGuest(Boolean(isGuest)); | ||
// ...not to be confused with Matrix.createClient()... | ||
createClient(hs_url, is_url, user_id, access_token, this.guestAccess); | ||
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. Given |
||
if (localStorage) { | ||
try { | ||
|
@@ -136,7 +140,7 @@ class MatrixClient { | |
localStorage.setItem("mx_access_token", access_token); | ||
console.log("Session persisted for %s", user_id); | ||
} catch (e) { | ||
console.warn("Error using local storage: can't persist session!"); | ||
console.warn("Error using local storage: can't persist session!", e); | ||
} | ||
} else { | ||
console.warn("No local storage available: can't persist session!"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,15 +85,41 @@ module.exports = React.createClass({ | |
}; | ||
}, | ||
|
||
getCurrentHsUrl: function() { | ||
if (MatrixClientPeg.get()) { | ||
return MatrixClientPeg.get().getHomeserverUrl(); | ||
} | ||
else if (window.localStorage && window.localStorage.getItem("mx_hs_url")) { | ||
return window.localStorage.getItem("mx_hs_url"); | ||
} | ||
else if (this.props.config) { | ||
return this.props.config.default_hs_url | ||
} | ||
return "https://matrix.org"; | ||
}, | ||
|
||
getCurrentIsUrl: function() { | ||
if (MatrixClientPeg.get()) { | ||
return MatrixClientPeg.get().getIdentityServerUrl(); | ||
} | ||
else if (window.localStorage && window.localStorage.getItem("mx_is_url")) { | ||
return window.localStorage.getItem("mx_is_url"); | ||
} | ||
else if (this.props.config) { | ||
return this.props.config.default_is_url | ||
} | ||
return "https://matrix.org"; | ||
}, | ||
|
||
componentWillMount: function() { | ||
this.favicon = new Favico({animation: 'none'}); | ||
}, | ||
|
||
componentDidMount: function() { | ||
this._autoRegisterAsGuest = false; | ||
if (this.props.enableGuest) { | ||
if (!this.props.config || !this.props.config.default_hs_url) { | ||
console.error("Cannot enable guest access: No supplied config prop for HS/IS URLs"); | ||
if (!this.getCurrentHsUrl() || !this.getCurrentIsUrl()) { | ||
console.error("Cannot enable guest access: can't determine HS/IS URLs to use"); | ||
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. Do we really need an IS URL specified to register as a guest? I think you'll find we don't. |
||
} | ||
else if (this.props.startingQueryParams.client_secret && this.props.startingQueryParams.sid) { | ||
console.log("Not registering as guest; registration."); | ||
|
@@ -155,19 +181,19 @@ module.exports = React.createClass({ | |
|
||
_registerAsGuest: function() { | ||
var self = this; | ||
var config = this.props.config; | ||
console.log("Doing guest login on %s", config.default_hs_url); | ||
console.log("Doing guest login on %s", this.getCurrentHsUrl()); | ||
MatrixClientPeg.replaceUsingUrls( | ||
config.default_hs_url, config.default_is_url | ||
this.getCurrentHsUrl(), | ||
this.getCurrentIsUrl() | ||
); | ||
MatrixClientPeg.get().registerGuest().done(function(creds) { | ||
console.log("Registered as guest: %s", creds.user_id); | ||
self._setAutoRegisterAsGuest(false); | ||
self.onLoggedIn({ | ||
userId: creds.user_id, | ||
accessToken: creds.access_token, | ||
homeserverUrl: config.default_hs_url, | ||
identityServerUrl: config.default_is_url, | ||
homeserverUrl: self.getCurrentHsUrl(), | ||
identityServerUrl: self.getCurrentIsUrl(), | ||
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. I really don't like how this is structured :( - The figurative rug can easily be pulled from under you between the call to |
||
guest: true | ||
}); | ||
}, function(err) { | ||
|
@@ -188,7 +214,12 @@ module.exports = React.createClass({ | |
switch (payload.action) { | ||
case 'logout': | ||
if (window.localStorage) { | ||
// preserve our HS & IS URLs for convenience | ||
var hsUrl = this.getCurrentHsUrl(); | ||
var isUrl = this.getCurrentIsUrl(); | ||
window.localStorage.clear(); | ||
window.localStorage.setItem("mx_hs_url", hsUrl); | ||
window.localStorage.setItem("mx_is_url", isUrl); | ||
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. Tempted to inline this: The variable name isn't giving you any more information than the key name here. |
||
} | ||
Notifier.stop(); | ||
UserActivity.stop(); | ||
|
@@ -711,7 +742,7 @@ module.exports = React.createClass({ | |
} | ||
} | ||
else { | ||
console.error("Unknown screen : %s", screen); | ||
console.info("Ignoring showScreen for '%s'", screen); | ||
} | ||
}, | ||
|
||
|
@@ -875,6 +906,8 @@ module.exports = React.createClass({ | |
var NewVersionBar = sdk.getComponent('globals.NewVersionBar'); | ||
var ForgotPassword = sdk.getComponent('structures.login.ForgotPassword'); | ||
|
||
// work out the HS URL prompts we should show for | ||
|
||
// needs to be before normal PageTypes as you are logged in technically | ||
if (this.state.screen == 'post_registration') { | ||
return ( | ||
|
@@ -970,26 +1003,34 @@ module.exports = React.createClass({ | |
username={this.state.upgradeUsername} | ||
disableUsernameChanges={Boolean(this.state.upgradeUsername)} | ||
guestAccessToken={this.state.guestAccessToken} | ||
hsUrl={this.props.config.default_hs_url} | ||
isUrl={this.props.config.default_is_url} | ||
defaultHsUrl={this.props.config.default_hs_url} | ||
defaultIsUrl={this.props.config.default_is_url} | ||
initialHsUrl={this.getCurrentHsUrl()} | ||
initialIsUrl={this.getCurrentIsUrl()} | ||
registrationUrl={this.props.registrationUrl} | ||
onLoggedIn={this.onRegistered} | ||
onLoginClick={this.onLoginClick} /> | ||
onLoginClick={this.onLoginClick} | ||
onRegisterClick={this.onRegisterClick} /> | ||
); | ||
} else if (this.state.screen == 'forgot_password') { | ||
return ( | ||
<ForgotPassword | ||
homeserverUrl={this.props.config.default_hs_url} | ||
identityServerUrl={this.props.config.default_is_url} | ||
onComplete={this.onLoginClick} /> | ||
defaultHsUrl={this.props.config.default_hs_url} | ||
defaultIsUrl={this.props.config.default_is_url} | ||
initialHsUrl={this.getCurrentHsUrl()} | ||
initialIsUrl={this.getCurrentIsUrl()} | ||
onComplete={this.onLoginClick} | ||
onLoginClick={this.onLoginClick} /> | ||
); | ||
} else { | ||
return ( | ||
<Login | ||
onLoggedIn={this.onLoggedIn} | ||
onRegisterClick={this.onRegisterClick} | ||
homeserverUrl={this.props.config.default_hs_url} | ||
identityServerUrl={this.props.config.default_is_url} | ||
defaultHsUrl={this.props.config.default_hs_url} | ||
defaultIsUrl={this.props.config.default_is_url} | ||
initialHsUrl={this.getCurrentHsUrl()} | ||
initialIsUrl={this.getCurrentIsUrl()} | ||
onForgotPasswordClick={this.onForgotPasswordClick} | ||
onLoginAsGuestClick={this.props.enableGuest && this.props.config && this.props.config.default_hs_url ? this._registerAsGuest: undefined} | ||
/> | ||
|
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.
A wild space monster appears !