Skip to content

Commit

Permalink
Warn for password reset when files_encryption is enabled
Browse files Browse the repository at this point in the history
This patch wil warn the user of the consequences when resetting the password and requires checking a checkbox (as we had in the past) to reset a password.

Furthermore I updated the code to use our new classes and added some unit tests for it 👯

Fixes #11438
  • Loading branch information
LukasReschke committed Oct 21, 2014
1 parent c0ddf06 commit 5ff95ef
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 149 deletions.
64 changes: 50 additions & 14 deletions core/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@

namespace OC\Core;

use OC\AppFramework\Utility\SimpleContainer;
use \OCP\AppFramework\App;
use OC\Core\LostPassword\Controller\LostController;
use OC\Core\User\UserController;
use \OCP\Util;

/**
* Class Application
*
* @package OC\Core
*/
class Application extends App {


/**
* @param array $urlParams
*/
public function __construct(array $urlParams=array()){
parent::__construct('core', $urlParams);

Expand All @@ -25,29 +34,56 @@ public function __construct(array $urlParams=array()){
/**
* Controllers
*/
$container->registerService('LostController', function($c) {
$container->registerService('LostController', function(SimpleContainer $c) {
return new LostController(
$c->query('AppName'),
$c->query('Request'),
$c->query('ServerContainer')->getURLGenerator(),
$c->query('ServerContainer')->getUserManager(),
new \OC_Defaults(),
$c->query('ServerContainer')->getL10N('core'),
$c->query('ServerContainer')->getConfig(),
$c->query('ServerContainer')->getUserSession(),
\OCP\Util::getDefaultEmailAddress('lostpassword-noreply'),
\OC_App::isEnabled('files_encryption')
$c->query('URLGenerator'),
$c->query('UserManager'),
$c->query('Defaults'),
$c->query('L10N'),
$c->query('Config'),
$c->query('SecureRandom'),
$c->query('DefaultEmailAddress'),
$c->query('IsEncryptionEnabled')
);
});
$container->registerService('UserController', function($c) {
$container->registerService('UserController', function(SimpleContainer $c) {
return new UserController(
$c->query('AppName'),
$c->query('Request'),
$c->query('ServerContainer')->getUserManager(),
new \OC_Defaults()
$c->query('UserManager'),
$c->query('Defaults')
);
});
}

/**
* Core class wrappers
*/
$container->registerService('IsEncryptionEnabled', function() {
return \OC_App::isEnabled('files_encryption');
});
$container->registerService('URLGenerator', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getURLGenerator();
});
$container->registerService('UserManager', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getUserManager();
});
$container->registerService('Config', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getConfig();
});
$container->registerService('L10N', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getL10N('core');
});
$container->registerService('SecureRandom', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getSecureRandom();
});
$container->registerService('Defaults', function() {
return new \OC_Defaults;
});
$container->registerService('DefaultEmailAddress', function() {
return Util::getDefaultEmailAddress('lostpassword-noreply');
});
}

}
19 changes: 6 additions & 13 deletions core/js/lostpassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,12 @@ OC.Lostpassword = {
+ ('<br /><input type="checkbox" id="encrypted-continue" value="Yes" />')
+ '<label for="encrypted-continue">'
+ t('core', 'I know what I\'m doing')
+ '</label><br />'
+ '<a id="lost-password-encryption" href>'
+ t('core', 'Reset password')
+ '</a>',
+ '</label><br />',

resetErrorMsg : t('core', 'Password can not be changed. Please contact your administrator.'),

init : function() {
if ($('#lost-password-encryption').length){
$('#lost-password-encryption').click(OC.Lostpassword.sendLink);
} else {
$('#lost-password').click(OC.Lostpassword.sendLink);
}
$('#lost-password').click(OC.Lostpassword.sendLink);
$('#reset-password #submit').click(OC.Lostpassword.resetPassword);
},

Expand All @@ -32,8 +25,7 @@ OC.Lostpassword = {
$.post(
OC.generateUrl('/lostpassword/email'),
{
user : $('#user').val(),
proceed: $('#encrypted-continue').attr('checked') ? 'Yes' : 'No'
user : $('#user').val()
},
OC.Lostpassword.sendLinkDone
);
Expand Down Expand Up @@ -84,7 +76,8 @@ OC.Lostpassword = {
$.post(
$('#password').parents('form').attr('action'),
{
password : $('#password').val()
password : $('#password').val(),
proceed: $('#encrypted-continue').attr('checked') ? 'true' : 'false'
},
OC.Lostpassword.resetDone
);
Expand Down Expand Up @@ -126,7 +119,7 @@ OC.Lostpassword = {

getResetStatusNode : function (){
if (!$('#lost-password').length){
$('<p id="lost-password"></p>').insertAfter($('#submit'));
$('<p id="lost-password"></p>').insertBefore($('#reset-password fieldset'));
} else {
$('#lost-password').replaceWith($('<p id="lost-password"></p>'));
}
Expand Down
Loading

0 comments on commit 5ff95ef

Please sign in to comment.