-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
185: second and third modals when clicking on save button (#304)
* 185: add second modal * 185-second-modal-when-clicking-on-save-button: add third modal * 185-second-modal-when-clicking-on-save-button: final modifs pre PR * 185-second-modal-when-clicking-on-save-button: change faq url + space and wording typos * 185-second-modal-when-clicking-on-save-button: remove patch * 185-second-modal-when-clicking-on-save-button: last PR modifs * 185-second-modal-when-clicking-on-save-button: add end of line for _TchapAnchor.pcss * remove incorrect headers * 185-second-modal-when-clicking-on-save-button: modif logout button for 3rd modal * 185: add variabilisation for logout/return in 3rd modal * 185: add correct label for onReturn button * 185-second-modal-when-clicking-on-save-button: modifs wording and fix bug not closing popup on logout Co-authored-by: olivier <odelcroi@gmail.com>
- Loading branch information
Showing
14 changed files
with
443 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
patches/rename-exported-keys/matrix-react-sdk+3.58.0-rc.2.patch
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.tc_anchor { | ||
color: var(--accent) !important; | ||
text-decoration: underline !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
Copyright 2022 DINUM | ||
*/ | ||
|
||
.tc_exportE2eKeysDialog { | ||
.tc_modalParagraph { | ||
line-height: 22px; | ||
margin-bottom: 0px; | ||
margin-top: 0px; | ||
} | ||
|
||
.tc_withMarginTop { | ||
margin-top: 22px; | ||
} | ||
|
||
.tc_withMarginBottom { | ||
margin-bottom: 8px; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
res/css/views/dialogs/_TchapExportE2eKeysSuccessDialog.pcss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
Copyright 2022 DINUM | ||
*/ | ||
|
||
.tc_exportE2eKeysSuccessDialog { | ||
.tc_exportE2eKeysSuccessDialog_img { | ||
display: flex; | ||
justify-content: center; | ||
margin-bottom: 26px; | ||
margin-top: 34px; | ||
} | ||
|
||
.tc_modalParagraph { | ||
line-height: 22px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright 2021 DINUM | ||
Copyright 2022 DINUM | ||
*/ | ||
|
||
.mx_ServerPickerDialog { | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
227 changes: 227 additions & 0 deletions
227
src/async-components/views/dialogs/security/TchapExportE2eKeysDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
/* | ||
Copyright 2022 DINUM | ||
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 FileSaver from 'file-saver'; | ||
import React, { ComponentType } from 'react'; | ||
import BaseDialog from "matrix-react-sdk/src/components/views/dialogs/BaseDialog"; | ||
import { IDialogProps } from "matrix-react-sdk/src/components/views/dialogs/IDialogProps"; | ||
import { _t } from 'matrix-react-sdk/src/languageHandler'; | ||
import Field from "matrix-react-sdk/src/components/views/elements/Field"; | ||
import Modal from 'matrix-react-sdk/src/Modal'; | ||
import * as MegolmExportEncryption from 'matrix-react-sdk/src/utils/MegolmExportEncryption'; | ||
import { KeysStartingWith } from "matrix-react-sdk/src/@types/common"; | ||
import { MatrixClient } from 'matrix-js-sdk/src/client'; | ||
import { logger } from "matrix-js-sdk/src/logger"; | ||
|
||
import "../../../../../res/css/views/dialogs/_TchapExportE2eKeysDialog.pcss"; | ||
|
||
enum Phase { | ||
Edit = "edit", | ||
Exporting = "exporting", | ||
} | ||
|
||
interface IProps extends IDialogProps { | ||
allowLogout: boolean; | ||
matrixClient: MatrixClient; | ||
onFinished: (success: boolean) => void; | ||
} | ||
|
||
interface IState { | ||
phase: Phase; | ||
errStr: string; | ||
passphrase1: string; | ||
passphrase2: string; | ||
} | ||
|
||
type AnyPassphrase = KeysStartingWith<IState, "passphrase">; | ||
|
||
export default class TchapExportE2eKeysDialog extends React.Component<IProps, IState> { | ||
private unmounted = false; | ||
|
||
constructor(props: IProps) { | ||
super(props); | ||
|
||
this.state = { | ||
phase: Phase.Edit, | ||
errStr: null, | ||
passphrase1: "", | ||
passphrase2: "", | ||
}; | ||
|
||
this.startExport = this.startExport.bind(this); | ||
this.onPassphraseFormSubmit = this.onPassphraseFormSubmit.bind(this); | ||
this.onCancelClick = this.onCancelClick.bind(this); | ||
} | ||
|
||
public componentWillUnmount(): void { | ||
this.unmounted = true; | ||
} | ||
|
||
private startExport(passphrase: string): void { | ||
// extra Promise.resolve() to turn synchronous exceptions into | ||
// asynchronous ones. | ||
Promise.resolve().then(() => { | ||
return this.props.matrixClient.exportRoomKeys(); | ||
}).then((k) => { | ||
return MegolmExportEncryption.encryptMegolmKeyFile( | ||
JSON.stringify(k), passphrase, | ||
); | ||
}).then((f) => { | ||
const blob = new Blob([f], { | ||
type: 'text/plain;charset=us-ascii', | ||
}); | ||
FileSaver.saveAs(blob, 'tchap-keys.txt'); | ||
// :TCHAP: don't close too fast | ||
}).then(() => { | ||
// :TCHAP: added a confirmation modal | ||
Modal.createDialogAsync( | ||
import( | ||
"./TchapExportE2eKeysSuccessDialog" | ||
) as unknown as Promise<ComponentType<{}>>, | ||
{ | ||
allowLogout: this.props.allowLogout, | ||
onFinished: (res) => { | ||
this.props.onFinished(res); | ||
}, | ||
}, | ||
); | ||
}).catch((e) => { | ||
logger.error("Error exporting e2e keys:", e); | ||
if (this.unmounted) { | ||
return; | ||
} | ||
const msg = e.friendlyText || _t('Unknown error'); | ||
this.setState({ | ||
errStr: msg, | ||
phase: Phase.Edit, | ||
}); | ||
}); | ||
|
||
this.setState({ | ||
errStr: null, | ||
phase: Phase.Exporting, | ||
}); | ||
} | ||
|
||
private onPassphraseChange = (ev: React.ChangeEvent<HTMLInputElement>, phrase: AnyPassphrase) => { | ||
this.setState({ | ||
[phrase]: ev.target.value, | ||
} as Pick<IState, AnyPassphrase>); | ||
}; | ||
|
||
private onPassphraseFormSubmit = (ev: React.FormEvent): boolean => { | ||
ev.preventDefault(); | ||
|
||
const passphrase = this.state.passphrase1; | ||
|
||
if (passphrase.length < 8) { | ||
this.setState({ errStr: _t('Passphrase must be at least 8 character long') }); | ||
return false; | ||
} | ||
if (passphrase !== this.state.passphrase2) { | ||
this.setState({ errStr: _t('Passphrases must match') }); | ||
return false; | ||
} | ||
if (!passphrase) { | ||
this.setState({ errStr: _t('Passphrase must not be empty') }); | ||
return false; | ||
} | ||
|
||
this.startExport(passphrase); | ||
return false; | ||
}; | ||
|
||
private onCancelClick = (ev: React.MouseEvent): boolean => { | ||
ev.preventDefault(); | ||
this.props.onFinished(false); | ||
return false; | ||
}; | ||
|
||
public render(): JSX.Element { | ||
const disableForm = (this.state.phase === Phase.Exporting); | ||
|
||
return ( | ||
<BaseDialog className='tc_exportE2eKeysDialog' | ||
onFinished={this.props.onFinished} | ||
title={_t("Save your Tchap Keys (encryption keys)")} | ||
> | ||
<form onSubmit={this.onPassphraseFormSubmit}> | ||
<div className="mx_Dialog_content"> | ||
<p className='tc_modalParagraph'> | ||
{ _t( | ||
'If you do not have another connected device, ' + | ||
'<b>we advise you to save your keys in a file on your device</b>.', | ||
{}, | ||
{ b: (sub) => <b>{ sub }</b> }, | ||
) } | ||
</p> | ||
<p className='tc_modalParagraph'> | ||
{ _t( | ||
'This file will be protected by a password, ' + | ||
'which will be asked next time you log in, ' + | ||
'when you will import the keys to unlock your messages.', | ||
) } | ||
</p> | ||
<p className='tc_modalParagraph tc_withMarginBottom tc_withMarginTop'> | ||
{ _t('Create your Tchap Key password (minimum 8 characters)') } | ||
</p> | ||
<div className='error'> | ||
{ this.state.errStr } | ||
</div> | ||
<div className='mx_E2eKeysDialog_inputTable'> | ||
<div className='mx_E2eKeysDialog_inputRow'> | ||
<div className='mx_E2eKeysDialog_inputCell'> | ||
<Field | ||
autoFocus={true} | ||
disabled={disableForm} | ||
label={_t('Your Tchap Key password')} | ||
onChange={e => this.onPassphraseChange(e, "passphrase1")} | ||
size={64} | ||
type="password" | ||
value={this.state.passphrase1} | ||
/> | ||
</div> | ||
</div> | ||
<div className='mx_E2eKeysDialog_inputRow'> | ||
<div className='mx_E2eKeysDialog_inputCell'> | ||
<Field | ||
disabled={disableForm} | ||
label={_t('Confirm your Tchap Key password')} | ||
onChange={e => this.onPassphraseChange(e, "passphrase2")} | ||
size={64} | ||
type="password" | ||
value={this.state.passphrase2} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div className='mx_Dialog_buttons'> | ||
<button onClick={this.onCancelClick} disabled={disableForm}> | ||
{ _t("Cancel") } | ||
</button> | ||
<input | ||
className='mx_Dialog_primary' | ||
disabled={disableForm} | ||
type='submit' | ||
value={_t('Save my keys')} | ||
/> | ||
</div> | ||
</form> | ||
</BaseDialog> | ||
); | ||
} | ||
} |
Oops, something went wrong.