Skip to content

Commit 9fd0ffd

Browse files
steffunkyCopilot
andauthored
N°8545 - Standardize return message from password reset (#812)
* N°8545 - Standardize return message from password reset * N°8545 - Change log severity depending on the error source * Add copyrights * Update application/loginwebpage.class.inc.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update application/loginwebpage.class.inc.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Avoid using dictionary entries in logs * Update application/loginwebpage.class.inc.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent d2f67dc commit 9fd0ffd

File tree

5 files changed

+49
-17
lines changed

5 files changed

+49
-17
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) 2010-2026 Combodo SAS
5+
* @license http://opensource.org/licenses/AGPL-3.0
6+
*/
7+
8+
class ForgotPasswordApplicationException extends Exception
9+
{
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) 2010-2026 Combodo SAS
5+
* @license http://opensource.org/licenses/AGPL-3.0
6+
*/
7+
8+
class ForgotPasswordUserInputException extends Exception
9+
{
10+
}

application/loginwebpage.class.inc.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,16 @@ protected function ForgotPwdGo()
221221

222222
if ($oUser != null) {
223223
if (!MetaModel::IsValidAttCode(get_class($oUser), 'reset_pwd_token')) {
224-
throw new Exception(Dict::S('UI:ResetPwd-Error-NotPossible'));
225-
}
226-
if (!$oUser->CanChangePassword()) {
227-
throw new Exception(Dict::S('UI:ResetPwd-Error-FixedPwd'));
228-
}
224+
throw new ForgotPasswordUserInputException('External accounts do not allow password reset');
225+
}
226+
if (!$oUser->CanChangePassword()) {
227+
throw new ForgotPasswordUserInputException('The account does not allow password reset');
228+
}
229229

230-
$sTo = $oUser->GetResetPasswordEmail(); // throws Exceptions if not allowed
231-
if ($sTo == '') {
232-
throw new Exception(Dict::S('UI:ResetPwd-Error-NoEmail'));
233-
}
230+
$sTo = $oUser->GetResetPasswordEmail(); // throws Exceptions if not allowed
231+
if ($sTo == '') {
232+
throw new ForgotPasswordUserInputException('Missing email address for this account');
233+
}
234234

235235
// This token allows the user to change the password without knowing the previous one
236236
$sToken = bin2hex(random_bytes(32));
@@ -255,17 +255,21 @@ protected function ForgotPwdGo()
255255

256256
case EMAIL_SEND_ERROR:
257257
default:
258-
IssueLog::Error('Failed to send the email with the NEW password for '.$oUser->Get('friendlyname').': '.implode(', ', $aIssues));
259-
throw new Exception(Dict::S('UI:ResetPwd-Error-Send'));
258+
throw new ForgotPasswordApplicationException('Failed to send the password reset email for ' . $oUser->Get('friendlyname') . ': ' . implode(', ', $aIssues));
260259
}
261260
}
262261

263-
$oTwigContext = new LoginTwigRenderer();
264-
$aVars = $oTwigContext->GetDefaultVars();
265-
$oTwigContext->Render($this, 'forgotpwdsent.html.twig', $aVars);
266-
} catch (Exception $e) {
267-
$this->DisplayForgotPwdForm(true, $e->getMessage());
262+
} catch (ForgotPasswordApplicationException $e) {
263+
IssueLog::Error('Failed to process the forgot password request for user "' . $sAuthUser . '" [reason=' . get_class($e) . ']: ' . $e->getMessage());
264+
} catch (ForgotPasswordUserInputException $e) {
265+
IssueLog::Info('Failed to process the forgot password request for user "' . $sAuthUser . '" [reason=' . get_class($e) . ']: ' . $e->getMessage());
266+
} catch (\Throwable $e) {
267+
IssueLog::Error('Unexpected error while processing the forgot password request for user "' . $sAuthUser . '": ' . $e->getMessage());
268268
}
269+
270+
$oTwigContext = new LoginTwigRenderer();
271+
$aVars = $oTwigContext->GetDefaultVars();
272+
$oTwigContext->Render($this, 'forgotpwdsent.html.twig', $aVars);
269273
}
270274

271275
public function DisplayResetPwdForm($sErrorMessage = null)

lib/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,8 @@
744744
'Firebase\\JWT\\JWTExceptionWithPayloadInterface' => $vendorDir . '/firebase/php-jwt/src/JWTExceptionWithPayloadInterface.php',
745745
'Firebase\\JWT\\Key' => $vendorDir . '/firebase/php-jwt/src/Key.php',
746746
'Firebase\\JWT\\SignatureInvalidException' => $vendorDir . '/firebase/php-jwt/src/SignatureInvalidException.php',
747+
'ForgotPasswordApplicationException' => $baseDir . '/application/exceptions/ForgotPasswordApplicationException.php',
748+
'ForgotPasswordUserInputException' => $baseDir . '/application/exceptions/ForgotPasswordUserInputException.php',
747749
'FunctionExpression' => $baseDir . '/core/oql/expression.class.inc.php',
748750
'FunctionOqlExpression' => $baseDir . '/core/oql/oqlquery.class.inc.php',
749751
'GraphEdge' => $baseDir . '/core/simplegraph.class.inc.php',

lib/composer/autoload_static.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
127127
array (
128128
0 => __DIR__ . '/..' . '/symfony/polyfill-php83',
129129
),
130+
'Symfony\\Polyfill\\Php80\\' =>
131+
array (
132+
0 => __DIR__ . '/..' . '/symfony/polyfill-php80',
133+
),
130134
'Symfony\\Polyfill\\Mbstring\\' =>
131135
array (
132136
0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring',
@@ -1103,6 +1107,8 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
11031107
'Firebase\\JWT\\JWTExceptionWithPayloadInterface' => __DIR__ . '/..' . '/firebase/php-jwt/src/JWTExceptionWithPayloadInterface.php',
11041108
'Firebase\\JWT\\Key' => __DIR__ . '/..' . '/firebase/php-jwt/src/Key.php',
11051109
'Firebase\\JWT\\SignatureInvalidException' => __DIR__ . '/..' . '/firebase/php-jwt/src/SignatureInvalidException.php',
1110+
'ForgotPasswordApplicationException' => __DIR__ . '/../..' . '/application/exceptions/ForgotPasswordApplicationException.php',
1111+
'ForgotPasswordUserInputException' => __DIR__ . '/../..' . '/application/exceptions/ForgotPasswordUserInputException.php',
11061112
'FunctionExpression' => __DIR__ . '/../..' . '/core/oql/expression.class.inc.php',
11071113
'FunctionOqlExpression' => __DIR__ . '/../..' . '/core/oql/oqlquery.class.inc.php',
11081114
'GraphEdge' => __DIR__ . '/../..' . '/core/simplegraph.class.inc.php',
@@ -3542,7 +3548,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
35423548
'privUITransactionFile' => __DIR__ . '/../..' . '/application/transaction.class.inc.php',
35433549
'privUITransactionSession' => __DIR__ . '/../..' . '/application/transaction.class.inc.php',
35443550
'utils' => __DIR__ . '/../..' . '/application/utils.inc.php',
3545-
'©' => __DIR__ . '/..' . '/symfony/cache/Traits/ValueWrapper.php',
3551+
'©' => __DIR__ . '/..' . '/symfony/cache/Traits/ValueWrapper.php',
35463552
);
35473553

35483554
public static function getInitializer(ClassLoader $loader)

0 commit comments

Comments
 (0)