TOTP: Fix copy to clipboard button in recovery page

This commit is contained in:
yflory 2023-05-15 18:11:32 +02:00
parent ea25adcf34
commit 4b51300174
2 changed files with 16 additions and 3 deletions

View File

@ -112,7 +112,7 @@ Msg.recovery_totp_disabled = "Multi-factor authentication is already disabled fo
Msg._getKey('recovery_totp_beta', [Config.adminEmail])) : undefined,
h('label', Msg.recovery_totp_proof),
h('textarea.cp-recover-email', {readonly: 'readonly'}),
h('button.btn.btn-secondary', Msg.copyToClipboard),
h('button.btn.btn-secondary#totpcopyproof', Msg.copyToClipboard),
]),
]),
h('div.cp-recovery-step.step-info', { style: 'display: none;' }, [

View File

@ -10,6 +10,7 @@ define([
'/common/common-realtime.js',
'/common/common-constants.js',
'/common/common-feedback.js',
'/common/clipboard.js',
'/common/outer/local-store.js',
'/common/outer/login-block.js',
'/common/outer/http-command.js',
@ -18,7 +19,7 @@ define([
'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
], function ($, Sortify, Login, Cryptpad, /*Test,*/ Cred, UI, Util, Realtime, Constants, Feedback,
LocalStore, Block, ServerCommand) {
Clipboard, LocalStore, Block, ServerCommand) {
if (window.top !== window) { return; }
var Messages = Cryptpad.Messages;
@ -35,6 +36,7 @@ define([
var $uname = $('#username');
var $passwd = $('#password');
var $recoveryKey = $('#totprecovery');
var $copyProof = $('#totpcopyproof');
var $step1 = $('.cp-recovery-step.step1');
var $step2 = $('.cp-recovery-step.step2');
@ -55,6 +57,7 @@ define([
$stepInfo.show();
};
var proofStr;
var addProof = function (blockKeys) {
var pub = blockKeys.sign.publicKey;
var sec = blockKeys.sign.secretKey;
@ -65,9 +68,19 @@ define([
};
var proof = Nacl.sign.detached(Nacl.util.decodeUTF8(Sortify(toSign)), sec);
toSign.proof = Nacl.util.encodeBase64(proof);
$totpProof.html(JSON.stringify(toSign, 0, 2));
proofStr = JSON.stringify(toSign, 0, 2);
$totpProof.html(proofStr);
};
$copyProof.click(function () {
if (!proofStr) { return; }
if (Clipboard.copy.multiline(proofStr)) {
UI.log(Messages.genericCopySuccess);
} else {
UI.warn(Messages.error);
}
});
var revokeTOTP = function (blockKeys) {
var recoveryKey = $recoveryKey.val().trim();
if (!recoveryKey || recoveryKey.length !== 32) {