jcardo
January 25, 2024, 6:43pm
1
Hello PKP Forum
Because some users forget their usernames or try to log in with their email account, I want to add a message in the PASSWORD_RESET_CONFIRM template that says:
“Don’t forget to log in with your username: {$username}”
But the content of the variable $username is not being sent, only the name of the variable
$username variable works correctly for PASSWORD_RESET template
Thanks for your help
Juan
Hello @jcardo ,
Can you please indicate which specific version of OJS you’re using (e.g. 3.3.0-14)?
Thank you!
-Roger
PKP Team
radjr
April 21, 2025, 8:53pm
6
We have the same problem!! HELP! Please?
jcardo
April 21, 2025, 11:25pm
7
Hi Radjr.
I forgot to reply the solution:
Add the $username variable in \lib\pkp\pages\login\LoginHandler.inc.php modyfing the function requestResetPassword adding: ‘username’ => $user->getUsername(),
like this:
function requestResetPassword($args, $request) {
$this->setupTemplate($request);
$templateMgr = TemplateManager::getManager($request);
$email = $request->getUserVar('email');
$userDao = DAORegistry::getDAO('UserDAO'); /** @var UserDAO $userDao */
$user = $userDao->getUserByEmail($email);
if ($user == null || ($hash = Validation::generatePasswordResetHash($user->getId())) == false) {
$templateMgr
->assign('error', 'user.login.lostPassword.invalidUser')
->display('frontend/pages/userLostPassword.tpl');
return;
}
if ($user->getDisabled()) {
$templateMgr
->assign([
'error' => 'user.login.lostPassword.confirmationSentFailedWithReason',
'reason' => empty($reason = $user->getDisabledReason() ?? '')
? __('user.login.accountDisabled')
: __('user.login.accountDisabledWithReason', ['reason' => $reason])
])
->display('frontend/pages/userLostPassword.tpl');
return;
}
// Send email confirming password reset as all check has passed
import('lib.pkp.classes.mail.MailTemplate');
$mail = new MailTemplate('PASSWORD_RESET_CONFIRM');
$site = $request->getSite();
$this->_setMailFrom($request, $mail, $site);
$mail->assignParams([
'url' => $request->url(null, 'login', 'resetPassword', $user->getUsername(), array('confirm' => $hash)),
'siteTitle' => htmlspecialchars($site->getLocalizedTitle()),
'username' => $user->getUsername(),
]);
$mail->addRecipient($user->getEmail(), $user->getFullName());
$mail->send();
$templateMgr->assign([
'pageTitle' => 'user.login.resetPassword',
'message' => 'user.login.lostPassword.confirmationSent',
'backLink' => $request->url(null, $request->getRequestedPage()),
'backLinkLabel' => 'user.login',
]);
$templateMgr->display('frontend/pages/message.tpl');
}
Don’ t forget to make a copy of the original file.
Regards.