MAPG-142 modify UserPasswordResetterRepository to return only one resetter for user

(it is not possible for an user to have multiple)
This commit is contained in:
Bence Pőcze 2020-07-05 13:22:22 +02:00
parent 32392590bd
commit 37094e552b
Signed by: bence
GPG Key ID: AA52B11A3269D1C1
2 changed files with 4 additions and 4 deletions

View File

@ -196,7 +196,8 @@ class UserController implements ISecured
$this->pdm->deleteFromDb($userConfirmation);
}
foreach ($this->userPasswordResetterRepository->getByUser($user) as $userPasswordResetter) {
$userPasswordResetter = $this->userPasswordResetterRepository->getByUser($user);
if ($userPasswordResetter !== null) {
$this->pdm->deleteFromDb($userPasswordResetter);
}

View File

@ -1,6 +1,5 @@
<?php namespace MapGuesser\Repository;
use Generator;
use MapGuesser\Database\Query\Select;
use MapGuesser\PersistentData\Model\User;
use MapGuesser\PersistentData\Model\UserPasswordResetter;
@ -28,11 +27,11 @@ class UserPasswordResetterRepository
return $this->pdm->selectFromDb($select, UserPasswordResetter::class);
}
public function getByUser(User $user): Generator
public function getByUser(User $user): ?UserPasswordResetter
{
$select = new Select(\Container::$dbConnection);
$select->where('user_id', '=', $user->getId());
yield from $this->pdm->selectMultipleFromDb($select, UserPasswordResetter::class);
return $this->pdm->selectFromDb($select, UserPasswordResetter::class);
}
}