|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Webcook security bundle. |
|
5
|
|
|
* |
|
6
|
|
|
* See LICENSE file in the root of the bundle. Webcook |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Webcook\Cms\SecurityBundle\Entity; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
12
|
|
|
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface; |
|
13
|
|
|
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; |
|
14
|
|
|
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; |
|
15
|
|
|
use Doctrine\ORM\EntityRepository; |
|
16
|
|
|
use Doctrine\ORM\NoResultException; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* User entity repository. |
|
20
|
|
|
*/ |
|
21
|
|
|
class UserRepository extends EntityRepository implements UserLoaderInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
* |
|
26
|
|
|
* @param [type] $username [description] |
|
|
|
|
|
|
27
|
|
|
* |
|
28
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
29
|
|
|
*/ |
|
30
|
1 |
|
public function loadUserByUsername($username) |
|
31
|
|
|
{ |
|
32
|
|
|
$q = $this |
|
33
|
1 |
|
->createQueryBuilder('u') |
|
34
|
1 |
|
->where('(u.username = :username OR u.email = :email) AND u.isActive = :active') |
|
35
|
1 |
|
->setParameter('username', $username) |
|
36
|
1 |
|
->setParameter('email', $username) |
|
37
|
1 |
|
->setParameter('active', true) |
|
38
|
1 |
|
->getQuery(); |
|
39
|
|
|
|
|
40
|
|
|
try { |
|
41
|
1 |
|
$user = $q->getSingleResult(); |
|
42
|
1 |
|
} catch (NoResultException $e) { |
|
43
|
1 |
|
$message = sprintf( |
|
44
|
1 |
|
'Unable to find an active admin object identified by "%s".', |
|
45
|
|
|
$username |
|
46
|
|
|
); |
|
47
|
1 |
|
throw new UsernameNotFoundException($message, 0, $e); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
return $user; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
* |
|
56
|
|
|
* @param UserInterface $user [description] |
|
57
|
|
|
* |
|
58
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
59
|
|
|
*/ |
|
60
|
1 |
|
public function refreshUser(UserInterface $user) |
|
61
|
|
|
{ |
|
62
|
1 |
|
$class = get_class($user); |
|
63
|
1 |
|
if (!$this->supportsClass($class)) { |
|
64
|
|
|
throw new UnsupportedUserException( |
|
65
|
|
|
sprintf( |
|
66
|
|
|
'Instances of "%s" are not supported.', |
|
67
|
|
|
$class |
|
68
|
|
|
) |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
return $this |
|
72
|
1 |
|
->createQueryBuilder('u') |
|
73
|
1 |
|
->where('u.id = :id AND u.isActive = :active') |
|
74
|
1 |
|
->setParameter('id', $user->getId()) |
|
|
|
|
|
|
75
|
1 |
|
->setParameter('active', true) |
|
76
|
1 |
|
->getQuery() |
|
77
|
1 |
|
->getSingleResult(); |
|
78
|
|
|
|
|
79
|
|
|
//return $this->find($user->getId()); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* {@inheritdoc} |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $class [description] |
|
86
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
87
|
|
|
*/ |
|
88
|
1 |
|
public function supportsClass($class) |
|
89
|
|
|
{ |
|
90
|
1 |
|
return $this->getEntityName() === $class |
|
91
|
1 |
|
|| is_subclass_of($class, $this->getEntityName()); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.