Support Matrix 1.1 (drop legacy r0 versions) (#9819)
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
f9e79fd5d6
commit
180fcaa70f
32 changed files with 712 additions and 440 deletions
|
@ -100,30 +100,25 @@ export default class AddThreepid {
|
|||
*/
|
||||
public async bindEmailAddress(emailAddress: string): Promise<IRequestTokenResponse> {
|
||||
this.bind = true;
|
||||
if (await this.matrixClient.doesServerSupportSeparateAddAndBind()) {
|
||||
// For separate bind, request a token directly from the IS.
|
||||
const authClient = new IdentityAuthClient();
|
||||
const identityAccessToken = (await authClient.getAccessToken()) ?? undefined;
|
||||
try {
|
||||
const res = await this.matrixClient.requestEmailToken(
|
||||
emailAddress,
|
||||
this.clientSecret,
|
||||
1,
|
||||
undefined,
|
||||
identityAccessToken,
|
||||
);
|
||||
this.sessionId = res.sid;
|
||||
return res;
|
||||
} catch (err) {
|
||||
if (err instanceof MatrixError && err.errcode === "M_THREEPID_IN_USE") {
|
||||
throw new UserFriendlyError("This email address is already in use", { cause: err });
|
||||
}
|
||||
// Otherwise, just blurt out the same error
|
||||
throw err;
|
||||
// For separate bind, request a token directly from the IS.
|
||||
const authClient = new IdentityAuthClient();
|
||||
const identityAccessToken = (await authClient.getAccessToken()) ?? undefined;
|
||||
try {
|
||||
const res = await this.matrixClient.requestEmailToken(
|
||||
emailAddress,
|
||||
this.clientSecret,
|
||||
1,
|
||||
undefined,
|
||||
identityAccessToken,
|
||||
);
|
||||
this.sessionId = res.sid;
|
||||
return res;
|
||||
} catch (err) {
|
||||
if (err instanceof MatrixError && err.errcode === "M_THREEPID_IN_USE") {
|
||||
throw new UserFriendlyError("This email address is already in use", { cause: err });
|
||||
}
|
||||
} else {
|
||||
// For tangled bind, request a token via the HS.
|
||||
return this.addEmailAddress(emailAddress);
|
||||
// Otherwise, just blurt out the same error
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,31 +158,26 @@ export default class AddThreepid {
|
|||
*/
|
||||
public async bindMsisdn(phoneCountry: string, phoneNumber: string): Promise<IRequestMsisdnTokenResponse> {
|
||||
this.bind = true;
|
||||
if (await this.matrixClient.doesServerSupportSeparateAddAndBind()) {
|
||||
// For separate bind, request a token directly from the IS.
|
||||
const authClient = new IdentityAuthClient();
|
||||
const identityAccessToken = (await authClient.getAccessToken()) ?? undefined;
|
||||
try {
|
||||
const res = await this.matrixClient.requestMsisdnToken(
|
||||
phoneCountry,
|
||||
phoneNumber,
|
||||
this.clientSecret,
|
||||
1,
|
||||
undefined,
|
||||
identityAccessToken,
|
||||
);
|
||||
this.sessionId = res.sid;
|
||||
return res;
|
||||
} catch (err) {
|
||||
if (err instanceof MatrixError && err.errcode === "M_THREEPID_IN_USE") {
|
||||
throw new UserFriendlyError("This phone number is already in use", { cause: err });
|
||||
}
|
||||
// Otherwise, just blurt out the same error
|
||||
throw err;
|
||||
// For separate bind, request a token directly from the IS.
|
||||
const authClient = new IdentityAuthClient();
|
||||
const identityAccessToken = (await authClient.getAccessToken()) ?? undefined;
|
||||
try {
|
||||
const res = await this.matrixClient.requestMsisdnToken(
|
||||
phoneCountry,
|
||||
phoneNumber,
|
||||
this.clientSecret,
|
||||
1,
|
||||
undefined,
|
||||
identityAccessToken,
|
||||
);
|
||||
this.sessionId = res.sid;
|
||||
return res;
|
||||
} catch (err) {
|
||||
if (err instanceof MatrixError && err.errcode === "M_THREEPID_IN_USE") {
|
||||
throw new UserFriendlyError("This phone number is already in use", { cause: err });
|
||||
}
|
||||
} else {
|
||||
// For tangled bind, request a token via the HS.
|
||||
return this.addMsisdn(phoneCountry, phoneNumber);
|
||||
// Otherwise, just blurt out the same error
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,70 +189,59 @@ export default class AddThreepid {
|
|||
*/
|
||||
public async checkEmailLinkClicked(): Promise<[success?: boolean, result?: IAuthData | Error | null]> {
|
||||
try {
|
||||
if (await this.matrixClient.doesServerSupportSeparateAddAndBind()) {
|
||||
if (this.bind) {
|
||||
const authClient = new IdentityAuthClient();
|
||||
const identityAccessToken = await authClient.getAccessToken();
|
||||
if (!identityAccessToken) {
|
||||
throw new UserFriendlyError("No identity access token found");
|
||||
}
|
||||
await this.matrixClient.bindThreePid({
|
||||
sid: this.sessionId!,
|
||||
client_secret: this.clientSecret,
|
||||
id_server: getIdServerDomain(this.matrixClient),
|
||||
id_access_token: identityAccessToken,
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
await this.makeAddThreepidOnlyRequest();
|
||||
|
||||
// The spec has always required this to use UI auth but synapse briefly
|
||||
// implemented it without, so this may just succeed and that's OK.
|
||||
return [true];
|
||||
} catch (err) {
|
||||
if (!(err instanceof MatrixError) || err.httpStatus !== 401 || !err.data || !err.data.flows) {
|
||||
// doesn't look like an interactive-auth failure
|
||||
throw err;
|
||||
}
|
||||
|
||||
const dialogAesthetics = {
|
||||
[SSOAuthEntry.PHASE_PREAUTH]: {
|
||||
title: _t("Use Single Sign On to continue"),
|
||||
body: _t(
|
||||
"Confirm adding this email address by using Single Sign On to prove your identity.",
|
||||
),
|
||||
continueText: _t("Single Sign On"),
|
||||
continueKind: "primary",
|
||||
},
|
||||
[SSOAuthEntry.PHASE_POSTAUTH]: {
|
||||
title: _t("Confirm adding email"),
|
||||
body: _t("Click the button below to confirm adding this email address."),
|
||||
continueText: _t("Confirm"),
|
||||
continueKind: "primary",
|
||||
},
|
||||
};
|
||||
const { finished } = Modal.createDialog(InteractiveAuthDialog<{}>, {
|
||||
title: _t("Add Email Address"),
|
||||
matrixClient: this.matrixClient,
|
||||
authData: err.data,
|
||||
makeRequest: this.makeAddThreepidOnlyRequest,
|
||||
aestheticsForStagePhases: {
|
||||
[SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics,
|
||||
[SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics,
|
||||
},
|
||||
} as InteractiveAuthDialogProps<IAddThreePidOnlyBody>);
|
||||
return finished;
|
||||
}
|
||||
if (this.bind) {
|
||||
const authClient = new IdentityAuthClient();
|
||||
const identityAccessToken = await authClient.getAccessToken();
|
||||
if (!identityAccessToken) {
|
||||
throw new UserFriendlyError("No identity access token found");
|
||||
}
|
||||
await this.matrixClient.bindThreePid({
|
||||
sid: this.sessionId!,
|
||||
client_secret: this.clientSecret,
|
||||
id_server: getIdServerDomain(this.matrixClient),
|
||||
id_access_token: identityAccessToken,
|
||||
});
|
||||
} else {
|
||||
await this.matrixClient.addThreePid(
|
||||
{
|
||||
sid: this.sessionId!,
|
||||
client_secret: this.clientSecret,
|
||||
id_server: getIdServerDomain(this.matrixClient),
|
||||
},
|
||||
this.bind,
|
||||
);
|
||||
try {
|
||||
await this.makeAddThreepidOnlyRequest();
|
||||
|
||||
// The spec has always required this to use UI auth but synapse briefly
|
||||
// implemented it without, so this may just succeed and that's OK.
|
||||
return [true];
|
||||
} catch (err) {
|
||||
if (!(err instanceof MatrixError) || err.httpStatus !== 401 || !err.data || !err.data.flows) {
|
||||
// doesn't look like an interactive-auth failure
|
||||
throw err;
|
||||
}
|
||||
|
||||
const dialogAesthetics = {
|
||||
[SSOAuthEntry.PHASE_PREAUTH]: {
|
||||
title: _t("Use Single Sign On to continue"),
|
||||
body: _t(
|
||||
"Confirm adding this email address by using Single Sign On to prove your identity.",
|
||||
),
|
||||
continueText: _t("Single Sign On"),
|
||||
continueKind: "primary",
|
||||
},
|
||||
[SSOAuthEntry.PHASE_POSTAUTH]: {
|
||||
title: _t("Confirm adding email"),
|
||||
body: _t("Click the button below to confirm adding this email address."),
|
||||
continueText: _t("Confirm"),
|
||||
continueKind: "primary",
|
||||
},
|
||||
};
|
||||
const { finished } = Modal.createDialog(InteractiveAuthDialog<{}>, {
|
||||
title: _t("Add Email Address"),
|
||||
matrixClient: this.matrixClient,
|
||||
authData: err.data,
|
||||
makeRequest: this.makeAddThreepidOnlyRequest,
|
||||
aestheticsForStagePhases: {
|
||||
[SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics,
|
||||
[SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics,
|
||||
},
|
||||
} as InteractiveAuthDialogProps<IAddThreePidOnlyBody>);
|
||||
return finished;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (err instanceof HTTPError && err.httpStatus === 401) {
|
||||
|
@ -301,7 +280,6 @@ export default class AddThreepid {
|
|||
msisdnToken: string,
|
||||
): Promise<[success?: boolean, result?: IAuthData | Error | null] | undefined> {
|
||||
const authClient = new IdentityAuthClient();
|
||||
const supportsSeparateAddAndBind = await this.matrixClient.doesServerSupportSeparateAddAndBind();
|
||||
|
||||
let result: { success: boolean } | MatrixError;
|
||||
if (this.submitUrl) {
|
||||
|
@ -311,7 +289,7 @@ export default class AddThreepid {
|
|||
this.clientSecret,
|
||||
msisdnToken,
|
||||
);
|
||||
} else if (this.bind || !supportsSeparateAddAndBind) {
|
||||
} else if (this.bind) {
|
||||
result = await this.matrixClient.submitMsisdnToken(
|
||||
this.sessionId!,
|
||||
this.clientSecret,
|
||||
|
@ -325,65 +303,52 @@ export default class AddThreepid {
|
|||
throw result;
|
||||
}
|
||||
|
||||
if (supportsSeparateAddAndBind) {
|
||||
if (this.bind) {
|
||||
await this.matrixClient.bindThreePid({
|
||||
sid: this.sessionId!,
|
||||
client_secret: this.clientSecret,
|
||||
id_server: getIdServerDomain(this.matrixClient),
|
||||
id_access_token: await authClient.getAccessToken(),
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
await this.makeAddThreepidOnlyRequest();
|
||||
|
||||
// The spec has always required this to use UI auth but synapse briefly
|
||||
// implemented it without, so this may just succeed and that's OK.
|
||||
return;
|
||||
} catch (err) {
|
||||
if (!(err instanceof MatrixError) || err.httpStatus !== 401 || !err.data || !err.data.flows) {
|
||||
// doesn't look like an interactive-auth failure
|
||||
throw err;
|
||||
}
|
||||
|
||||
const dialogAesthetics = {
|
||||
[SSOAuthEntry.PHASE_PREAUTH]: {
|
||||
title: _t("Use Single Sign On to continue"),
|
||||
body: _t(
|
||||
"Confirm adding this phone number by using Single Sign On to prove your identity.",
|
||||
),
|
||||
continueText: _t("Single Sign On"),
|
||||
continueKind: "primary",
|
||||
},
|
||||
[SSOAuthEntry.PHASE_POSTAUTH]: {
|
||||
title: _t("Confirm adding phone number"),
|
||||
body: _t("Click the button below to confirm adding this phone number."),
|
||||
continueText: _t("Confirm"),
|
||||
continueKind: "primary",
|
||||
},
|
||||
};
|
||||
const { finished } = Modal.createDialog(InteractiveAuthDialog<{}>, {
|
||||
title: _t("Add Phone Number"),
|
||||
matrixClient: this.matrixClient,
|
||||
authData: err.data,
|
||||
makeRequest: this.makeAddThreepidOnlyRequest,
|
||||
aestheticsForStagePhases: {
|
||||
[SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics,
|
||||
[SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics,
|
||||
},
|
||||
} as InteractiveAuthDialogProps<IAddThreePidOnlyBody>);
|
||||
return finished;
|
||||
}
|
||||
}
|
||||
if (this.bind) {
|
||||
await this.matrixClient.bindThreePid({
|
||||
sid: this.sessionId!,
|
||||
client_secret: this.clientSecret,
|
||||
id_server: getIdServerDomain(this.matrixClient),
|
||||
id_access_token: await authClient.getAccessToken(),
|
||||
});
|
||||
} else {
|
||||
await this.matrixClient.addThreePid(
|
||||
{
|
||||
sid: this.sessionId!,
|
||||
client_secret: this.clientSecret,
|
||||
id_server: getIdServerDomain(this.matrixClient),
|
||||
},
|
||||
this.bind,
|
||||
);
|
||||
try {
|
||||
await this.makeAddThreepidOnlyRequest();
|
||||
|
||||
// The spec has always required this to use UI auth but synapse briefly
|
||||
// implemented it without, so this may just succeed and that's OK.
|
||||
return;
|
||||
} catch (err) {
|
||||
if (!(err instanceof MatrixError) || err.httpStatus !== 401 || !err.data || !err.data.flows) {
|
||||
// doesn't look like an interactive-auth failure
|
||||
throw err;
|
||||
}
|
||||
|
||||
const dialogAesthetics = {
|
||||
[SSOAuthEntry.PHASE_PREAUTH]: {
|
||||
title: _t("Use Single Sign On to continue"),
|
||||
body: _t("Confirm adding this phone number by using Single Sign On to prove your identity."),
|
||||
continueText: _t("Single Sign On"),
|
||||
continueKind: "primary",
|
||||
},
|
||||
[SSOAuthEntry.PHASE_POSTAUTH]: {
|
||||
title: _t("Confirm adding phone number"),
|
||||
body: _t("Click the button below to confirm adding this phone number."),
|
||||
continueText: _t("Confirm"),
|
||||
continueKind: "primary",
|
||||
},
|
||||
};
|
||||
const { finished } = Modal.createDialog(InteractiveAuthDialog<{}>, {
|
||||
title: _t("Add Phone Number"),
|
||||
matrixClient: this.matrixClient,
|
||||
authData: err.data,
|
||||
makeRequest: this.makeAddThreepidOnlyRequest,
|
||||
aestheticsForStagePhases: {
|
||||
[SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics,
|
||||
[SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics,
|
||||
},
|
||||
} as InteractiveAuthDialogProps<IAddThreePidOnlyBody>);
|
||||
return finished;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import { decryptAES, encryptAES, IEncryptedPayload } from "matrix-js-sdk/src/cry
|
|||
import { QueryDict } from "matrix-js-sdk/src/utils";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { SSOAction } from "matrix-js-sdk/src/@types/auth";
|
||||
import { MINIMUM_MATRIX_VERSION } from "matrix-js-sdk/src/version-support";
|
||||
|
||||
import { IMatrixClientCreds, MatrixClientPeg } from "./MatrixClientPeg";
|
||||
import SecurityCustomisations from "./customisations/Security";
|
||||
|
@ -66,6 +67,7 @@ import { SdkContextClass } from "./contexts/SDKContext";
|
|||
import { messageForLoginError } from "./utils/ErrorUtils";
|
||||
import { completeOidcLogin } from "./utils/oidc/authorize";
|
||||
import { persistOidcAuthenticatedSettings } from "./utils/oidc/persistOidcSettings";
|
||||
import GenericToast from "./components/views/toasts/GenericToast";
|
||||
|
||||
const HOMESERVER_URL_KEY = "mx_hs_url";
|
||||
const ID_SERVER_URL_KEY = "mx_is_url";
|
||||
|
@ -584,6 +586,7 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
|
|||
},
|
||||
false,
|
||||
);
|
||||
checkServerVersions();
|
||||
return true;
|
||||
} else {
|
||||
logger.log("No previous session found.");
|
||||
|
@ -591,6 +594,35 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
|
|||
}
|
||||
}
|
||||
|
||||
async function checkServerVersions(): Promise<void> {
|
||||
MatrixClientPeg.get()
|
||||
?.getVersions()
|
||||
.then((response) => {
|
||||
if (!response.versions.includes(MINIMUM_MATRIX_VERSION)) {
|
||||
const toastKey = "LEGACY_SERVER";
|
||||
ToastStore.sharedInstance().addOrReplaceToast({
|
||||
key: toastKey,
|
||||
title: _t("Your server is unsupported"),
|
||||
props: {
|
||||
description: _t(
|
||||
"This server is using an older version of Matrix. Upgrade to Matrix %(version)s to use %(brand)s without errors.",
|
||||
{
|
||||
version: MINIMUM_MATRIX_VERSION,
|
||||
brand: SdkConfig.get().brand,
|
||||
},
|
||||
),
|
||||
acceptLabel: _t("OK"),
|
||||
onAccept: () => {
|
||||
ToastStore.sharedInstance().dismissToast(toastKey);
|
||||
},
|
||||
},
|
||||
component: GenericToast,
|
||||
priority: 98,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function handleLoadSessionFailure(e: unknown): Promise<boolean> {
|
||||
logger.error("Unable to load session", e);
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ limitations under the License.
|
|||
|
||||
import React, { ReactNode } from "react";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { createClient } from "matrix-js-sdk/src/matrix";
|
||||
import { sleep } from "matrix-js-sdk/src/utils";
|
||||
|
||||
import { _t, _td } from "../../../languageHandler";
|
||||
|
@ -81,7 +80,6 @@ interface State {
|
|||
serverIsAlive: boolean;
|
||||
serverDeadError: string;
|
||||
|
||||
serverSupportsControlOfDevicesLogout: boolean;
|
||||
logoutDevices: boolean;
|
||||
}
|
||||
|
||||
|
@ -104,16 +102,11 @@ export default class ForgotPassword extends React.Component<Props, State> {
|
|||
// be seeing.
|
||||
serverIsAlive: true,
|
||||
serverDeadError: "",
|
||||
serverSupportsControlOfDevicesLogout: false,
|
||||
logoutDevices: false,
|
||||
};
|
||||
this.reset = new PasswordReset(this.props.serverConfig.hsUrl, this.props.serverConfig.isUrl);
|
||||
}
|
||||
|
||||
public componentDidMount(): void {
|
||||
this.checkServerCapabilities(this.props.serverConfig);
|
||||
}
|
||||
|
||||
public componentDidUpdate(prevProps: Readonly<Props>): void {
|
||||
if (
|
||||
prevProps.serverConfig.hsUrl !== this.props.serverConfig.hsUrl ||
|
||||
|
@ -121,9 +114,6 @@ export default class ForgotPassword extends React.Component<Props, State> {
|
|||
) {
|
||||
// Do a liveliness check on the new URLs
|
||||
this.checkServerLiveliness(this.props.serverConfig);
|
||||
|
||||
// Do capabilities check on new URLs
|
||||
this.checkServerCapabilities(this.props.serverConfig);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,19 +136,6 @@ export default class ForgotPassword extends React.Component<Props, State> {
|
|||
}
|
||||
}
|
||||
|
||||
private async checkServerCapabilities(serverConfig: ValidatedServerConfig): Promise<void> {
|
||||
const tempClient = createClient({
|
||||
baseUrl: serverConfig.hsUrl,
|
||||
});
|
||||
|
||||
const serverSupportsControlOfDevicesLogout = await tempClient.doesServerSupportLogoutDevices();
|
||||
|
||||
this.setState({
|
||||
logoutDevices: !serverSupportsControlOfDevicesLogout,
|
||||
serverSupportsControlOfDevicesLogout,
|
||||
});
|
||||
}
|
||||
|
||||
private async onPhaseEmailInputSubmit(): Promise<void> {
|
||||
this.phase = Phase.SendingEmail;
|
||||
|
||||
|
@ -376,16 +353,10 @@ export default class ForgotPassword extends React.Component<Props, State> {
|
|||
description: (
|
||||
<div>
|
||||
<p>
|
||||
{!this.state.serverSupportsControlOfDevicesLogout
|
||||
? _t(
|
||||
"Resetting your password on this homeserver will cause all of your devices to be " +
|
||||
"signed out. This will delete the message encryption keys stored on them, " +
|
||||
"making encrypted chat history unreadable.",
|
||||
)
|
||||
: _t(
|
||||
"Signing out your devices will delete the message encryption keys stored on them, " +
|
||||
"making encrypted chat history unreadable.",
|
||||
)}
|
||||
{_t(
|
||||
"Signing out your devices will delete the message encryption keys stored on them, " +
|
||||
"making encrypted chat history unreadable.",
|
||||
)}
|
||||
</p>
|
||||
<p>
|
||||
{_t(
|
||||
|
@ -446,16 +417,14 @@ export default class ForgotPassword extends React.Component<Props, State> {
|
|||
autoComplete="new-password"
|
||||
/>
|
||||
</div>
|
||||
{this.state.serverSupportsControlOfDevicesLogout ? (
|
||||
<div className="mx_AuthBody_fieldRow">
|
||||
<StyledCheckbox
|
||||
onChange={() => this.setState({ logoutDevices: !this.state.logoutDevices })}
|
||||
checked={this.state.logoutDevices}
|
||||
>
|
||||
{_t("Sign out of all devices")}
|
||||
</StyledCheckbox>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="mx_AuthBody_fieldRow">
|
||||
<StyledCheckbox
|
||||
onChange={() => this.setState({ logoutDevices: !this.state.logoutDevices })}
|
||||
checked={this.state.logoutDevices}
|
||||
>
|
||||
{_t("Sign out of all devices")}
|
||||
</StyledCheckbox>
|
||||
</div>
|
||||
{this.state.errorText && <ErrorMessage message={this.state.errorText} />}
|
||||
<button type="submit" className="mx_Login_submit">
|
||||
{submitButtonChild}
|
||||
|
|
|
@ -18,7 +18,6 @@ limitations under the License.
|
|||
import React from "react";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import type ExportE2eKeysDialog from "../../../async-components/views/dialogs/security/ExportE2eKeysDialog";
|
||||
import Field from "../elements/Field";
|
||||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||
import AccessibleButton from "../elements/AccessibleButton";
|
||||
|
@ -29,7 +28,6 @@ import Modal from "../../../Modal";
|
|||
import PassphraseField from "../auth/PassphraseField";
|
||||
import { PASSWORD_MIN_SCORE } from "../auth/RegistrationForm";
|
||||
import SetEmailDialog from "../dialogs/SetEmailDialog";
|
||||
import QuestionDialog from "../dialogs/QuestionDialog";
|
||||
|
||||
const FIELD_OLD_PASSWORD = "field_old_password";
|
||||
const FIELD_NEW_PASSWORD = "field_new_password";
|
||||
|
@ -43,11 +41,7 @@ enum Phase {
|
|||
}
|
||||
|
||||
interface IProps {
|
||||
onFinished: (outcome: {
|
||||
didSetEmail?: boolean;
|
||||
/** Was one or more other devices logged out whilst changing the password */
|
||||
didLogoutOutOtherDevices: boolean;
|
||||
}) => void;
|
||||
onFinished: (outcome: { didSetEmail?: boolean }) => void;
|
||||
onError: (error: Error) => void;
|
||||
rowClassName?: string;
|
||||
buttonClassName?: string;
|
||||
|
@ -95,58 +89,10 @@ export default class ChangePassword extends React.Component<IProps, IState> {
|
|||
private async onChangePassword(oldPassword: string, newPassword: string): Promise<void> {
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
|
||||
// if the server supports it then don't sign user out of all devices
|
||||
const serverSupportsControlOfDevicesLogout = await cli.doesServerSupportLogoutDevices();
|
||||
const userHasOtherDevices = (await cli.getDevices()).devices.length > 1;
|
||||
|
||||
if (userHasOtherDevices && !serverSupportsControlOfDevicesLogout && this.props.confirm) {
|
||||
// warn about logging out all devices
|
||||
const { finished } = Modal.createDialog(QuestionDialog, {
|
||||
title: _t("Warning!"),
|
||||
description: (
|
||||
<div>
|
||||
<p>
|
||||
{_t(
|
||||
"Changing your password on this homeserver will cause all of your other devices to be " +
|
||||
"signed out. This will delete the message encryption keys stored on them, and may make " +
|
||||
"encrypted chat history unreadable.",
|
||||
)}
|
||||
</p>
|
||||
<p>
|
||||
{_t(
|
||||
"If you want to retain access to your chat history in encrypted rooms you should first " +
|
||||
"export your room keys and re-import them afterwards.",
|
||||
)}
|
||||
</p>
|
||||
<p>
|
||||
{_t(
|
||||
"You can also ask your homeserver admin to upgrade the server to change this behaviour.",
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
),
|
||||
button: _t("Continue"),
|
||||
extraButtons: [
|
||||
<button key="exportRoomKeys" className="mx_Dialog_primary" onClick={this.onExportE2eKeysClicked}>
|
||||
{_t("Export E2E room keys")}
|
||||
</button>,
|
||||
],
|
||||
});
|
||||
|
||||
const [confirmed] = await finished;
|
||||
if (!confirmed) return;
|
||||
}
|
||||
|
||||
this.changePassword(cli, oldPassword, newPassword, serverSupportsControlOfDevicesLogout, userHasOtherDevices);
|
||||
this.changePassword(cli, oldPassword, newPassword);
|
||||
}
|
||||
|
||||
private changePassword(
|
||||
cli: MatrixClient,
|
||||
oldPassword: string,
|
||||
newPassword: string,
|
||||
serverSupportsControlOfDevicesLogout: boolean,
|
||||
userHasOtherDevices: boolean,
|
||||
): void {
|
||||
private changePassword(cli: MatrixClient, oldPassword: string, newPassword: string): void {
|
||||
const authDict = {
|
||||
type: "m.login.password",
|
||||
identifier: {
|
||||
|
@ -163,23 +109,17 @@ 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 didLogoutOutOtherDevices = !serverSupportsControlOfDevicesLogout && userHasOtherDevices;
|
||||
|
||||
cli.setPassword(authDict, newPassword, logoutDevices)
|
||||
cli.setPassword(authDict, newPassword, false)
|
||||
.then(
|
||||
() => {
|
||||
if (this.props.shouldAskForEmail) {
|
||||
return this.optionallySetEmail().then((confirmed) => {
|
||||
this.props.onFinished({
|
||||
didSetEmail: confirmed,
|
||||
didLogoutOutOtherDevices,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.props.onFinished({ didLogoutOutOtherDevices });
|
||||
this.props.onFinished({});
|
||||
}
|
||||
},
|
||||
(err) => {
|
||||
|
@ -229,17 +169,6 @@ export default class ChangePassword extends React.Component<IProps, IState> {
|
|||
return modal.finished.then(([confirmed]) => !!confirmed);
|
||||
}
|
||||
|
||||
private onExportE2eKeysClicked = (): void => {
|
||||
Modal.createDialogAsync(
|
||||
import("../../../async-components/views/dialogs/security/ExportE2eKeysDialog") as unknown as Promise<
|
||||
typeof ExportE2eKeysDialog
|
||||
>,
|
||||
{
|
||||
matrixClient: MatrixClientPeg.safeGet(),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
private markFieldValid(fieldID: FieldType, valid?: boolean): void {
|
||||
const { fieldValid } = this.state;
|
||||
fieldValid[fieldID] = valid;
|
||||
|
|
|
@ -210,7 +210,7 @@ export default class PhoneNumbers extends React.Component<IProps, IState> {
|
|||
?.haveMsisdnToken(token)
|
||||
.then(([finished] = []) => {
|
||||
let newPhoneNumber = this.state.newPhoneNumber;
|
||||
if (finished) {
|
||||
if (finished !== false) {
|
||||
const msisdns = [...this.props.msisdns, { address, medium: ThreepidMedium.Phone }];
|
||||
this.props.onMsisdnsChange(msisdns);
|
||||
newPhoneNumber = "";
|
||||
|
|
|
@ -77,10 +77,6 @@ export class EmailAddress extends React.Component<IEmailAddressProps, IEmailAddr
|
|||
}
|
||||
|
||||
private async changeBinding({ bind, label, errorTitle }: Binding): Promise<void> {
|
||||
if (!(await MatrixClientPeg.safeGet().doesServerSupportSeparateAddAndBind())) {
|
||||
return this.changeBindingTangledAddBind({ bind, label, errorTitle });
|
||||
}
|
||||
|
||||
const { medium, address } = this.props.email;
|
||||
|
||||
try {
|
||||
|
@ -113,41 +109,6 @@ export class EmailAddress extends React.Component<IEmailAddressProps, IEmailAddr
|
|||
}
|
||||
}
|
||||
|
||||
private async changeBindingTangledAddBind({ bind, label, errorTitle }: Binding): Promise<void> {
|
||||
const { medium, address } = this.props.email;
|
||||
|
||||
const task = new AddThreepid(MatrixClientPeg.safeGet());
|
||||
this.setState({
|
||||
verifying: true,
|
||||
continueDisabled: true,
|
||||
addTask: task,
|
||||
});
|
||||
|
||||
try {
|
||||
await MatrixClientPeg.safeGet().deleteThreePid(medium, address);
|
||||
if (bind) {
|
||||
await task.bindEmailAddress(address);
|
||||
} else {
|
||||
await task.addEmailAddress(address);
|
||||
}
|
||||
this.setState({
|
||||
continueDisabled: false,
|
||||
bound: bind,
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error(`changeBindingTangledAddBind: Unable to ${label} email address ${address}`, err);
|
||||
this.setState({
|
||||
verifying: false,
|
||||
continueDisabled: false,
|
||||
addTask: null,
|
||||
});
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: errorTitle,
|
||||
description: extractErrorMessageFromError(err, _t("Operation failed")),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private onRevokeClick = (e: ButtonEvent): void => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
|
|
@ -73,10 +73,6 @@ export class PhoneNumber extends React.Component<IPhoneNumberProps, IPhoneNumber
|
|||
}
|
||||
|
||||
private async changeBinding({ bind, label, errorTitle }: Binding): Promise<void> {
|
||||
if (!(await MatrixClientPeg.safeGet().doesServerSupportSeparateAddAndBind())) {
|
||||
return this.changeBindingTangledAddBind({ bind, label, errorTitle });
|
||||
}
|
||||
|
||||
const { medium, address } = this.props.msisdn;
|
||||
|
||||
try {
|
||||
|
@ -114,47 +110,6 @@ export class PhoneNumber extends React.Component<IPhoneNumberProps, IPhoneNumber
|
|||
}
|
||||
}
|
||||
|
||||
private async changeBindingTangledAddBind({ bind, label, errorTitle }: Binding): Promise<void> {
|
||||
const { medium, address } = this.props.msisdn;
|
||||
|
||||
const task = new AddThreepid(MatrixClientPeg.safeGet());
|
||||
this.setState({
|
||||
verifying: true,
|
||||
continueDisabled: true,
|
||||
addTask: task,
|
||||
});
|
||||
|
||||
try {
|
||||
await MatrixClientPeg.safeGet().deleteThreePid(medium, address);
|
||||
// XXX: Sydent will accept a number without country code if you add
|
||||
// a leading plus sign to a number in E.164 format (which the 3PID
|
||||
// address is), but this goes against the spec.
|
||||
// See https://github.com/matrix-org/matrix-doc/issues/2222
|
||||
if (bind) {
|
||||
// @ts-ignore
|
||||
await task.bindMsisdn(null, `+${address}`);
|
||||
} else {
|
||||
// @ts-ignore
|
||||
await task.addMsisdn(null, `+${address}`);
|
||||
}
|
||||
this.setState({
|
||||
continueDisabled: false,
|
||||
bound: bind,
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error(`changeBindingTangledAddBind: Unable to ${label} phone number ${address}`, err);
|
||||
this.setState({
|
||||
verifying: false,
|
||||
continueDisabled: false,
|
||||
addTask: null,
|
||||
});
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: errorTitle,
|
||||
description: extractErrorMessageFromError(err, _t("Operation failed")),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private onRevokeClick = (e: ButtonEvent): void => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
|
|
@ -37,7 +37,6 @@ import { Service, ServicePolicyPair, startTermsFlow } from "../../../../../Terms
|
|||
import IdentityAuthClient from "../../../../../IdentityAuthClient";
|
||||
import { abbreviateUrl } from "../../../../../utils/UrlUtils";
|
||||
import { getThreepidsWithBindStatus } from "../../../../../boundThreepids";
|
||||
import Spinner from "../../../elements/Spinner";
|
||||
import { SettingLevel } from "../../../../../settings/SettingLevel";
|
||||
import { UIFeature } from "../../../../../settings/UIFeature";
|
||||
import { ActionPayload } from "../../../../../dispatcher/payloads";
|
||||
|
@ -70,7 +69,6 @@ interface IState {
|
|||
spellCheckEnabled?: boolean;
|
||||
spellCheckLanguages: string[];
|
||||
haveIdServer: boolean;
|
||||
serverSupportsSeparateAddAndBind?: boolean;
|
||||
idServerHasUnsignedTerms: boolean;
|
||||
requiredPolicyInfo:
|
||||
| {
|
||||
|
@ -166,8 +164,6 @@ export default class GeneralUserSettingsTab extends React.Component<IProps, ISta
|
|||
private async getCapabilities(): Promise<void> {
|
||||
const cli = this.context;
|
||||
|
||||
const serverSupportsSeparateAddAndBind = await cli.doesServerSupportSeparateAddAndBind();
|
||||
|
||||
const capabilities = await cli.getCapabilities(); // this is cached
|
||||
const changePasswordCap = capabilities["m.change_password"];
|
||||
|
||||
|
@ -179,7 +175,7 @@ export default class GeneralUserSettingsTab extends React.Component<IProps, ISta
|
|||
const delegatedAuthConfig = M_AUTHENTICATION.findIn<IDelegatedAuthConfig | undefined>(cli.getClientWellKnown());
|
||||
const externalAccountManagementUrl = delegatedAuthConfig?.account;
|
||||
|
||||
this.setState({ serverSupportsSeparateAddAndBind, canChangePassword, externalAccountManagementUrl });
|
||||
this.setState({ canChangePassword, externalAccountManagementUrl });
|
||||
}
|
||||
|
||||
private async getThreepidState(): Promise<void> {
|
||||
|
@ -303,12 +299,8 @@ export default class GeneralUserSettingsTab extends React.Component<IProps, ISta
|
|||
});
|
||||
};
|
||||
|
||||
private onPasswordChanged = ({ didLogoutOutOtherDevices }: { didLogoutOutOtherDevices: boolean }): void => {
|
||||
let description = _t("Your password was successfully changed.");
|
||||
if (didLogoutOutOtherDevices) {
|
||||
description +=
|
||||
" " + _t("You will not receive push notifications on other devices until you sign back in to them.");
|
||||
}
|
||||
private onPasswordChanged = (): void => {
|
||||
const description = _t("Your password was successfully changed.");
|
||||
// TODO: Figure out a design that doesn't involve replacing the current dialog
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: _t("Success"),
|
||||
|
@ -327,15 +319,7 @@ export default class GeneralUserSettingsTab extends React.Component<IProps, ISta
|
|||
private renderAccountSection(): JSX.Element {
|
||||
let threepidSection: ReactNode = null;
|
||||
|
||||
// For older homeservers without separate 3PID add and bind methods (MSC2290),
|
||||
// we use a combo add with bind option API which requires an identity server to
|
||||
// validate 3PID ownership even if we're just adding to the homeserver only.
|
||||
// For newer homeservers with separate 3PID add and bind methods (MSC2290),
|
||||
// there is no such concern, so we can always show the HS account 3PIDs.
|
||||
if (
|
||||
SettingsStore.getValue(UIFeature.ThirdPartyID) &&
|
||||
(this.state.haveIdServer || this.state.serverSupportsSeparateAddAndBind === true)
|
||||
) {
|
||||
if (SettingsStore.getValue(UIFeature.ThirdPartyID)) {
|
||||
const emails = this.state.loading3pids ? (
|
||||
<InlineSpinner />
|
||||
) : (
|
||||
|
@ -365,8 +349,6 @@ export default class GeneralUserSettingsTab extends React.Component<IProps, ISta
|
|||
</SettingsSubsection>
|
||||
</>
|
||||
);
|
||||
} else if (this.state.serverSupportsSeparateAddAndBind === null) {
|
||||
threepidSection = <Spinner />;
|
||||
}
|
||||
|
||||
let passwordChangeSection: ReactNode = null;
|
||||
|
|
|
@ -105,6 +105,8 @@
|
|||
"We asked the browser to remember which homeserver you use to let you sign in, but unfortunately your browser has forgotten it. Go to the sign in page and try again.": "We asked the browser to remember which homeserver you use to let you sign in, but unfortunately your browser has forgotten it. Go to the sign in page and try again.",
|
||||
"We couldn't log you in": "We couldn't log you in",
|
||||
"Try again": "Try again",
|
||||
"Your server is unsupported": "Your server is unsupported",
|
||||
"This server is using an older version of Matrix. Upgrade to Matrix %(version)s to use %(brand)s without errors.": "This server is using an older version of Matrix. Upgrade to Matrix %(version)s to use %(brand)s without errors.",
|
||||
"User is not logged in": "User is not logged in",
|
||||
"Database unexpectedly closed": "Database unexpectedly closed",
|
||||
"This may be caused by having the app open in multiple tabs or due to clearing browser data.": "This may be caused by having the app open in multiple tabs or due to clearing browser data.",
|
||||
|
@ -690,6 +692,7 @@
|
|||
"No homeserver URL provided": "No homeserver URL provided",
|
||||
"Unexpected error resolving homeserver configuration": "Unexpected error resolving homeserver configuration",
|
||||
"Unexpected error resolving identity server configuration": "Unexpected error resolving identity server configuration",
|
||||
"Your homeserver is too old and does not support the minimum API version required. Please contact your server owner, or upgrade your server.": "Your homeserver is too old and does not support the minimum API version required. Please contact your server owner, or upgrade your server.",
|
||||
"This homeserver has hit its Monthly Active User limit.": "This homeserver has hit its Monthly Active User limit.",
|
||||
"This homeserver has been blocked by its administrator.": "This homeserver has been blocked by its administrator.",
|
||||
"This homeserver has exceeded one of its resource limits.": "This homeserver has exceeded one of its resource limits.",
|
||||
|
@ -1354,11 +1357,6 @@
|
|||
"Workspace: <networkLink/>": "Workspace: <networkLink/>",
|
||||
"Channel: <channelLink/>": "Channel: <channelLink/>",
|
||||
"No display name": "No display name",
|
||||
"Warning!": "Warning!",
|
||||
"Changing your password on this homeserver will cause all of your other devices to be signed out. This will delete the message encryption keys stored on them, and may make encrypted chat history unreadable.": "Changing your password on this homeserver will cause all of your other devices to be signed out. This will delete the message encryption keys stored on them, and may make encrypted chat history unreadable.",
|
||||
"If you want to retain access to your chat history in encrypted rooms you should first export your room keys and re-import them afterwards.": "If you want to retain access to your chat history in encrypted rooms you should first export your room keys and re-import them afterwards.",
|
||||
"You can also ask your homeserver admin to upgrade the server to change this behaviour.": "You can also ask your homeserver admin to upgrade the server to change this behaviour.",
|
||||
"Export E2E room keys": "Export E2E room keys",
|
||||
"Error while changing password: %(error)s": "Error while changing password: %(error)s",
|
||||
"New passwords don't match": "New passwords don't match",
|
||||
"Passwords can't be empty": "Passwords can't be empty",
|
||||
|
@ -1388,6 +1386,7 @@
|
|||
"Homeserver feature support:": "Homeserver feature support:",
|
||||
"exists": "exists",
|
||||
"<not supported>": "<not supported>",
|
||||
"Export E2E room keys": "Export E2E room keys",
|
||||
"Import E2E room keys": "Import E2E room keys",
|
||||
"Cryptography": "Cryptography",
|
||||
"Session ID:": "Session ID:",
|
||||
|
@ -1545,7 +1544,6 @@
|
|||
"%(errorMessage)s (HTTP status %(httpStatus)s)": "%(errorMessage)s (HTTP status %(httpStatus)s)",
|
||||
"Error changing password": "Error changing password",
|
||||
"Your password was successfully changed.": "Your password was successfully changed.",
|
||||
"You will not receive push notifications on other devices until you sign back in to them.": "You will not receive push notifications on other devices until you sign back in to them.",
|
||||
"Success": "Success",
|
||||
"Email addresses": "Email addresses",
|
||||
"Phone numbers": "Phone numbers",
|
||||
|
@ -2315,6 +2313,7 @@
|
|||
"Failed to mute user": "Failed to mute user",
|
||||
"Unmute": "Unmute",
|
||||
"Mute": "Mute",
|
||||
"Warning!": "Warning!",
|
||||
"You will not be able to undo this change as you are promoting the user to have the same power level as yourself.": "You will not be able to undo this change as you are promoting the user to have the same power level as yourself.",
|
||||
"Are you sure?": "Are you sure?",
|
||||
"Deactivate user?": "Deactivate user?",
|
||||
|
@ -3561,7 +3560,6 @@
|
|||
"Skip verification for now": "Skip verification for now",
|
||||
"Too many attempts in a short time. Wait some time before trying again.": "Too many attempts in a short time. Wait some time before trying again.",
|
||||
"Too many attempts in a short time. Retry after %(timeout)s.": "Too many attempts in a short time. Retry after %(timeout)s.",
|
||||
"Resetting your password on this homeserver will cause all of your devices to be signed out. This will delete the message encryption keys stored on them, making encrypted chat history unreadable.": "Resetting your password on this homeserver will cause all of your devices to be signed out. This will delete the message encryption keys stored on them, making encrypted chat history unreadable.",
|
||||
"Signing out your devices will delete the message encryption keys stored on them, making encrypted chat history unreadable.": "Signing out your devices will delete the message encryption keys stored on them, making encrypted chat history unreadable.",
|
||||
"If you want to retain access to your chat history in encrypted rooms, set up Key Backup or export your message keys from one of your other devices before proceeding.": "If you want to retain access to your chat history in encrypted rooms, set up Key Backup or export your message keys from one of your other devices before proceeding.",
|
||||
"Reset password": "Reset password",
|
||||
|
|
|
@ -236,6 +236,11 @@ export default class AutoDiscoveryUtils {
|
|||
if (AutoDiscovery.ALL_ERRORS.indexOf(hsResult.error as string) !== -1) {
|
||||
throw new UserFriendlyError(String(hsResult.error));
|
||||
}
|
||||
if (hsResult.error === AutoDiscovery.ERROR_HOMESERVER_TOO_OLD) {
|
||||
throw new UserFriendlyError(
|
||||
"Your homeserver is too old and does not support the minimum API version required. Please contact your server owner, or upgrade your server.",
|
||||
);
|
||||
}
|
||||
throw new UserFriendlyError("Unexpected error resolving homeserver configuration");
|
||||
} // else the error is not related to syntax - continue anyways.
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue