Skip to content

Commit 948d3d2

Browse files
committed
make ChangePasswordController and UI Code respect Message and Hint from HintException
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent e115bf9 commit 948d3d2

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

settings/Controller/ChangePasswordController.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,27 @@ public function __construct($appName,
8282
$this->l = $l;
8383
}
8484

85+
/**
86+
* formats HintException into a JSONResponse for output
87+
*
88+
* @param HintException $e
89+
* @return JSONResponse
90+
*/
91+
private function caughtHintException(HintException $e) {
92+
$message = $e->getMessage();
93+
$hint = $e->getHint();
94+
if($message === $hint) {
95+
$hint = '';
96+
}
97+
return new JSONResponse([
98+
'status' => 'error',
99+
'data' => [
100+
'message' => $message,
101+
'hint' => $hint
102+
],
103+
]);
104+
}
105+
85106
/**
86107
* @NoAdminRequired
87108
*
@@ -110,12 +131,7 @@ public function changePersonalPassword($oldpassword = '', $newpassword = null) {
110131
}
111132
// password policy app throws exception
112133
} catch(HintException $e) {
113-
return new JSONResponse([
114-
'status' => 'error',
115-
'data' => [
116-
'message' => $e->getHint(),
117-
],
118-
]);
134+
return $this->caughtHintException($e);
119135
}
120136

121137
$this->userSession->updateSessionTokenPassword($newpassword);
@@ -230,12 +246,7 @@ public function changeUserPassword($username = null, $password = null, $recovery
230246
$result = $targetUser->setPassword($password, $recoveryPassword);
231247
// password policy app throws exception
232248
} catch(HintException $e) {
233-
return new JSONResponse([
234-
'status' => 'error',
235-
'data' => [
236-
'message' => $e->getHint(),
237-
],
238-
]);
249+
return $this->caughtHintException($e);
239250
}
240251
if (!$result && $recoveryEnabledForUser) {
241252
return new JSONResponse([
@@ -265,12 +276,7 @@ public function changeUserPassword($username = null, $password = null, $recovery
265276
}
266277
// password policy app throws exception
267278
} catch(HintException $e) {
268-
return new JSONResponse([
269-
'status' => 'error',
270-
'data' => [
271-
'message' => $e->getHint(),
272-
],
273-
]);
279+
return $this->caughtHintException($e);
274280
}
275281
}
276282

settings/js/personal.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ $(document).ready(function () {
231231
$('#pass2').val('').change();
232232
} else {
233233
if (typeof(data.data) !== "undefined") {
234+
if(!_.isEmpty(data.data.hint)) {
235+
data.data.message += "\n" + data.data.hint;
236+
}
234237
OC.msg.finishedSaving('#password-error-msg', data);
235238
} else {
236239
OC.msg.finishedSaving('#password-error-msg',

settings/js/users/users.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,11 @@ $(document).ready(function () {
664664
if (result.status === 'success') {
665665
OC.Notification.showTemporary(t('admin', 'Password successfully changed'));
666666
} else {
667-
OC.Notification.showTemporary(t('admin', result.data.message));
667+
var message = _.escape(result.data.message);
668+
if(!_.isEmpty(result.data.hint)) {
669+
message += "<br/>" + _.escape(result.data.hint);
670+
}
671+
OC.Notification.showTemporary(t('admin', message), {isHTML: true});
668672
}
669673
}
670674
);

0 commit comments

Comments
 (0)