Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UUID and ULID support #171

Closed
jnadaud opened this issue May 25, 2021 · 3 comments
Closed

UUID and ULID support #171

jnadaud opened this issue May 25, 2021 · 3 comments

Comments

@jnadaud
Copy link

jnadaud commented May 25, 2021

Hi,

It's a great and useful bundle!
Have you plan to support UUID and ULID type of User ID ?

Kind regards

@jnadaud jnadaud closed this as completed Jun 11, 2021
@misaert
Copy link

misaert commented Nov 19, 2021

Hi,

It seems the trait ResetPasswordRequestRepositoryTrait does not support UUID and ULID because with Doctrine, it must add 'ulid' as the third argument to tell Doctrine that this is a ULID or alternatively, you can convert it to a value compatible with the type inferred by Doctrine (see https://symfony.com/doc/current/components/uid.html#storing-ulids-in-databases).

I have to override 2 trait methods to do them work:

class ResetPasswordRequestRepository extends ServiceEntityRepository implements ResetPasswordRequestRepositoryInterface
{
    use ResetPasswordRequestRepositoryTrait;

    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, ResetPasswordRequest::class);
    }

    /**
     * @param User $user
     */
    public function createResetPasswordRequest(
        object $user,
        DateTimeInterface $expiresAt,
        string $selector,
        string $hashedToken
    ): ResetPasswordRequestInterface {
        return new ResetPasswordRequest($user, $expiresAt, $selector, $hashedToken);
    }

    /**
     * Override trait method because of using ulid for user ID.
     *
     * @param User $user
     */
    public function getMostRecentNonExpiredRequestDate(object $user): ?DateTimeInterface
    {
        // Normally there is only 1 max request per use, but written to be flexible
        /** @var ResetPasswordRequestInterface $resetPasswordRequest */
        $resetPasswordRequest = $this->createQueryBuilder('t')
            ->where('t.user = :user')
            ->setParameter('user', $user->getId(), 'ulid')
            ->orderBy('t.requestedAt', 'DESC')
            ->setMaxResults(1)
            ->getQuery()
            ->getOneorNullResult()
        ;
        if (null !== $resetPasswordRequest && !$resetPasswordRequest->isExpired()) {
            return $resetPasswordRequest->getRequestedAt();
        }

        return null;
    }

    /**
     * Override trait method because of using ulid for user ID.
     */
    public function removeResetPasswordRequest(ResetPasswordRequestInterface $resetPasswordRequest): void
    {
        /** @var User $user */
        $user = $resetPasswordRequest->getUser();

        $this->createQueryBuilder('t')
            ->delete()
            ->where('t.user = :user')
            ->setParameter('user', $user->getId(), 'ulid')
            ->getQuery()
            ->execute()
        ;
    }
}

Did I have another solution?

Thanks a lot,

Mickaël

@misaert
Copy link

misaert commented Nov 25, 2021

Hi,

@jrushlow, @weaverryan, does this issue deserve to be reopened?

Thanks a lot,

Mickaël

@misaert
Copy link

misaert commented Dec 13, 2021

Hi,

I have created this new issue: #198.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants