@@ -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
0 commit comments