Skip to content
This repository was archived by the owner on Mar 13, 2026. It is now read-only.

Commit d174eb6

Browse files
authored
Merge pull request #3277 from zikula/issue-3274
search also for user entities during lost user name and lost password processes, fixed #3274
2 parents 083dae5 + c4761dd commit d174eb6

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

src/system/ZAuthModule/Controller/AccountController.php

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,28 @@ public function lostUserNameAction(Request $request)
4848
$form->handleRequest($request);
4949
if ($form->isSubmitted()) {
5050
$data = $form->getData();
51-
$mapping = $this->get('zikula_zauth_module.authentication_mapping_repository')->findBy(['email' => $data['email']]);
51+
52+
$email = $data['email'];
53+
$userName = '';
54+
55+
$mapping = $this->get('zikula_zauth_module.authentication_mapping_repository')->findBy(['email' => $email]);
5256
if (count($mapping) == 1) {
57+
$userName = $mapping[0]->getUname();
58+
} elseif (count($mapping) < 1) {
59+
$user = $this->get('zikula_users_module.user_repository')->findBy(['email' => $email]);
60+
if (count($user) == 1) {
61+
$userName = $user[0]->getUname();
62+
}
63+
}
64+
65+
if ($userName != '') {
5366
// send email
54-
$sent = $this->get('zikula_zauth_module.helper.mail_helper')->sendNotification($mapping[0]->getEmail(), 'lostuname', [
55-
'uname' => $mapping[0]->getUname(),
67+
$sent = $this->get('zikula_zauth_module.helper.mail_helper')->sendNotification($email, 'lostuname', [
68+
'uname' => $userName,
5669
'requestedByAdmin' => false,
5770
]);
5871
if ($sent) {
59-
$this->addFlash('status', $this->__f('Done! The account information for %s has been sent via e-mail.', ['%s' => $data['email']]));
72+
$this->addFlash('status', $this->__f('Done! The account information for %s has been sent via e-mail.', ['%s' => $email]));
6073
} else {
6174
$this->addFlash('error', $this->__('Unable to send email to the requested address. Please contact the system administrator for assistance.'));
6275
}
@@ -90,20 +103,33 @@ public function lostPasswordAction(Request $request)
90103
$form->handleRequest($request);
91104
if ($form->isSubmitted() && $form->isValid()) {
92105
$redirectToRoute = '';
93-
$map = ['uname' => $this->__('username'), 'email' => $this->__('email address')];
106+
$map = [
107+
'uname' => $this->__('username'),
108+
'email' => $this->__('email address')
109+
];
94110
$data = $form->getData();
95111
$field = empty($data['uname']) ? 'email' : 'uname';
96112
$inverse = $field == 'uname' ? 'email' : 'uname';
113+
114+
$user = null;
115+
97116
$mapping = $this->get('zikula_zauth_module.authentication_mapping_repository')->findBy([$field => $data[$field]]);
98117
if (count($mapping) == 1) {
99-
$mapping = $mapping[0];
100-
$user = $this->get('zikula_users_module.user_repository')->find($mapping->getUid());
118+
$user = $this->get('zikula_users_module.user_repository')->find($mapping[0]->getUid());
119+
} elseif (count($mapping) < 1) {
120+
$users = $this->get('zikula_users_module.user_repository')->findBy([$field => $data[$field]]);
121+
if (count($users) == 1) {
122+
$user = $users[0];
123+
}
124+
}
125+
126+
if (null !== $user) {
101127
switch ($user->getActivated()) {
102128
case UsersConstant::ACTIVATED_ACTIVE:
103129
$changePasswordExpireDays = $this->getVar(ZAuthConstant::MODVAR_EXPIRE_DAYS_CHANGE_PASSWORD, ZAuthConstant::DEFAULT_EXPIRE_DAYS_CHANGE_PASSWORD);
104-
$lostPasswordId = $this->get('zikula_zauth_module.helper.lost_password_verification_helper')->createLostPasswordId($mapping);
105-
$sent = $this->get('zikula_zauth_module.helper.mail_helper')->sendNotification($mapping->getEmail(), 'lostpassword', [
106-
'uname' => $mapping->getUname(),
130+
$lostPasswordId = $this->get('zikula_zauth_module.helper.lost_password_verification_helper')->createLostPasswordId($user);
131+
$sent = $this->get('zikula_zauth_module.helper.mail_helper')->sendNotification($user->getEmail(), 'lostpassword', [
132+
'uname' => $user->getUname(),
107133
'validDays' => $changePasswordExpireDays,
108134
'lostPasswordId' => $lostPasswordId,
109135
'requestedByAdmin' => false,

src/system/ZAuthModule/Helper/LostPasswordVerificationHelper.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Zikula\ZAuthModule\Helper;
1313

14+
use Zikula\Core\Doctrine\EntityAccess;
1415
use Zikula\ExtensionsModule\Api\VariableApi;
16+
use Zikula\UsersModule\Entity\UserEntity;
1517
use Zikula\ZAuthModule\Entity\AuthenticationMappingEntity;
1618
use Zikula\ZAuthModule\Entity\RepositoryInterface\UserVerificationRepositoryInterface;
1719
use Zikula\ZAuthModule\Entity\UserVerificationEntity;
@@ -55,17 +57,21 @@ public function __construct(UserVerificationRepositoryInterface $userVerificatio
5557
* Creates an identifier for the lost password link.
5658
* This link carries the user's id, name and email address as well as the actual confirmation code.
5759
*
58-
* @param AuthenticationMappingEntity $mapping
60+
* @param EntityAccess $record instance of UserEntity or AuthenticationMappingEntity
5961
* @return string The created identifier
6062
*/
61-
public function createLostPasswordId(AuthenticationMappingEntity $mapping)
63+
public function createLostPasswordId(EntityAccess $record)
6264
{
63-
$confirmationCode = $this->userVerificationRepository->setVerificationCode($mapping->getUid());
65+
if (!($record instanceof UserEntity) && !($record instanceof AuthenticationMappingEntity)) {
66+
throw new Exception('Record must be an instance of UserEntity or AuthenticationMappingEntity.');
67+
}
68+
69+
$confirmationCode = $this->userVerificationRepository->setVerificationCode($record->getUid());
6470

6571
$params = [
66-
$mapping->getUid(),
67-
$mapping->getUname(),
68-
$mapping->getEmail(),
72+
$record->getUid(),
73+
$record->getUname(),
74+
$record->getEmail(),
6975
$confirmationCode
7076
];
7177

0 commit comments

Comments
 (0)