1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher User Bundle. |
7
|
|
|
* |
8
|
|
|
* Copyright 2021 Sourcefabric z.ú. and contributors. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please see the |
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* @Copyright 2021 Sourcefabric z.ú |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace SWP\Bundle\UserBundle\Model; |
18
|
|
|
|
19
|
|
|
abstract class UserManager implements UserManagerInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function createUser(): UserInterface |
25
|
|
|
{ |
26
|
|
|
$class = $this->getClass(); |
27
|
|
|
$user = new $class(); |
28
|
|
|
|
29
|
|
|
return $user; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function findUserByEmail($email) |
36
|
|
|
{ |
37
|
|
|
return $this->findUserBy(['email' => $email]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function findUserByUsername($username) |
44
|
|
|
{ |
45
|
|
|
return $this->findUserBy(['username' => $username]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function findUserByUsernameOrEmail($usernameOrEmail) |
52
|
|
|
{ |
53
|
|
|
if (preg_match('/^.+\@\S+\.\S+$/', $usernameOrEmail)) { |
54
|
|
|
$user = $this->findUserByEmail($usernameOrEmail); |
55
|
|
|
if (null !== $user) { |
56
|
|
|
return $user; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $this->findUserByUsername($usernameOrEmail); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function findUserByConfirmationToken($token) |
67
|
|
|
{ |
68
|
|
|
return $this->findUserBy(['confirmationToken' => $token]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
abstract public function deleteUser(UserInterface $user); |
72
|
|
|
|
73
|
|
|
abstract public function findUserBy(array $criteria); |
74
|
|
|
|
75
|
|
|
abstract public function findUsers(); |
76
|
|
|
|
77
|
|
|
public function getClass() |
78
|
|
|
{ |
79
|
|
|
return User::class; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
abstract public function updateUser(UserInterface $user, $andFlush = true); |
83
|
|
|
} |
84
|
|
|
|