Skip to content

Commit

Permalink
[NF] Add functionality for remember me token with user auth
Browse files Browse the repository at this point in the history
  • Loading branch information
barryo committed Apr 26, 2014
1 parent b90b94f commit 2c51421
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions src/Doctrine2Bridge/Auth/Doctrine2UserProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

/**
* Doctrine2 Bridge - Brings Doctrine2 to Laravel 4.
Expand All @@ -15,7 +15,7 @@
/**
* Class to provide a Doctrine2 user object for Laravel authentication.
*/
class Doctrine2UserProvider implements \Illuminate\Auth\UserProviderInterface
class Doctrine2UserProvider implements \Illuminate\Auth\UserProviderInterface
{
/**
* The hasher implementation.
Expand Down Expand Up @@ -107,4 +107,45 @@ public function validateCredentials( \Illuminate\Auth\UserInterface $user, array
return $this->hasher->check( $plain, $user->getAuthPassword() );
}

}

/**
* 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();
}


}

0 comments on commit 2c51421

Please sign in to comment.