Skip to content

Commit

Permalink
Check for 'currentPassword' param in addition to 'password'
Browse files Browse the repository at this point in the history
Resolves #4169
  • Loading branch information
brandonkelly committed Apr 23, 2019
1 parent 2fb1067 commit b8b087f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### Changed
- Craft now correctly typecasts all core boolean and integer values saved to the project config. ([#3695](https://github.com/craftcms/cms/issues/3695))
- Craft now saves new entry versions every time an entry is saved, unless it’s being propagated or resaved.
- `users/save-user` and `users/start-elevated-session` requests now check for a `currentPassword` body param in addition to `password`, when looking for the user’s current password. ([#4169](https://github.com/craftcms/cms/issues/4169))
- `craft\services\Path::getStoragePath()` now has a `$create` argument.
- Updated Twig to ~2.8.1.

Expand Down
13 changes: 7 additions & 6 deletions src/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ public function actionGetElevatedSessionTimeout(): Response
*/
public function actionStartElevatedSession()
{
$password = Craft::$app->getRequest()->getBodyParam('password');
$request = Craft::$app->getRequest();
$password = $request->getBodyParam('currentPassword') ?? $request->getBodyParam('password');

try {
$success = Craft::$app->getUser()->startElevatedSession($password);
Expand Down Expand Up @@ -1758,14 +1759,14 @@ private function _verifyExistingPassword(): bool
return false;
}

$currentHashedPassword = $currentUser->password;

try {
$currentPassword = Craft::$app->getRequest()->getRequiredParam('password');
} catch (BadRequestHttpException $e) {
$request = Craft::$app->getRequest();
$currentPassword = $request->getParam('currentPassword') ?? $request->getParam('password');
if ($currentPassword === null) {
return false;
}

$currentHashedPassword = $currentUser->password;

try {
return Craft::$app->getSecurity()->validatePassword($currentPassword, $currentHashedPassword);
} catch (InvalidArgumentException $e) {
Expand Down
4 changes: 2 additions & 2 deletions src/web/assets/cp/dist/js/Craft.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! - 2019-03-29 */
/*! - 2019-04-23 */
(function($){

/** global: Craft */
Expand Down Expand Up @@ -13515,7 +13515,7 @@ Craft.ElevatedSessionManager = Garnish.Base.extend(
this.clearLoginError();

var data = {
password: this.$passwordInput.val()
currentPassword: this.$passwordInput.val()
};

Craft.postActionRequest('users/start-elevated-session', data, $.proxy(function(response, textStatus) {
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/js/Craft.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/js/Craft.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/src/js/ElevatedSessionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Craft.ElevatedSessionManager = Garnish.Base.extend(
this.clearLoginError();

var data = {
password: this.$passwordInput.val()
currentPassword: this.$passwordInput.val()
};

Craft.postActionRequest('users/start-elevated-session', data, $.proxy(function(response, textStatus) {
Expand Down

0 comments on commit b8b087f

Please sign in to comment.