Skip to content

Commit

Permalink
Merge pull request #3277 from zikula/issue-3274
Browse files Browse the repository at this point in the history
search also for user entities during lost user name and lost password processes, fixed #3274
  • Loading branch information
craigh authored Dec 7, 2016
2 parents 083dae5 + c4761dd commit d174eb6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
46 changes: 36 additions & 10 deletions src/system/ZAuthModule/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,28 @@ public function lostUserNameAction(Request $request)
$form->handleRequest($request);
if ($form->isSubmitted()) {
$data = $form->getData();
$mapping = $this->get('zikula_zauth_module.authentication_mapping_repository')->findBy(['email' => $data['email']]);

$email = $data['email'];
$userName = '';

$mapping = $this->get('zikula_zauth_module.authentication_mapping_repository')->findBy(['email' => $email]);
if (count($mapping) == 1) {
$userName = $mapping[0]->getUname();
} elseif (count($mapping) < 1) {
$user = $this->get('zikula_users_module.user_repository')->findBy(['email' => $email]);
if (count($user) == 1) {
$userName = $user[0]->getUname();
}
}

if ($userName != '') {
// send email
$sent = $this->get('zikula_zauth_module.helper.mail_helper')->sendNotification($mapping[0]->getEmail(), 'lostuname', [
'uname' => $mapping[0]->getUname(),
$sent = $this->get('zikula_zauth_module.helper.mail_helper')->sendNotification($email, 'lostuname', [
'uname' => $userName,
'requestedByAdmin' => false,
]);
if ($sent) {
$this->addFlash('status', $this->__f('Done! The account information for %s has been sent via e-mail.', ['%s' => $data['email']]));
$this->addFlash('status', $this->__f('Done! The account information for %s has been sent via e-mail.', ['%s' => $email]));
} else {
$this->addFlash('error', $this->__('Unable to send email to the requested address. Please contact the system administrator for assistance.'));
}
Expand Down Expand Up @@ -90,20 +103,33 @@ public function lostPasswordAction(Request $request)
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$redirectToRoute = '';
$map = ['uname' => $this->__('username'), 'email' => $this->__('email address')];
$map = [
'uname' => $this->__('username'),
'email' => $this->__('email address')
];
$data = $form->getData();
$field = empty($data['uname']) ? 'email' : 'uname';
$inverse = $field == 'uname' ? 'email' : 'uname';

$user = null;

$mapping = $this->get('zikula_zauth_module.authentication_mapping_repository')->findBy([$field => $data[$field]]);
if (count($mapping) == 1) {
$mapping = $mapping[0];
$user = $this->get('zikula_users_module.user_repository')->find($mapping->getUid());
$user = $this->get('zikula_users_module.user_repository')->find($mapping[0]->getUid());
} elseif (count($mapping) < 1) {
$users = $this->get('zikula_users_module.user_repository')->findBy([$field => $data[$field]]);
if (count($users) == 1) {
$user = $users[0];
}
}

if (null !== $user) {
switch ($user->getActivated()) {
case UsersConstant::ACTIVATED_ACTIVE:
$changePasswordExpireDays = $this->getVar(ZAuthConstant::MODVAR_EXPIRE_DAYS_CHANGE_PASSWORD, ZAuthConstant::DEFAULT_EXPIRE_DAYS_CHANGE_PASSWORD);
$lostPasswordId = $this->get('zikula_zauth_module.helper.lost_password_verification_helper')->createLostPasswordId($mapping);
$sent = $this->get('zikula_zauth_module.helper.mail_helper')->sendNotification($mapping->getEmail(), 'lostpassword', [
'uname' => $mapping->getUname(),
$lostPasswordId = $this->get('zikula_zauth_module.helper.lost_password_verification_helper')->createLostPasswordId($user);
$sent = $this->get('zikula_zauth_module.helper.mail_helper')->sendNotification($user->getEmail(), 'lostpassword', [
'uname' => $user->getUname(),
'validDays' => $changePasswordExpireDays,
'lostPasswordId' => $lostPasswordId,
'requestedByAdmin' => false,
Expand Down
18 changes: 12 additions & 6 deletions src/system/ZAuthModule/Helper/LostPasswordVerificationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

namespace Zikula\ZAuthModule\Helper;

use Zikula\Core\Doctrine\EntityAccess;
use Zikula\ExtensionsModule\Api\VariableApi;
use Zikula\UsersModule\Entity\UserEntity;
use Zikula\ZAuthModule\Entity\AuthenticationMappingEntity;
use Zikula\ZAuthModule\Entity\RepositoryInterface\UserVerificationRepositoryInterface;
use Zikula\ZAuthModule\Entity\UserVerificationEntity;
Expand Down Expand Up @@ -55,17 +57,21 @@ public function __construct(UserVerificationRepositoryInterface $userVerificatio
* Creates an identifier for the lost password link.
* This link carries the user's id, name and email address as well as the actual confirmation code.
*
* @param AuthenticationMappingEntity $mapping
* @param EntityAccess $record instance of UserEntity or AuthenticationMappingEntity
* @return string The created identifier
*/
public function createLostPasswordId(AuthenticationMappingEntity $mapping)
public function createLostPasswordId(EntityAccess $record)
{
$confirmationCode = $this->userVerificationRepository->setVerificationCode($mapping->getUid());
if (!($record instanceof UserEntity) && !($record instanceof AuthenticationMappingEntity)) {
throw new Exception('Record must be an instance of UserEntity or AuthenticationMappingEntity.');
}

$confirmationCode = $this->userVerificationRepository->setVerificationCode($record->getUid());

$params = [
$mapping->getUid(),
$mapping->getUname(),
$mapping->getEmail(),
$record->getUid(),
$record->getUname(),
$record->getEmail(),
$confirmationCode
];

Expand Down

0 comments on commit d174eb6

Please sign in to comment.