Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions settings/Controller/ChangePasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ public function __construct($appName,
$this->l = $l;
}

/**
* formats HintException into a JSONResponse for output
*
* @param HintException $e
* @return JSONResponse
*/
private function caughtHintException(HintException $e) {
$message = $e->getMessage();
$hint = $e->getHint();
if($message === $hint) {
$hint = '';
}
return new JSONResponse([
'status' => 'error',
'data' => [
'message' => $message,
'hint' => $hint
],
]);
}

/**
* @NoAdminRequired
* @NoSubadminRequired
Expand Down Expand Up @@ -111,12 +132,7 @@ public function changePersonalPassword($oldpassword = '', $newpassword = null) {
}
// password policy app throws exception
} catch(HintException $e) {
return new JSONResponse([
'status' => 'error',
'data' => [
'message' => $e->getHint(),
],
]);
return $this->caughtHintException($e);
}

$this->userSession->updateSessionTokenPassword($newpassword);
Expand Down Expand Up @@ -232,12 +248,7 @@ public function changeUserPassword($username = null, $password = null, $recovery
$result = $targetUser->setPassword($password, $recoveryPassword);
// password policy app throws exception
} catch(HintException $e) {
return new JSONResponse([
'status' => 'error',
'data' => [
'message' => $e->getHint(),
],
]);
return $this->caughtHintException($e);
}
if (!$result && $recoveryEnabledForUser) {
return new JSONResponse([
Expand Down Expand Up @@ -267,12 +278,7 @@ public function changeUserPassword($username = null, $password = null, $recovery
}
// password policy app throws exception
} catch(HintException $e) {
return new JSONResponse([
'status' => 'error',
'data' => [
'message' => $e->getHint(),
],
]);
return $this->caughtHintException($e);
}
}

Expand Down
3 changes: 3 additions & 0 deletions settings/js/personal.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ $(document).ready(function () {
$('#pass2').val('').change();
}
if (typeof(data.data) !== "undefined") {
if(!_.isEmpty(data.data.hint)) {
data.data.message += "\n" + data.data.hint;
}
OC.msg.finishedSaving('#password-error-msg', data);
} else {
OC.msg.finishedSaving('#password-error-msg',
Expand Down
6 changes: 5 additions & 1 deletion settings/js/users/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,11 @@ $(document).ready(function () {
if (result.status === 'success') {
OC.Notification.showTemporary(t('admin', 'Password successfully changed'));
} else {
OC.Notification.showTemporary(t('admin', result.data.message));
var message = _.escape(result.data.message);
if(!_.isEmpty(result.data.hint)) {
message += "<br/>" + _.escape(result.data.hint);
}
OC.Notification.showTemporary(message, {isHTML: true});
}
}
).fail(blurFunction);
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Controller/ChangePasswordControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ public function testChangePersonalPasswordCommonPassword() {
$user->expects($this->once())
->method('setPassword')
->with('new')
->will($this->throwException(new HintException('Common password')));
->will($this->throwException(new HintException('Common password', 'Pick a less common one')));

$expects = [
'status' => 'error',
'data' => [
'message' => 'Common password',
'hint' => 'Pick a less common one',
],
];

Expand Down