From 2c5142104c0c6784320d5272bfbdde1334b19ad3 Mon Sep 17 00:00:00 2001 From: Barry O'Donovan Date: Sat, 26 Apr 2014 09:34:37 +0100 Subject: [PATCH] [NF] Add functionality for remember me token with user auth --- .../Auth/Doctrine2UserProvider.php | 47 +++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/Doctrine2Bridge/Auth/Doctrine2UserProvider.php b/src/Doctrine2Bridge/Auth/Doctrine2UserProvider.php index b13b147..0424111 100755 --- a/src/Doctrine2Bridge/Auth/Doctrine2UserProvider.php +++ b/src/Doctrine2Bridge/Auth/Doctrine2UserProvider.php @@ -1,4 +1,4 @@ -hasher->check( $plain, $user->getAuthPassword() ); } -} \ No newline at end of file + + /** + * Retrieve a user by their unique "remember me" token. + * + * @param mixed $identifier + * @param string $token + * @return \Illuminate\Auth\UserInterface|null + */ + public function retrieveByToken( $identifier, $token ) + { + try { + return $this->d2repository + ->createQueryBuilder( 'u' ) + ->setMaxResults( 1 ) + ->select( 'u' ) + ->andWhere( 'u.id = :id' )->setParameter( 'id', $identifier ) + ->andWhere( 'u.remember_token = :token' )->setParameter( 'token', $token ) + ->getQuery() + ->getSingleResult(); + } + catch( \Doctrine\ORM\NoResultException $e ) { + return null; + } + } + + + /** + * Updates the "remember me" token for the given user in storage. + * + * @param \Illuminate\Auth\UserInterface $user + * @param string $token + * @return void + */ + public function updateRememberToken( \Illuminate\Auth\UserInterface $user, $token ) + { + + $user->setRememberToken( $token ); + $this->d2repository->createQueryBuilder()->getEntityManager()->flush(); + } + + +}