Skip to content

Patch L5 auth #93

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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/DoctrineUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Illuminate\Auth\UserProviderInterface;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Hashing\Hasher;

class DoctrineUserProvider implements UserProviderInterface
class DoctrineUserProvider implements UserProvider
{
/**
* @var Hasher
Expand Down Expand Up @@ -53,8 +53,10 @@ public function retrieveById($identifier)
public function retrieveByToken($identifier, $token)
{
$entity = $this->getEntity();
$keyName = $this->entityManager->getClassMetadata(get_class($entity))->getSingleIdentifierFieldName();

return $this->getRepository()->findOneBy([
$entity->getKeyName() => $identifier,
$keyName => $identifier,
$entity->getRememberTokenName() => $token
]);
}
Expand Down Expand Up @@ -82,9 +84,11 @@ public function updateRememberToken(Authenticatable $user, $token)
public function retrieveByCredentials(array $credentials)
{
$criteria = [];
foreach ($credentials as $key => $value)
if ( ! str_contains($key, 'password'))
foreach ($credentials as $key => $value) {
if ( ! str_contains($key, 'password')) {
$criteria[$key] = $value;
}
}

return $this->getRepository()->findOneBy($criteria);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Traits/Authentication.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Mitch\LaravelDoctrine\Traits;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping AS ORM;

trait Authentication {
Expand Down Expand Up @@ -27,7 +28,9 @@ public function setPassword($password) {
* @return mixed
*/
public function getAuthIdentifier() {
return method_exists($this, 'getKeyName') ? $this->getKeyName() : 'id';
$entityManager = app('Doctrine\ORM\EntityManager');

return $this->{$entityManager->getClassMetadata(get_class($this))->getSingleIdentifierFieldName()};
}

/**
Expand Down Expand Up @@ -60,6 +63,6 @@ public function setRememberToken($value) {
* @return string
*/
public function getRememberTokenName() {
return 'remember_token';
return 'rememberToken';
}
}