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

Commit

Permalink
Only warn user when changing password in Settings if they have other …
Browse files Browse the repository at this point in the history
…devices
  • Loading branch information
hughns committed Apr 21, 2022
1 parent 853e0e9 commit 9038ea7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
23 changes: 15 additions & 8 deletions src/components/views/settings/ChangePassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ enum Phase {
}

interface IProps {
onFinished?: (outcome: { didSetEmail?: boolean, didLogoutAllDevices: boolean }) => void;
onFinished?: (outcome: {
didSetEmail?: boolean;
/** Was one or more other devices logged out whilst changing the password */
didLogoutOutOtherDevices: boolean;
}) => void;
onError?: (error: {error: string}) => void;
rowClassName?: string;
buttonClassName?: string;
Expand Down Expand Up @@ -87,9 +91,9 @@ export default class ChangePassword extends React.Component<IProps, IState> {

// if the server supports it then don't sign user out of all devices
const serverSupportsControlOfDevicesLogout = await cli.doesServerSupportLogoutDevices();
const logoutDevices = serverSupportsControlOfDevicesLogout ? false : undefined;
const userHasOtherDevices = (await cli.getDevices()).devices.length > 1;

if (!serverSupportsControlOfDevicesLogout && this.props.confirm) {
if (userHasOtherDevices && !serverSupportsControlOfDevicesLogout && this.props.confirm) {
// warn about logging out all devices
const { finished } = Modal.createTrackedDialog<[boolean]>('Change Password', '', QuestionDialog, {
title: _t("Warning!"),
Expand Down Expand Up @@ -124,14 +128,15 @@ export default class ChangePassword extends React.Component<IProps, IState> {
if (!confirmed) return;
}

this.changePassword(cli, oldPassword, newPassword, logoutDevices);
this.changePassword(cli, oldPassword, newPassword, serverSupportsControlOfDevicesLogout, userHasOtherDevices);
}

private changePassword(
cli: MatrixClient,
oldPassword: string,
newPassword: string,
logoutDevices: boolean | undefined,
serverSupportsControlOfDevicesLogout: boolean,
userHasOtherDevices: boolean,
): void {
const authDict = {
type: 'm.login.password',
Expand All @@ -149,19 +154,21 @@ export default class ChangePassword extends React.Component<IProps, IState> {
phase: Phase.Uploading,
});

const logoutDevices = serverSupportsControlOfDevicesLogout ? false : undefined;

// undefined or true mean all devices signed out
const didLogoutAllDevices = logoutDevices !== false;
const didLogoutOutOtherDevices = !serverSupportsControlOfDevicesLogout && userHasOtherDevices;

cli.setPassword(authDict, newPassword, logoutDevices).then(() => {
if (this.props.shouldAskForEmail) {
return this.optionallySetEmail().then((confirmed) => {
this.props.onFinished({
didSetEmail: confirmed,
didLogoutAllDevices,
didLogoutOutOtherDevices,
});
});
} else {
this.props.onFinished({ didLogoutAllDevices });
this.props.onFinished({ didLogoutOutOtherDevices });
}
}, (err) => {
this.props.onError(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ export default class GeneralUserSettingsTab extends React.Component<IProps, ISta
});
};

private onPasswordChanged = ({ didLogoutAllDevices }: { didLogoutAllDevices: boolean }): void => {
private onPasswordChanged = ({ didLogoutOutOtherDevices }: { didLogoutOutOtherDevices: boolean }): void => {
let description = _t("Your password was successfully changed.");
if (didLogoutAllDevices) {
if (didLogoutOutOtherDevices) {
description += " " + _t(
"You will not receive push notifications on other devices until you sign back in to them.",
);
Expand Down

0 comments on commit 9038ea7

Please sign in to comment.