2020-01-15 21:13:56 +00:00
|
|
|
/*
|
|
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
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";
|
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-09-08 13:55:31 -04:00
|
|
|
lostKeys: boolean;
|
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();
|
2021-07-03 11:38:51 +01:00
|
|
|
store.on("update", this.onStoreUpdate);
|
2020-03-24 15:57:04 +01:00
|
|
|
store.start();
|
2021-09-08 13:55:31 -04:00
|
|
|
this.state = { phase: store.phase, lostKeys: store.lostKeys() };
|
2020-01-25 20:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-03 11:38:51 +01:00
|
|
|
private onStoreUpdate = (): void => {
|
2020-03-24 15:57:04 +01:00
|
|
|
const store = SetupEncryptionStore.sharedInstance();
|
2021-09-08 13:55:31 -04:00
|
|
|
this.setState({ phase: store.phase, lostKeys: store.lostKeys() });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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 {
|
2021-09-08 13:55:31 -04:00
|
|
|
const { phase, lostKeys } = 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) {
|
2021-09-08 13:55:31 -04:00
|
|
|
if (lostKeys) {
|
|
|
|
|
icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_warning" />;
|
2023-10-02 16:13:00 +05:30
|
|
|
title = _t("encryption|verification|after_new_login|unable_to_verify");
|
2021-09-08 13:55:31 -04:00
|
|
|
} else {
|
|
|
|
|
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
|
|
|
}
|
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.ConfirmReset) {
|
|
|
|
|
icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_warning" />;
|
2023-10-02 16:13:00 +05:30
|
|
|
title = _t("encryption|verification|after_new_login|reset_confirmation");
|
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}`);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 13:55:31 -04:00
|
|
|
let skipButton;
|
|
|
|
|
if (phase === Phase.Intro || phase === Phase.ConfirmReset) {
|
|
|
|
|
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 (
|
|
|
|
|
<AuthPage>
|
2020-01-27 22:27:11 +00:00
|
|
|
<CompleteSecurityBody>
|
2022-08-01 08:31:14 +01:00
|
|
|
<h1 className="mx_CompleteSecurity_header">
|
2021-07-19 22:43:11 +01:00
|
|
|
{icon}
|
|
|
|
|
{title}
|
2021-09-08 13:55:31 -04:00
|
|
|
{skipButton}
|
2022-08-01 08:31:14 +01:00
|
|
|
</h1>
|
2020-01-15 21:13:56 +00:00
|
|
|
<div className="mx_CompleteSecurity_body">
|
2020-03-24 15:57:04 +01:00
|
|
|
<SetupEncryptionBody onFinished={this.props.onFinished} />
|
2020-01-15 21:13:56 +00:00
|
|
|
</div>
|
2020-01-27 22:27:11 +00:00
|
|
|
</CompleteSecurityBody>
|
2020-01-15 21:13:56 +00:00
|
|
|
</AuthPage>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|