Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Show password nag bar when user is PWLU #864

Merged
merged 1 commit into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export function setLoggedIn(credentials) {

// Resolves by default
let teamPromise = Promise.resolve(null);
let isPasswordStored = false;

// persist the session
if (localStorage) {
Expand All @@ -307,6 +308,7 @@ export function setLoggedIn(credentials) {
// is cached here such that the user can change it at a later time.
if (credentials.password) {
localStorage.setItem("mx_pass", credentials.password);
isPasswordStored = true;
}

console.log("Session persisted for %s", credentials.userId);
Expand All @@ -332,10 +334,10 @@ export function setLoggedIn(credentials) {
MatrixClientPeg.replaceUsingCreds(credentials);

teamPromise.then((teamToken) => {
dis.dispatch({action: 'on_logged_in', teamToken: teamToken});
dis.dispatch({action: 'on_logged_in', teamToken: teamToken, isPasswordStored});
}, (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();
Expand Down
13 changes: 9 additions & 4 deletions src/components/structures/LoggedInView.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export default React.createClass({

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.
},

Expand Down Expand Up @@ -177,6 +181,7 @@ export default React.createClass({
const MatrixToolbar = sdk.getComponent('globals.MatrixToolbar');
const GuestWarningBar = sdk.getComponent('globals.GuestWarningBar');
const NewVersionBar = sdk.getComponent('globals.NewVersionBar');
const PasswordNagBar = sdk.getComponent('globals.PasswordNagBar');

let page_element;
let right_panel = '';
Expand Down Expand Up @@ -250,11 +255,11 @@ export default React.createClass({
topBar = <NewVersionBar version={this.props.version} newVersion={this.props.newVersion}
releaseNotes={this.props.newVersionReleaseNotes}
/>;
}
else if (this.props.matrixClient.isGuest()) {
} else if (this.props.matrixClient.isGuest()) {
topBar = <GuestWarningBar />;
}
else if (Notifier.supportsDesktopNotifications() && !Notifier.isEnabled() && !Notifier.isToolbarHidden()) {
} else if (this.props.userHasGeneratedPassword) {
topBar = <PasswordNagBar />;
} else if (Notifier.supportsDesktopNotifications() && !Notifier.isEnabled() && !Notifier.isToolbarHidden()) {
topBar = <MatrixToolbar />;
}

Expand Down
12 changes: 10 additions & 2 deletions src/components/structures/MatrixChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ module.exports = React.createClass({
register_hs_url: null,
register_is_url: null,
register_id_sid: null,

// Initially, use localStorage as source of truth
userHasGeneratedPassword: localStorage && localStorage.getItem('mx_pass'),
};
return s;
},
Expand Down Expand Up @@ -569,7 +572,7 @@ module.exports = React.createClass({
this.setState({loggingIn: true});
break;
case 'on_logged_in':
this._onLoggedIn(payload.teamToken);
this._onLoggedIn(payload.teamToken, payload.isPasswordStored);
break;
case 'on_logged_out':
this._onLoggedOut();
Expand Down Expand Up @@ -755,11 +758,15 @@ module.exports = React.createClass({
/**
* Called when a new logged in session has started
*/
_onLoggedIn: function(teamToken) {
_onLoggedIn: function(teamToken, isPasswordStored) {
this.setState({
guestCreds: null,
loggedIn: true,
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) {
Expand Down Expand Up @@ -1168,6 +1175,7 @@ module.exports = React.createClass({
onUserSettingsClose={this.onUserSettingsClose}
onRegistered={this.onRegistered}
teamToken={this._teamToken}
userHasGeneratedPassword={this.state.userHasGeneratedPassword}
{...this.props}
{...this.state}
/>
Expand Down