2018-12-11 14:42:52 +03:00
|
|
|
/*
|
2019-01-07 13:08:57 +03:00
|
|
|
Copyright 2018, 2019 New Vector Ltd
|
2020-01-03 16:33:32 +03:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2018-12-11 14:42:52 +03:00
|
|
|
|
|
|
|
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';
|
|
|
|
import Modal from '../../../Modal';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../../index';
|
2020-05-14 05:41:41 +03:00
|
|
|
import dis from '../../../dispatcher/dispatcher';
|
2018-12-11 14:42:52 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2020-09-10 15:56:07 +03:00
|
|
|
import { MatrixClientPeg } from '../../../MatrixClientPeg';
|
|
|
|
import RestoreKeyBackupDialog from './security/RestoreKeyBackupDialog';
|
2021-06-29 15:11:58 +03:00
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
2018-12-11 14:42:52 +03:00
|
|
|
|
2021-03-09 05:59:41 +03:00
|
|
|
@replaceableComponent("views.dialogs.LogoutDialog")
|
2019-01-07 15:09:19 +03:00
|
|
|
export default class LogoutDialog extends React.Component {
|
2019-02-12 19:01:38 +03:00
|
|
|
defaultProps = {
|
|
|
|
onFinished: function() {},
|
2019-05-31 18:14:49 +03:00
|
|
|
};
|
2019-02-12 19:01:38 +03:00
|
|
|
|
2019-01-07 15:09:19 +03:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this._onSettingsLinkClick = this._onSettingsLinkClick.bind(this);
|
|
|
|
this._onExportE2eKeysClicked = this._onExportE2eKeysClicked.bind(this);
|
|
|
|
this._onFinished = this._onFinished.bind(this);
|
|
|
|
this._onSetRecoveryMethodClick = this._onSetRecoveryMethodClick.bind(this);
|
|
|
|
this._onLogoutConfirm = this._onLogoutConfirm.bind(this);
|
2019-02-12 19:01:38 +03:00
|
|
|
|
2020-03-23 17:48:55 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
const shouldLoadBackupStatus = cli.isCryptoEnabled() && !cli.getKeyBackupEnabled();
|
2019-02-27 14:45:00 +03:00
|
|
|
|
2019-02-12 19:01:38 +03:00
|
|
|
this.state = {
|
2019-05-31 18:20:13 +03:00
|
|
|
shouldLoadBackupStatus: shouldLoadBackupStatus,
|
2019-02-27 14:45:00 +03:00
|
|
|
loading: shouldLoadBackupStatus,
|
2019-02-12 19:01:38 +03:00
|
|
|
backupInfo: null,
|
|
|
|
error: null,
|
|
|
|
};
|
|
|
|
|
2019-02-27 14:45:00 +03:00
|
|
|
if (shouldLoadBackupStatus) {
|
2019-02-12 19:01:38 +03:00
|
|
|
this._loadBackupStatus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async _loadBackupStatus() {
|
|
|
|
try {
|
|
|
|
const backupInfo = await MatrixClientPeg.get().getKeyBackupVersion();
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
backupInfo,
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
console.log("Unable to fetch key backup status", e);
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
error: e,
|
|
|
|
});
|
|
|
|
}
|
2019-01-07 15:09:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_onSettingsLinkClick() {
|
2019-01-07 13:08:57 +03:00
|
|
|
// close dialog
|
2019-02-12 19:01:38 +03:00
|
|
|
this.props.onFinished();
|
2019-01-07 13:08:57 +03:00
|
|
|
}
|
2018-12-11 14:42:52 +03:00
|
|
|
|
2019-01-07 15:09:19 +03:00
|
|
|
_onExportE2eKeysClicked() {
|
2018-12-11 14:42:52 +03:00
|
|
|
Modal.createTrackedDialogAsync('Export E2E Keys', '',
|
2020-09-10 15:56:07 +03:00
|
|
|
import('../../../async-components/views/dialogs/security/ExportE2eKeysDialog'),
|
2018-12-11 14:42:52 +03:00
|
|
|
{
|
|
|
|
matrixClient: MatrixClientPeg.get(),
|
|
|
|
},
|
|
|
|
);
|
2019-01-07 15:09:19 +03:00
|
|
|
}
|
2018-12-11 14:42:52 +03:00
|
|
|
|
2019-01-07 15:09:19 +03:00
|
|
|
_onFinished(confirmed) {
|
2018-12-11 14:42:52 +03:00
|
|
|
if (confirmed) {
|
2021-06-29 15:11:58 +03:00
|
|
|
dis.dispatch({ action: 'logout' });
|
2018-12-11 14:43:56 +03:00
|
|
|
}
|
|
|
|
// close dialog
|
2019-02-12 19:01:38 +03:00
|
|
|
this.props.onFinished();
|
2019-01-07 15:09:19 +03:00
|
|
|
}
|
2018-12-11 14:42:52 +03:00
|
|
|
|
2019-01-07 15:09:19 +03:00
|
|
|
_onSetRecoveryMethodClick() {
|
2019-02-27 14:45:00 +03:00
|
|
|
if (this.state.backupInfo) {
|
|
|
|
// A key backup exists for this account, but the creating device is not
|
|
|
|
// verified, so restore the backup which will give us the keys from it and
|
|
|
|
// allow us to trust it (ie. upload keys to it)
|
2020-01-03 16:33:32 +03:00
|
|
|
Modal.createTrackedDialog(
|
|
|
|
'Restore Backup', '', RestoreKeyBackupDialog, null, null,
|
|
|
|
/* priority = */ false, /* static = */ true,
|
|
|
|
);
|
2019-02-27 14:45:00 +03:00
|
|
|
} else {
|
|
|
|
Modal.createTrackedDialogAsync("Key Backup", "Key Backup",
|
2020-09-10 15:56:07 +03:00
|
|
|
import("../../../async-components/views/dialogs/security/CreateKeyBackupDialog"),
|
2020-01-03 18:34:03 +03:00
|
|
|
null, null, /* priority = */ false, /* static = */ true,
|
2019-02-27 14:45:00 +03:00
|
|
|
);
|
|
|
|
}
|
2019-01-07 13:08:57 +03:00
|
|
|
|
|
|
|
// close dialog
|
2019-02-12 19:01:38 +03:00
|
|
|
this.props.onFinished();
|
2019-01-07 15:09:19 +03:00
|
|
|
}
|
2019-01-07 13:08:57 +03:00
|
|
|
|
2019-01-07 15:09:19 +03:00
|
|
|
_onLogoutConfirm() {
|
2021-06-29 15:11:58 +03:00
|
|
|
dis.dispatch({ action: 'logout' });
|
2019-01-07 13:08:57 +03:00
|
|
|
|
|
|
|
// close dialog
|
2019-02-12 19:01:38 +03:00
|
|
|
this.props.onFinished();
|
2019-01-07 15:09:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-05-31 18:20:13 +03:00
|
|
|
if (this.state.shouldLoadBackupStatus) {
|
2019-02-08 19:58:09 +03:00
|
|
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
2019-02-12 19:01:38 +03:00
|
|
|
|
2019-05-31 18:14:49 +03:00
|
|
|
const description = <div>
|
2021-07-20 00:43:11 +03:00
|
|
|
<p>{ _t(
|
2019-05-31 18:14:49 +03:00
|
|
|
"Encrypted messages are secured with end-to-end encryption. " +
|
|
|
|
"Only you and the recipient(s) have the keys to read these messages.",
|
2021-07-20 00:43:11 +03:00
|
|
|
) }</p>
|
|
|
|
<p>{ _t("Back up your keys before signing out to avoid losing them.") }</p>
|
2019-05-31 18:14:49 +03:00
|
|
|
</div>;
|
|
|
|
|
2019-02-12 19:01:38 +03:00
|
|
|
let dialogContent;
|
|
|
|
if (this.state.loading) {
|
|
|
|
const Spinner = sdk.getComponent('views.elements.Spinner');
|
|
|
|
|
|
|
|
dialogContent = <Spinner />;
|
|
|
|
} else {
|
|
|
|
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
|
|
|
|
let setupButtonCaption;
|
|
|
|
if (this.state.backupInfo) {
|
2020-01-29 18:48:25 +03:00
|
|
|
setupButtonCaption = _t("Connect this session to Key Backup");
|
2019-02-12 19:01:38 +03:00
|
|
|
} else {
|
|
|
|
// if there's an error fetching the backup info, we'll just assume there's
|
|
|
|
// no backup for the purpose of the button caption
|
|
|
|
setupButtonCaption = _t("Start using Key Backup");
|
|
|
|
}
|
|
|
|
|
|
|
|
dialogContent = <div>
|
|
|
|
<div className="mx_Dialog_content" id='mx_Dialog_content'>
|
|
|
|
{ description }
|
|
|
|
</div>
|
|
|
|
<DialogButtons primaryButton={setupButtonCaption}
|
|
|
|
hasCancel={false}
|
|
|
|
onPrimaryButtonClick={this._onSetRecoveryMethodClick}
|
|
|
|
focus={true}
|
|
|
|
>
|
|
|
|
<button onClick={this._onLogoutConfirm}>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ _t("I don't want my encrypted messages") }
|
2019-02-12 19:01:38 +03:00
|
|
|
</button>
|
|
|
|
</DialogButtons>
|
|
|
|
<details>
|
2021-07-20 00:43:11 +03:00
|
|
|
<summary>{ _t("Advanced") }</summary>
|
2019-02-12 19:01:38 +03:00
|
|
|
<p><button onClick={this._onExportE2eKeysClicked}>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ _t("Manually export keys") }
|
2019-02-12 19:01:38 +03:00
|
|
|
</button></p>
|
|
|
|
</details>
|
|
|
|
</div>;
|
|
|
|
}
|
2019-02-08 19:58:09 +03:00
|
|
|
// Not quite a standard question dialog as the primary button cancels
|
|
|
|
// the action and does something else instead, whilst non-default button
|
|
|
|
// confirms the action.
|
|
|
|
return (<BaseDialog
|
2019-02-12 19:01:38 +03:00
|
|
|
title={_t("You'll lose access to your encrypted messages")}
|
2019-02-08 19:58:09 +03:00
|
|
|
contentId='mx_Dialog_content'
|
2019-02-12 19:01:38 +03:00
|
|
|
hasCancel={true}
|
|
|
|
onFinished={this._onFinished}
|
2019-02-08 19:58:09 +03:00
|
|
|
>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ dialogContent }
|
2019-02-08 19:58:09 +03:00
|
|
|
</BaseDialog>);
|
2019-01-07 13:08:57 +03:00
|
|
|
} else {
|
|
|
|
const QuestionDialog = sdk.getComponent('views.dialogs.QuestionDialog');
|
|
|
|
return (<QuestionDialog
|
|
|
|
hasCancelButton={true}
|
|
|
|
title={_t("Sign out")}
|
2019-02-08 19:58:09 +03:00
|
|
|
description={_t(
|
2019-02-12 19:01:38 +03:00
|
|
|
"Are you sure you want to sign out?",
|
2019-02-08 19:58:09 +03:00
|
|
|
)}
|
2019-01-07 13:08:57 +03:00
|
|
|
button={_t("Sign out")}
|
2019-01-07 15:09:19 +03:00
|
|
|
onFinished={this._onFinished}
|
2019-01-07 13:08:57 +03:00
|
|
|
/>);
|
|
|
|
}
|
|
|
|
}
|
2019-01-07 15:09:19 +03:00
|
|
|
}
|