2020-01-15 21:13:56 +00:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2020-01-15 21:13:56 +00:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2020-01-15 21:13:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2025-09-12 14:37:14 -04:00
|
|
|
import { Glass } from "@vector-im/compound-web";
|
2021-10-22 17:23:32 -05:00
|
|
|
|
2020-01-15 21:13:56 +00:00
|
|
|
import { _t } from "../../../languageHandler";
|
2021-06-18 14:05:12 +01:00
|
|
|
import { SetupEncryptionStore, Phase } from "../../../stores/SetupEncryptionStore";
|
2020-03-24 15:57:04 +01:00
|
|
|
import SetupEncryptionBody from "./SetupEncryptionBody";
|
2021-09-08 13:55:31 -04:00
|
|
|
import AccessibleButton from "../../views/elements/AccessibleButton";
|
2021-11-08 11:27:52 +01:00
|
|
|
import CompleteSecurityBody from "../../views/auth/CompleteSecurityBody";
|
|
|
|
|
import AuthPage from "../../views/auth/AuthPage";
|
2024-09-11 21:55:00 +01:00
|
|
|
import SdkConfig from "../../../SdkConfig";
|
2020-01-15 21:13:56 +00:00
|
|
|
|
2021-07-03 11:38:51 +01:00
|
|
|
interface IProps {
|
|
|
|
|
onFinished: () => void;
|
|
|
|
|
}
|
2020-01-15 21:13:56 +00:00
|
|
|
|
2021-07-03 11:38:51 +01:00
|
|
|
interface IState {
|
2023-05-16 14:25:43 +01:00
|
|
|
phase?: Phase;
|
2021-07-03 11:38:51 +01:00
|
|
|
}
|
|
|
|
|
|
2025-09-12 14:37:14 -04:00
|
|
|
/**
|
|
|
|
|
* Prompts the user to verify their device when they first log in.
|
|
|
|
|
*/
|
2021-07-03 11:38:51 +01:00
|
|
|
export default class CompleteSecurity extends React.Component<IProps, IState> {
|
2022-12-16 12:29:59 +00:00
|
|
|
public constructor(props: IProps) {
|
2021-07-03 11:38:51 +01:00
|
|
|
super(props);
|
2020-03-24 15:57:04 +01:00
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.start();
|
2025-09-12 14:37:14 -04:00
|
|
|
this.state = { phase: store.phase };
|
2020-01-25 20:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-01 17:39:08 +00:00
|
|
|
public componentDidMount(): void {
|
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.on("update", this.onStoreUpdate);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-03 11:38:51 +01:00
|
|
|
private onStoreUpdate = (): void => {
|
2020-03-24 15:57:04 +01:00
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
2025-09-12 14:37:14 -04:00
|
|
|
this.setState({ phase: store.phase });
|
2021-09-08 13:55:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private onSkipClick = (): void => {
|
|
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
|
|
|
|
store.skip();
|
2020-03-24 15:57:04 +01:00
|
|
|
};
|
|
|
|
|
|
2021-07-03 11:38:51 +01:00
|
|
|
public componentWillUnmount(): void {
|
2020-03-24 15:57:04 +01:00
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
2021-07-03 11:38:51 +01:00
|
|
|
store.off("update", this.onStoreUpdate);
|
2020-03-24 15:57:04 +01:00
|
|
|
store.stop();
|
2020-01-15 21:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2025-09-12 14:37:14 -04:00
|
|
|
const { phase } = this.state;
|
2020-01-15 21:13:56 +00:00
|
|
|
let icon;
|
|
|
|
|
let title;
|
2020-03-16 17:47:56 +00:00
|
|
|
|
2021-06-18 14:05:12 +01:00
|
|
|
if (phase === Phase.Loading) {
|
2021-03-08 23:28:44 +00:00
|
|
|
return null;
|
2021-06-18 14:05:12 +01:00
|
|
|
} else if (phase === Phase.Intro) {
|
2025-09-12 14:37:14 -04:00
|
|
|
// We don't specify an icon nor title since `SetupEncryptionBody` provides its own
|
2021-06-18 14:05:12 +01:00
|
|
|
} else if (phase === Phase.Done) {
|
2020-04-16 13:23:01 +01:00
|
|
|
icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_verified" />;
|
2023-10-02 16:13:00 +05:30
|
|
|
title = _t("encryption|verification|after_new_login|device_verified");
|
2021-06-18 14:05:12 +01:00
|
|
|
} else if (phase === Phase.ConfirmSkip) {
|
2020-04-16 13:23:01 +01:00
|
|
|
icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_warning" />;
|
2023-09-29 08:49:26 +01:00
|
|
|
title = _t("common|are_you_sure");
|
2021-06-18 14:05:12 +01:00
|
|
|
} else if (phase === Phase.Busy) {
|
2020-04-16 13:23:01 +01:00
|
|
|
icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_warning" />;
|
2023-10-02 16:13:00 +05:30
|
|
|
title = _t("encryption|verification|after_new_login|verify_this_device");
|
2021-09-08 13:55:31 -04:00
|
|
|
} else if (phase === Phase.Finished) {
|
|
|
|
|
// SetupEncryptionBody will take care of calling onFinished, we don't need to do anything
|
2020-01-15 21:13:56 +00:00
|
|
|
} else {
|
|
|
|
|
throw new Error(`Unknown phase ${phase}`);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-03 09:55:06 +01:00
|
|
|
const forceVerification = SdkConfig.get("force_verification");
|
2024-09-11 21:55:00 +01:00
|
|
|
|
2021-09-08 13:55:31 -04:00
|
|
|
let skipButton;
|
2025-04-30 11:08:38 +01:00
|
|
|
if (!forceVerification && phase === Phase.Intro) {
|
2021-09-08 13:55:31 -04:00
|
|
|
skipButton = (
|
|
|
|
|
<AccessibleButton
|
|
|
|
|
onClick={this.onSkipClick}
|
|
|
|
|
className="mx_CompleteSecurity_skip"
|
2023-10-02 16:13:00 +05:30
|
|
|
aria-label={_t("encryption|verification|after_new_login|skip_verification")}
|
2021-09-08 13:55:31 -04:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-15 21:13:56 +00:00
|
|
|
return (
|
2025-09-12 14:37:14 -04:00
|
|
|
<AuthPage addBlur={false}>
|
|
|
|
|
<Glass className="mx_Dialog_border">
|
|
|
|
|
<CompleteSecurityBody>
|
|
|
|
|
<h1 className="mx_CompleteSecurity_header">
|
|
|
|
|
{icon}
|
|
|
|
|
{title}
|
|
|
|
|
{skipButton}
|
|
|
|
|
</h1>
|
|
|
|
|
<div className="mx_CompleteSecurity_body">
|
|
|
|
|
<SetupEncryptionBody onFinished={this.props.onFinished} allowLogout={true} />
|
|
|
|
|
</div>
|
|
|
|
|
</CompleteSecurityBody>
|
|
|
|
|
</Glass>
|
2020-01-15 21:13:56 +00:00
|
|
|
</AuthPage>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|