Skip to content

Commit

Permalink
Update Auth provider for L5
Browse files Browse the repository at this point in the history
  • Loading branch information
barryo committed Feb 9, 2015
1 parent 613c757 commit 3f0ee92
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
1 change: 1 addition & 0 deletions examples/auth/Entities.User.dcm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
</id>
<field name="username" type="string" unique="true" length="255" nullable="false"/>
<field name="password" type="string" length="255" nullable="false"/>
<field name="remember_token" type="string" length="255" nullable="true"/>
</entity>
</doctrine-mapping>
41 changes: 37 additions & 4 deletions examples/auth/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* User
*/
class User implements \Illuminate\Auth\UserInterface
class User implements \Illuminate\Contracts\Auth\Authenticatable
{
/**
* @var string
Expand Down Expand Up @@ -40,7 +40,7 @@ public function setUsername($username)
/**
* Get username
*
* @return string
* @return string
*/
public function getUsername()
{
Expand All @@ -64,7 +64,7 @@ public function setPassword($password)
/**
* Get password
*
* @return string
* @return string
*/
public function getPassword()
{
Expand All @@ -74,7 +74,7 @@ public function getPassword()
/**
* Get id
*
* @return integer
* @return integer
*/
public function getId()
{
Expand Down Expand Up @@ -107,4 +107,37 @@ public function getAuthPassword()
return $this->getPassword();
}


/**
* Get the token value for the "remember me" session.
*
* @return string
*/
public function getRememberToken()
{
return $this->remember_token;
}

/**
* Set the token value for the "remember me" session.
*
* @param string $value
* @return void
*/
public function setRememberToken($value)
{
$this->remember_token = $value;
}

/**
* Get the column name for the "remember me" token.
*
* @return string
*/
public function getRememberTokenName()
{
return 'remember_token';
}


}
11 changes: 4 additions & 7 deletions src/Doctrine2Bridge/Auth/Doctrine2UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@

namespace Doctrine2Bridge\Auth;

use Illuminate\Hashing\HasherInterface;

/**
* Class to provide a Doctrine2 user object for Laravel authentication.
*/
class Doctrine2UserProvider implements \Illuminate\Auth\UserProviderInterface
class Doctrine2UserProvider implements \Illuminate\Contracts\Auth\UserProvider
{
/**
* The hasher implementation.
Expand All @@ -38,7 +36,7 @@ class Doctrine2UserProvider implements \Illuminate\Auth\UserProviderInterface
* @param \Illuminate\Hashing\HasherInterface $hasher The hasher implementation
* @return void
*/
public function __construct( \Doctrine\ORM\EntityRepository $d2repository, HasherInterface $hasher )
public function __construct( \Doctrine\ORM\EntityRepository $d2repository, \Illuminate\Contracts\Hashing\Hasher $hasher )
{
$this->d2repository = $d2repository;
$this->hasher = $hasher;
Expand Down Expand Up @@ -100,7 +98,7 @@ public function retrieveByCredentials(array $credentials)
* @param array $credentials
* @return bool
*/
public function validateCredentials( \Illuminate\Auth\UserInterface $user, array $credentials )
public function validateCredentials( \Illuminate\Contracts\Auth\Authenticatable $user, array $credentials )
{
$plain = $credentials['password'];

Expand Down Expand Up @@ -140,12 +138,11 @@ public function retrieveByToken( $identifier, $token )
* @param string $token
* @return void
*/
public function updateRememberToken( \Illuminate\Auth\UserInterface $user, $token )
public function updateRememberToken( \Illuminate\Contracts\Auth\Authenticatable $user, $token )
{

$user->setRememberToken( $token );
$this->d2repository->createQueryBuilder()->getEntityManager()->flush();
}


}
2 changes: 1 addition & 1 deletion src/Doctrine2Bridge/Doctrine2BridgeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private function setupAuth()
{
Auth::extend( 'doctrine2bridge', function() {
return new \Illuminate\Auth\Guard(
new Auth\Doctrine2UserProvider(
new \Doctrine2Bridge\Auth\Doctrine2UserProvider(
\D2EM::getRepository( Config::get( 'd2bdoctrine.auth.entity' ) ),
new \Illuminate\Hashing\BcryptHasher
),
Expand Down

0 comments on commit 3f0ee92

Please sign in to comment.