Files
ThreadNet-Web/src/components/structures/auth/CompleteSecurity.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

115 lines
4.0 KiB
TypeScript
Raw Normal View History

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.
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";
import SetupEncryptionBody from "./SetupEncryptionBody";
import AccessibleButton from "../../views/elements/AccessibleButton";
import CompleteSecurityBody from "../../views/auth/CompleteSecurityBody";
import AuthPage from "../../views/auth/AuthPage";
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 {
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> {
public constructor(props: IProps) {
2021-07-03 11:38:51 +01:00
super(props);
const store = SetupEncryptionStore.sharedInstance();
store.start();
2025-09-12 14:37:14 -04:00
this.state = { phase: store.phase };
}
public componentDidMount(): void {
const store = SetupEncryptionStore.sharedInstance();
store.on("update", this.onStoreUpdate);
}
2021-07-03 11:38:51 +01:00
private onStoreUpdate = (): void => {
const store = SetupEncryptionStore.sharedInstance();
2025-09-12 14:37:14 -04:00
this.setState({ phase: store.phase });
};
private onSkipClick = (): void => {
const store = SetupEncryptionStore.sharedInstance();
store.skip();
};
2021-07-03 11:38:51 +01:00
public componentWillUnmount(): void {
const store = SetupEncryptionStore.sharedInstance();
2021-07-03 11:38:51 +01:00
store.off("update", this.onStoreUpdate);
store.stop();
2020-01-15 21:13:56 +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) {
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) {
icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_verified" />;
title = _t("encryption|verification|after_new_login|device_verified");
2021-06-18 14:05:12 +01:00
} else if (phase === Phase.ConfirmSkip) {
icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_warning" />;
title = _t("common|are_you_sure");
2021-06-18 14:05:12 +01:00
} else if (phase === Phase.Busy) {
icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_warning" />;
title = _t("encryption|verification|after_new_login|verify_this_device");
} 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}`);
}
const forceVerification = SdkConfig.get("force_verification");
let skipButton;
if (!forceVerification && phase === Phase.Intro) {
skipButton = (
<AccessibleButton
onClick={this.onSkipClick}
className="mx_CompleteSecurity_skip"
aria-label={_t("encryption|verification|after_new_login|skip_verification")}
/>
);
}
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>
);
}
}