Merge pull request #881 from matrix-org/luke/user-settings-remove-current-password

Remove "Current Password" input if mx_pass exists
This commit is contained in:
Luke Barnard 2017-05-16 12:29:23 +01:00 committed by GitHub
commit c6350379dc
6 changed files with 145 additions and 35 deletions

View file

@ -23,6 +23,7 @@ import Notifier from '../../Notifier';
import PageTypes from '../../PageTypes';
import sdk from '../../index';
import dis from '../../dispatcher';
import sessionStore from '../../stores/SessionStore';
/**
* This is what our MatrixChat shows when we are logged in. The precise view is
@ -49,10 +50,6 @@ 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.
},
@ -80,10 +77,19 @@ export default React.createClass({
this._scrollStateMap = {};
document.addEventListener('keydown', this._onKeyDown);
this._sessionStore = sessionStore;
this._sessionStoreToken = this._sessionStore.addListener(
this._setStateFromSessionStore,
);
this._setStateFromSessionStore();
},
componentWillUnmount: function() {
document.removeEventListener('keydown', this._onKeyDown);
if (this._sessionStoreToken) {
this._sessionStoreToken.remove();
}
},
getScrollStateForRoom: function(roomId) {
@ -97,6 +103,12 @@ export default React.createClass({
return this.refs.roomView.canResetTimeline();
},
_setStateFromSessionStore() {
this.setState({
userHasGeneratedPassword: Boolean(this._sessionStore.getCachedPassword()),
});
},
_onKeyDown: function(ev) {
/*
// Remove this for now as ctrl+alt = alt-gr so this breaks keyboards which rely on alt-gr for numbers
@ -257,7 +269,7 @@ export default React.createClass({
/>;
} else if (this.props.matrixClient.isGuest()) {
topBar = <GuestWarningBar />;
} else if (this.props.userHasGeneratedPassword) {
} else if (this.state.userHasGeneratedPassword) {
topBar = <PasswordNagBar />;
} else if (Notifier.supportsDesktopNotifications() && !Notifier.isEnabled() && !Notifier.isToolbarHidden()) {
topBar = <MatrixToolbar />;

View file

@ -138,9 +138,6 @@ 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;
},
@ -785,15 +782,11 @@ module.exports = React.createClass({
/**
* Called when a new logged in session has started
*/
_onLoggedIn: function(teamToken, isPasswordStored) {
_onLoggedIn: function(teamToken) {
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) {
@ -1206,7 +1199,6 @@ module.exports = React.createClass({
onUserSettingsClose={this.onUserSettingsClose}
onRegistered={this.onRegistered}
teamToken={this._teamToken}
userHasGeneratedPassword={this.state.userHasGeneratedPassword}
{...this.props}
{...this.state}
/>

View file

@ -327,6 +327,7 @@ module.exports = React.createClass({
receive push notifications on other devices until you
log back in to them.`,
});
dis.dispatch({action: 'password_changed'});
},
onUpgradeClicked: function() {