-
-
Notifications
You must be signed in to change notification settings - Fork 188
/
AccountRepository.php
99 lines (90 loc) · 3.09 KB
/
AccountRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Neos\Flow\Security;
/*
* This file is part of the Neos.Flow package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Persistence\Exception\IllegalObjectTypeException;
use Neos\Flow\Persistence\QueryInterface;
use Neos\Flow\Persistence\Repository;
use Neos\Flow\Security\Context as SecurityContext;
/**
* The repository for accounts
*
* @Flow\Scope("singleton")
*/
class AccountRepository extends Repository
{
/**
* @var string
*/
const ENTITY_CLASSNAME = Account::class;
/**
* @var array
*/
protected $defaultOrderings = ['creationDate' => QueryInterface::ORDER_DESCENDING];
/**
* Note: This is not required to be "the" SecurityContext of the current session, but any SecurityContext actually.
*
* @Flow\Inject
* @var SecurityContext
*/
protected $securityContext;
/**
* Removes an account
*
* @param object $object The account to remove
* @return void
* @throws IllegalObjectTypeException
*/
public function remove($object): void
{
parent::remove($object);
// destroy the sessions for the account to be removed
$this->securityContext->destroySessionsForAccount($object);
}
/**
* Returns the account for a specific authentication provider with the given identifier
*
* @param string $accountIdentifier The account identifier
* @param string $authenticationProviderName The authentication provider name
* @return Account|null
*/
public function findByAccountIdentifierAndAuthenticationProviderName($accountIdentifier, $authenticationProviderName)
{
$query = $this->createQuery();
return $query->matching(
$query->logicalAnd(
$query->equals('accountIdentifier', $accountIdentifier),
$query->equals('authenticationProviderName', $authenticationProviderName)
)
)->execute()->getFirst();
}
/**
* Returns the account for a specific authentication provider with the given identifier if it's not expired
*
* @param string $accountIdentifier The account identifier
* @param string $authenticationProviderName The authentication provider name
* @return Account|null
*/
public function findActiveByAccountIdentifierAndAuthenticationProviderName($accountIdentifier, $authenticationProviderName)
{
$query = $this->createQuery();
return $query->matching(
$query->logicalAnd(
$query->equals('accountIdentifier', $accountIdentifier),
$query->equals('authenticationProviderName', $authenticationProviderName),
$query->logicalOr(
$query->equals('expirationDate', null),
$query->greaterThan('expirationDate', new \DateTime())
)
)
)->execute()->getFirst();
}
}