1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the awurth/silex-user package. |
5
|
|
|
* |
6
|
|
|
* (c) Alexis Wurth <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace AWurth\Silex\User\Document; |
13
|
|
|
|
14
|
|
|
use AWurth\Silex\User\Model\User as BaseUser; |
15
|
|
|
use AWurth\Silex\User\Validator\Constraints\Unique; |
16
|
|
|
use DateTime; |
17
|
|
|
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; |
18
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Base User document class. |
22
|
|
|
* |
23
|
|
|
* @author Alexis Wurth <[email protected]> |
24
|
|
|
* |
25
|
|
|
* @ODM\MappedSuperclass |
26
|
|
|
*/ |
27
|
|
View Code Duplication |
abstract class User extends BaseUser |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var int |
31
|
|
|
* |
32
|
|
|
* @ODM\Id |
33
|
|
|
*/ |
34
|
|
|
protected $id; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
* |
39
|
|
|
* @ODM\Field(type="string") |
40
|
|
|
*/ |
41
|
|
|
protected $username; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
* |
46
|
|
|
* @ODM\Field(type="string") |
47
|
|
|
*/ |
48
|
|
|
protected $email; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
* |
53
|
|
|
* @ODM\Field(type="string") |
54
|
|
|
*/ |
55
|
|
|
protected $password; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
* |
60
|
|
|
* @ODM\Field(type="string") |
61
|
|
|
*/ |
62
|
|
|
protected $salt; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var bool |
66
|
|
|
* |
67
|
|
|
* @ODM\Field(type="boolean") |
68
|
|
|
*/ |
69
|
|
|
protected $enabled = false; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var DateTime |
73
|
|
|
* |
74
|
|
|
* @ODM\Field(type="date") |
75
|
|
|
*/ |
76
|
|
|
protected $lastLogin; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var array |
80
|
|
|
* |
81
|
|
|
* @ODM\Field(type="collection") |
82
|
|
|
*/ |
83
|
|
|
protected $roles = []; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var string |
87
|
|
|
* |
88
|
|
|
* @ODM\Field(type="string") |
89
|
|
|
*/ |
90
|
|
|
protected $confirmationToken; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
|
|
public static function loadValidatorMetadata(ClassMetadata $metadata) |
96
|
|
|
{ |
97
|
|
|
$metadata->addConstraint(new Unique([ |
98
|
|
|
'fields' => 'username', |
99
|
|
|
'message' => 'silex_user.username.already_used' |
100
|
|
|
])); |
101
|
|
|
$metadata->addConstraint(new Unique([ |
102
|
|
|
'fields' => 'email', |
103
|
|
|
'message' => 'silex_user.email.already_used' |
104
|
|
|
])); |
105
|
|
|
|
106
|
|
|
parent::loadValidatorMetadata($metadata); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.