Skip to content

Commit

Permalink
Require password confirmation for user management
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Oct 25, 2016
1 parent 2216a79 commit 616e840
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 14 deletions.
1 change: 1 addition & 0 deletions settings/Controller/ChangePasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public function changePersonalPassword($oldpassword = '', $newpassword = null) {

/**
* @NoAdminRequired
* @PasswordConfirmationRequired
*
* @param string $username
* @param string $password
Expand Down
2 changes: 2 additions & 0 deletions settings/Controller/GroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function index($pattern = '', $filterGroups = false, $sortGroups = MetaDa
}

/**
* @PasswordConfirmationRequired
* @param string $id
* @return DataResponse
*/
Expand Down Expand Up @@ -128,6 +129,7 @@ public function create($id) {
}

/**
* @PasswordConfirmationRequired
* @param string $id
* @return DataResponse
*/
Expand Down
3 changes: 3 additions & 0 deletions settings/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backe

/**
* @NoAdminRequired
* @PasswordConfirmationRequired
*
* @param string $username
* @param string $password
Expand Down Expand Up @@ -433,6 +434,7 @@ public function create($username, $password, array $groups=array(), $email='') {

/**
* @NoAdminRequired
* @PasswordConfirmationRequired
*
* @param string $id
* @return DataResponse
Expand Down Expand Up @@ -616,6 +618,7 @@ public function stats() {
*
* @NoAdminRequired
* @NoSubadminRequired
* @PasswordConfirmationRequired
*
* @param string $username
* @param string $displayName
Expand Down
7 changes: 7 additions & 0 deletions settings/ajax/togglegroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
OC_JSON::checkSubAdminUser();
OCP\JSON::callCheck();

$lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm');
if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
$l = \OC::$server->getL10N('core');
OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required'))));
exit();
}

$success = true;
$username = (string)$_POST['username'];
$group = (string)$_POST['group'];
Expand Down
7 changes: 7 additions & 0 deletions settings/ajax/togglesubadmins.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
OC_JSON::checkAdminUser();
OCP\JSON::callCheck();

$lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm');
if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
$l = \OC::$server->getL10N('core');
OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required'))));
exit();
}

$username = (string)$_POST['username'];
$group = (string)$_POST['group'];

Expand Down
68 changes: 54 additions & 14 deletions settings/js/users/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ var UserList = {
$userListBody.on('click', '.delete', function () {
// Call function for handling delete/undo
var uid = UserList.getUID(this);

if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(function() {
UserDeleteHandler.mark(uid);
});
return;
}

UserDeleteHandler.mark(uid);
});

Expand Down Expand Up @@ -405,6 +413,11 @@ var UserList = {
},

applyGroupSelect: function (element, user, checked) {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.applySubadminSelect, this, arguments));
return;
}

var $element = $(element);

var checkHandler = null;
Expand Down Expand Up @@ -467,6 +480,11 @@ var UserList = {
},

applySubadminSelect: function (element, user, checked) {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.applySubadminSelect, this, arguments));
return;
}

var $element = $(element);
var checkHandler = function (group) {
if (group === 'admin') {
Expand All @@ -478,7 +496,10 @@ var UserList = {
username: user,
group: group
},
function () {
function (response) {
if (response.data.message) {
OC.Notification.show(response.data.message);
}
}
);
};
Expand Down Expand Up @@ -635,6 +656,27 @@ $(document).ready(function () {
// TODO: move other init calls inside of initialize
UserList.initialize($('#userlist'));

var _submitPasswordChange = function(uid, password, recoveryPasswordVal) {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(function() {
_submitPasswordChange(uid, password, recoveryPasswordVal);
});
return;
}

$.post(
OC.generateUrl('/settings/users/changepassword'),
{username: uid, password: password, recoveryPassword: recoveryPasswordVal},
function (result) {
if (result.status === 'success') {
OC.Notification.showTemporary(t('admin', 'Password successfully changed'));
} else {
OC.Notification.showTemporary(t('admin', result.data.message));
}
}
);
};

$userListBody.on('click', '.password', function (event) {
event.stopPropagation();

Expand All @@ -657,17 +699,7 @@ $(document).ready(function () {
if (event.keyCode === 13) {
if ($(this).val().length > 0) {
var recoveryPasswordVal = $('input:password[id="recoveryPassword"]').val();
$.post(
OC.generateUrl('/settings/users/changepassword'),
{username: uid, password: $(this).val(), recoveryPassword: recoveryPasswordVal},
function (result) {
if (result.status === 'success') {
OC.Notification.showTemporary(t('admin', 'Password successfully changed'));
} else {
OC.Notification.showTemporary(t('admin', result.data.message));
}
}
);
_submitPasswordChange(uid, $(this).val(), recoveryPasswordVal);
$input.blur();
} else {
$input.blur();
Expand Down Expand Up @@ -796,7 +828,14 @@ $(document).ready(function () {
});

UserList._updateGroupListLabel($('#newuser .groups'), []);
$('#newuser').submit(function (event) {
var _submitNewUserForm = function (event) {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(function() {
_submitNewUserForm(event);
});
return;
}

event.preventDefault();
var username = $('#newusername').val();
var password = $('#newuserpassword').val();
Expand Down Expand Up @@ -866,7 +905,8 @@ $(document).ready(function () {
$('#newuser').get(0).reset();
});
});
});
}
$('#newuser').submit(_submitNewUserForm);

if ($('#CheckboxStorageLocation').is(':checked')) {
$("#userlist .storageLocation").show();
Expand Down

0 comments on commit 616e840

Please sign in to comment.