let user repeat the recovery key password to prevent typos

This commit is contained in:
Bjoern Schiessle 2013-09-18 16:03:53 +02:00
parent 1eb42626f5
commit 5fb0e257a4
2 changed files with 37 additions and 27 deletions

View File

@ -1,6 +1,6 @@
/** /**
* Copyright (c) 2013, Sam Tuke <samtuke@owncloud.com>, Robin Appelman * Copyright (c) 2013, Sam Tuke <samtuke@owncloud.com>, Robin Appelman
* <icewind1991@gmail.com> * <icewind1991@gmail.com>, Bjoern Schiessle <schiessle@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or later. * This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file. * See the COPYING-README file.
*/ */
@ -31,11 +31,12 @@ $(document).ready(function(){
// Trigger ajax on recoveryAdmin status change // Trigger ajax on recoveryAdmin status change
var enabledStatus = $('#adminEnableRecovery').val(); var enabledStatus = $('#adminEnableRecovery').val();
$('input:password[name="recoveryPassword"]').keyup(function(event) { $('input:password[name="encryptionRecoveryPassword"]').keyup(function(event) {
var recoveryPassword = $( '#recoveryPassword' ).val(); var recoveryPassword = $( '#encryptionRecoveryPassword' ).val();
var recoveryPasswordRepeated = $( '#repeatEncryptionRecoveryPassword' ).val();
var checkedButton = $('input:radio[name="adminEnableRecovery"]:checked').val(); var checkedButton = $('input:radio[name="adminEnableRecovery"]:checked').val();
var uncheckedValue = (1+parseInt(checkedButton)) % 2; var uncheckedValue = (1+parseInt(checkedButton)) % 2;
if (recoveryPassword != '' ) { if (recoveryPassword !== '' && recoveryPassword === recoveryPasswordRepeated) {
$('input:radio[name="adminEnableRecovery"][value="'+uncheckedValue.toString()+'"]').removeAttr("disabled"); $('input:radio[name="adminEnableRecovery"][value="'+uncheckedValue.toString()+'"]').removeAttr("disabled");
} else { } else {
$('input:radio[name="adminEnableRecovery"][value="'+uncheckedValue.toString()+'"]').attr("disabled", "true"); $('input:radio[name="adminEnableRecovery"][value="'+uncheckedValue.toString()+'"]').attr("disabled", "true");
@ -46,7 +47,7 @@ $(document).ready(function(){
function() { function() {
var recoveryStatus = $( this ).val(); var recoveryStatus = $( this ).val();
var oldStatus = (1+parseInt(recoveryStatus)) % 2; var oldStatus = (1+parseInt(recoveryStatus)) % 2;
var recoveryPassword = $( '#recoveryPassword' ).val(); var recoveryPassword = $( '#encryptionRecoveryPassword' ).val();
$.post( $.post(
OC.filePath( 'files_encryption', 'ajax', 'adminrecovery.php' ) OC.filePath( 'files_encryption', 'ajax', 'adminrecovery.php' )
, { adminEnableRecovery: recoveryStatus, recoveryPassword: recoveryPassword } , { adminEnableRecovery: recoveryStatus, recoveryPassword: recoveryPassword }
@ -57,11 +58,10 @@ $(document).ready(function(){
} else { } else {
OC.Notification.hide(); OC.Notification.hide();
if (recoveryStatus === "0") { if (recoveryStatus === "0") {
$('button:button[name="submitChangeRecoveryKey"]').attr("disabled", "true"); $('p[name="changeRecoveryPasswordBlock"]').attr("class", "hidden");
$('input:password[name="changeRecoveryPassword"]').attr("disabled", "true");
$('input:password[name="changeRecoveryPassword"]').val("");
} else { } else {
$('input:password[name="changeRecoveryPassword"]').removeAttr("disabled"); $('input:password[name="changeRecoveryPassword"]').val("");
$('p[name="changeRecoveryPasswordBlock"]').removeAttr("class");
} }
} }
} }
@ -72,9 +72,11 @@ $(document).ready(function(){
// change recovery password // change recovery password
$('input:password[name="changeRecoveryPassword"]').keyup(function(event) { $('input:password[name="changeRecoveryPassword"]').keyup(function(event) {
var oldRecoveryPassword = $('input:password[id="oldRecoveryPassword"]').val(); var oldRecoveryPassword = $('#oldEncryptionRecoveryPassword').val();
var newRecoveryPassword = $('input:password[id="newRecoveryPassword"]').val(); var newRecoveryPassword = $('#newEncryptionRecoveryPassword').val();
if (newRecoveryPassword != '' && oldRecoveryPassword != '' ) { var newRecoveryPasswordRepeated = $('#repeatedNewEncryptionRecoveryPassword').val();
console.log("new: " + newRecoveryPassword + " - repeated: " + newRecoveryPasswordRepeated);
if (newRecoveryPassword !== '' && oldRecoveryPassword !== '' && newRecoveryPassword === newRecoveryPasswordRepeated) {
$('button:button[name="submitChangeRecoveryKey"]').removeAttr("disabled"); $('button:button[name="submitChangeRecoveryKey"]').removeAttr("disabled");
} else { } else {
$('button:button[name="submitChangeRecoveryKey"]').attr("disabled", "true"); $('button:button[name="submitChangeRecoveryKey"]').attr("disabled", "true");
@ -83,8 +85,8 @@ $(document).ready(function(){
$('button:button[name="submitChangeRecoveryKey"]').click(function() { $('button:button[name="submitChangeRecoveryKey"]').click(function() {
var oldRecoveryPassword = $('input:password[id="oldRecoveryPassword"]').val(); var oldRecoveryPassword = $('#oldEncryptionRecoveryPassword').val();
var newRecoveryPassword = $('input:password[id="newRecoveryPassword"]').val(); var newRecoveryPassword = $('#newEncryptionRecoveryPassword').val();
OC.msg.startSaving('#encryption .msg'); OC.msg.startSaving('#encryption .msg');
$.post( $.post(
OC.filePath( 'files_encryption', 'ajax', 'changeRecoveryPassword.php' ) OC.filePath( 'files_encryption', 'ajax', 'changeRecoveryPassword.php' )

View File

@ -10,14 +10,17 @@
<?php p($l->t("Enable recovery key (allow to recover users files in case of password loss):")); ?> <?php p($l->t("Enable recovery key (allow to recover users files in case of password loss):")); ?>
<br/> <br/>
<br/> <br/>
<input type="password" name="recoveryPassword" id="recoveryPassword"/> <input type="password" name="encryptionRecoveryPassword" id="encryptionRecoveryPassword"/>
<label for="recoveryPassword"><?php p($l->t("Recovery key password")); ?></label> <label for="recoveryPassword"><?php p($l->t("Recovery key password")); ?></label>
<br/> <br/>
<input type="password" name="encryptionRecoveryPassword" id="repeatEncryptionRecoveryPassword"/>
<label for="repeatEncryptionRecoveryPassword"><?php p($l->t("Repeat Recovery key password")); ?></label>
<br/>
<input <input
type='radio' type='radio'
name='adminEnableRecovery' name='adminEnableRecovery'
value='1' value='1'
<?php echo($_["recoveryEnabled"] == 1 ? 'checked="checked"' : 'disabled'); ?> /> <?php echo($_["recoveryEnabled"] === '1' ? 'checked="checked"' : 'disabled'); ?> />
<?php p($l->t("Enabled")); ?> <?php p($l->t("Enabled")); ?>
<br/> <br/>
@ -25,27 +28,32 @@
type='radio' type='radio'
name='adminEnableRecovery' name='adminEnableRecovery'
value='0' value='0'
<?php echo($_["recoveryEnabled"] == 0 ? 'checked="checked"' : 'disabled'); ?> /> <?php echo($_["recoveryEnabled"] === '0' ? 'checked="checked"' : 'disabled'); ?> />
<?php p($l->t("Disabled")); ?> <?php p($l->t("Disabled")); ?>
</p> </p>
<br/><br/> <br/><br/>
<p> <p name="changeRecoveryPasswordBlock" <?php if ($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"');?>>
<strong><?php p($l->t("Change recovery key password:")); ?></strong> <strong><?php p($l->t("Change recovery key password:")); ?></strong>
<br/><br/> <br/><br/>
<input <input
type="password" type="password"
name="changeRecoveryPassword" name="changeRecoveryPassword"
id="oldRecoveryPassword" id="oldEncryptionRecoveryPassword"
<?php echo($_["recoveryEnabled"] == 0 ? 'disabled' : ''); ?> /> <label for="oldEncryptionRecoveryPassword"><?php p($l->t("Old Recovery key password")); ?></label>
<label for="oldRecoveryPassword"><?php p($l->t("Old Recovery key password")); ?></label> <br/>
<br/> <br/>
<input <input
type="password" type="password"
name="changeRecoveryPassword" name="changeRecoveryPassword"
id="newRecoveryPassword" id="newEncryptionRecoveryPassword"
<?php echo($_["recoveryEnabled"] == 0 ? 'disabled' : ''); ?> /> <label for="newEncryptionRecoveryPassword"><?php p($l->t("New Recovery key password")); ?></label>
<label for="newRecoveryPassword"><?php p($l->t("New Recovery key password")); ?></label> <br/>
<input
type="password"
name="changeRecoveryPassword"
id="repeatedNewEncryptionRecoveryPassword"
<label for="repeatEncryptionRecoveryPassword"><?php p($l->t("Repeat New Recovery key password")); ?></label>
<br/> <br/>
<button <button
type="button" type="button"