Merge pull request #864 from matrix-org/luke/show-pwd-nag-bar

Show password nag bar when user is PWLU
pull/21833/head
Luke Barnard 2017-05-08 09:52:04 +01:00 committed by GitHub
commit 69382d36b1
3 changed files with 23 additions and 8 deletions

View File

@ -284,6 +284,7 @@ export function setLoggedIn(credentials) {
// Resolves by default // Resolves by default
let teamPromise = Promise.resolve(null); let teamPromise = Promise.resolve(null);
let isPasswordStored = false;
// persist the session // persist the session
if (localStorage) { if (localStorage) {
@ -307,6 +308,7 @@ export function setLoggedIn(credentials) {
// is cached here such that the user can change it at a later time. // is cached here such that the user can change it at a later time.
if (credentials.password) { if (credentials.password) {
localStorage.setItem("mx_pass", credentials.password); localStorage.setItem("mx_pass", credentials.password);
isPasswordStored = true;
} }
console.log("Session persisted for %s", credentials.userId); console.log("Session persisted for %s", credentials.userId);
@ -332,10 +334,10 @@ export function setLoggedIn(credentials) {
MatrixClientPeg.replaceUsingCreds(credentials); MatrixClientPeg.replaceUsingCreds(credentials);
teamPromise.then((teamToken) => { teamPromise.then((teamToken) => {
dis.dispatch({action: 'on_logged_in', teamToken: teamToken}); dis.dispatch({action: 'on_logged_in', teamToken: teamToken, isPasswordStored});
}, (err) => { }, (err) => {
console.warn("Failed to get team token on login", err); console.warn("Failed to get team token on login", err);
dis.dispatch({action: 'on_logged_in', teamToken: null}); dis.dispatch({action: 'on_logged_in', teamToken: null, isPasswordStored});
}); });
startMatrixClient(); startMatrixClient();

View File

@ -49,6 +49,10 @@ export default React.createClass({
teamToken: React.PropTypes.string, teamToken: React.PropTypes.string,
// Has the user generated a password that is stored in local storage?
// (are they a PWLU?)
userHasGeneratedPassword: React.PropTypes.boolean,
// and lots and lots of other stuff. // and lots and lots of other stuff.
}, },
@ -177,6 +181,7 @@ export default React.createClass({
const MatrixToolbar = sdk.getComponent('globals.MatrixToolbar'); const MatrixToolbar = sdk.getComponent('globals.MatrixToolbar');
const GuestWarningBar = sdk.getComponent('globals.GuestWarningBar'); const GuestWarningBar = sdk.getComponent('globals.GuestWarningBar');
const NewVersionBar = sdk.getComponent('globals.NewVersionBar'); const NewVersionBar = sdk.getComponent('globals.NewVersionBar');
const PasswordNagBar = sdk.getComponent('globals.PasswordNagBar');
let page_element; let page_element;
let right_panel = ''; let right_panel = '';
@ -250,11 +255,11 @@ export default React.createClass({
topBar = <NewVersionBar version={this.props.version} newVersion={this.props.newVersion} topBar = <NewVersionBar version={this.props.version} newVersion={this.props.newVersion}
releaseNotes={this.props.newVersionReleaseNotes} releaseNotes={this.props.newVersionReleaseNotes}
/>; />;
} } else if (this.props.matrixClient.isGuest()) {
else if (this.props.matrixClient.isGuest()) {
topBar = <GuestWarningBar />; topBar = <GuestWarningBar />;
} } else if (this.props.userHasGeneratedPassword) {
else if (Notifier.supportsDesktopNotifications() && !Notifier.isEnabled() && !Notifier.isToolbarHidden()) { topBar = <PasswordNagBar />;
} else if (Notifier.supportsDesktopNotifications() && !Notifier.isEnabled() && !Notifier.isToolbarHidden()) {
topBar = <MatrixToolbar />; topBar = <MatrixToolbar />;
} }

View File

@ -138,6 +138,9 @@ module.exports = React.createClass({
register_hs_url: null, register_hs_url: null,
register_is_url: null, register_is_url: null,
register_id_sid: null, register_id_sid: null,
// Initially, use localStorage as source of truth
userHasGeneratedPassword: localStorage && localStorage.getItem('mx_pass'),
}; };
return s; return s;
}, },
@ -569,7 +572,7 @@ module.exports = React.createClass({
this.setState({loggingIn: true}); this.setState({loggingIn: true});
break; break;
case 'on_logged_in': case 'on_logged_in':
this._onLoggedIn(payload.teamToken); this._onLoggedIn(payload.teamToken, payload.isPasswordStored);
break; break;
case 'on_logged_out': case 'on_logged_out':
this._onLoggedOut(); this._onLoggedOut();
@ -755,11 +758,15 @@ module.exports = React.createClass({
/** /**
* Called when a new logged in session has started * Called when a new logged in session has started
*/ */
_onLoggedIn: function(teamToken) { _onLoggedIn: function(teamToken, isPasswordStored) {
this.setState({ this.setState({
guestCreds: null, guestCreds: null,
loggedIn: true, loggedIn: true,
loggingIn: false, loggingIn: false,
// isPasswordStored only true when ROU sets a username and becomes PWLU.
// (the password was randomly generated and stored in localStorage).
userHasGeneratedPassword:
this.state.userHasGeneratedPassword || isPasswordStored,
}); });
if (teamToken) { if (teamToken) {
@ -1168,6 +1175,7 @@ module.exports = React.createClass({
onUserSettingsClose={this.onUserSettingsClose} onUserSettingsClose={this.onUserSettingsClose}
onRegistered={this.onRegistered} onRegistered={this.onRegistered}
teamToken={this._teamToken} teamToken={this._teamToken}
userHasGeneratedPassword={this.state.userHasGeneratedPassword}
{...this.props} {...this.props}
{...this.state} {...this.state}
/> />