Skip to content

Commit

Permalink
updated find user, authentication
Browse files Browse the repository at this point in the history
Signed-off-by: bidi <[email protected]>
  • Loading branch information
bidi47 committed Dec 11, 2024
1 parent d332f71 commit 1b9d2a4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/User/src/Adapter/AuthenticationAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Frontend\User\Adapter;

use Doctrine\ORM\EntityRepository;
use Frontend\App\Common\Message;
use Frontend\User\Entity\UserIdentity;
use Frontend\User\Exception\AuthenticationAdapterException;
use Laminas\Authentication\Adapter\AbstractAdapter;
Expand Down Expand Up @@ -39,6 +40,16 @@ public function authenticate(): Result
);
}

$methodName = 'isDeleted';
$this->checkMethod($identityClass, $methodName);
if ($identityClass->$methodName()) {
return new Result(
Result::FAILURE_IDENTITY_NOT_FOUND,
null,
[Message::ACCOUNT_NOT_FOUND]
);
}

$getCredential = 'get' . ucfirst($this->config['credential_property']);

$this->checkMethod($identityClass, $getCredential);
Expand Down
21 changes: 18 additions & 3 deletions src/User/src/Service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Laminas\Diactoros\UploadedFile;
use Mezzio\Template\TemplateRendererInterface;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;

use function date;
use function file_exists;
Expand Down Expand Up @@ -74,7 +75,13 @@ public function __construct(
*/
public function findByUuid(string $uuid): ?User
{
return $this->userRepository->findByUuid($uuid);
$user = $this->userRepository->findByUuid($uuid);

if (! $user instanceof User || $user->isDeleted()) {
return null;
}

return $user;
}

/**
Expand Down Expand Up @@ -286,7 +293,8 @@ public function findOneBy(array $params = []): ?User
}

$user = $this->userRepository->findOneBy($params);
if ($user->isDeleted()) {

if (! $user instanceof User || $user->isDeleted()) {
return null;
}

Expand Down Expand Up @@ -323,11 +331,18 @@ public function findByResetPasswordHash(?string $hash): ?User
return null;
}

return $this->userRepository->findByResetPasswordHash($hash);
$user = $this->userRepository->findByResetPasswordHash($hash);

if (! $user instanceof User || $user->isDeleted()) {
return null;
}

return $user;
}

/**
* @throws MailException
* @throws TransportExceptionInterface
*/
public function sendResetPasswordCompletedMail(User $user): bool
{
Expand Down
3 changes: 3 additions & 0 deletions test/Unit/User/Adapter/AuthenticationAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ public function testCheckMethodThrowsException(): void
$this->expectExceptionMessage(
(AuthenticationAdapterException::methodNotExists('getPassword', $class::class))->getMessage()
);
$this->expectExceptionMessage(
(AuthenticationAdapterException::methodNotExists('isDeleted', $class::class))->getMessage()
);

$adapter = new AuthenticationAdapter($repository, $this->getConfig($class));

Expand Down

0 comments on commit 1b9d2a4

Please sign in to comment.