2018-12-11 14:42:52 +03:00
|
|
|
/*
|
2019-01-07 13:08:57 +03:00
|
|
|
Copyright 2018, 2019 New Vector Ltd
|
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-01-07 13:08:57 +03:00
|
|
|
import sdk from '../../../index';
|
2018-12-11 14:42:52 +03:00
|
|
|
import dis from '../../../dispatcher';
|
|
|
|
import { _t } from '../../../languageHandler';
|
|
|
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
|
|
|
|
2019-01-07 15:09:19 +03:00
|
|
|
export default class LogoutDialog extends React.Component {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onSettingsLinkClick() {
|
2019-01-07 13:08:57 +03:00
|
|
|
// close dialog
|
2019-01-07 15:09:19 +03:00
|
|
|
if (this.props.onFinished) {
|
|
|
|
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', '',
|
|
|
|
import('../../../async-components/views/dialogs/ExportE2eKeysDialog'),
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
dis.dispatch({action: 'logout'});
|
2018-12-11 14:43:56 +03:00
|
|
|
}
|
|
|
|
// close dialog
|
2019-01-07 15:09:19 +03:00
|
|
|
if (this.props.onFinished) {
|
|
|
|
this.props.onFinished();
|
2018-12-11 14:42:52 +03:00
|
|
|
}
|
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-01-07 13:08:57 +03:00
|
|
|
Modal.createTrackedDialogAsync('Key Backup', 'Key Backup',
|
|
|
|
import('../../../async-components/views/dialogs/keybackup/CreateKeyBackupDialog'),
|
|
|
|
);
|
|
|
|
|
|
|
|
// close dialog
|
2019-01-07 15:09:19 +03:00
|
|
|
if (this.props.onFinished) {
|
|
|
|
this.props.onFinished();
|
2019-01-07 13:08:57 +03:00
|
|
|
}
|
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() {
|
2019-01-07 13:08:57 +03:00
|
|
|
dis.dispatch({action: 'logout'});
|
|
|
|
|
|
|
|
// close dialog
|
2019-01-07 15:09:19 +03:00
|
|
|
if (this.props.onFinished) {
|
|
|
|
this.props.onFinished();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-02-08 19:58:09 +03:00
|
|
|
const description = <div>
|
|
|
|
<p>{_t(
|
|
|
|
"When you log out, you'll lose your secure message history. To prevent " +
|
|
|
|
"this, set up a recovery method.",
|
|
|
|
)}</p>
|
|
|
|
<p>{_t(
|
|
|
|
"Alternatively, advanced users can also manually export encryption keys in " +
|
|
|
|
"<a>Settings</a> before logging out.", {},
|
|
|
|
{
|
|
|
|
a: sub => <a href='#/settings' onClick={this._onSettingsLinkClick}>{sub}</a>,
|
|
|
|
},
|
|
|
|
)}</p>
|
|
|
|
</div>;
|
2019-01-07 13:08:57 +03:00
|
|
|
|
2019-02-08 19:58:09 +03:00
|
|
|
if (!MatrixClientPeg.get().getKeyBackupEnabled()) {
|
|
|
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
|
|
|
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
|
|
|
|
// 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
|
|
|
|
title={_t("Warning!")}
|
|
|
|
contentId='mx_Dialog_content'
|
|
|
|
hasCancel={false}
|
|
|
|
onFinsihed={this._onFinished}
|
|
|
|
>
|
|
|
|
<div className="mx_Dialog_content" id='mx_Dialog_content'>
|
|
|
|
{ description }
|
|
|
|
</div>
|
|
|
|
<DialogButtons primaryButton={_t('Set a Recovery Method')}
|
2019-01-07 13:08:57 +03:00
|
|
|
hasCancel={false}
|
2019-02-08 19:58:09 +03:00
|
|
|
onPrimaryButtonClick={this._onSetRecoveryMethodClick}
|
|
|
|
focus={true}
|
2019-01-07 13:08:57 +03:00
|
|
|
>
|
2019-02-08 19:58:09 +03:00
|
|
|
<button onClick={this._onLogoutConfirm}>
|
|
|
|
{_t("I understand, log out without")}
|
|
|
|
</button>
|
|
|
|
</DialogButtons>
|
|
|
|
</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
|
|
|
// TODO: This is made up by me and would need to also mention verifying
|
2019-02-08 20:23:18 +03:00
|
|
|
// once you can restore a backup by verifying a device
|
2019-02-08 19:58:09 +03:00
|
|
|
description={_t(
|
|
|
|
"When signing in again, you can access encrypted chat history by " +
|
|
|
|
"restoring your key backup. You'll need your recovery passphrase " +
|
|
|
|
"or, if you didn't set a recovery passphrase, your recovery key " +
|
|
|
|
"(that you downloaded).",
|
|
|
|
)}
|
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
|
|
|
}
|