|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the 2amigos/yii2-usuario project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2amigOS! <http://2amigos.us/> |
|
7
|
|
|
* @author E. Alamo <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view |
|
10
|
|
|
* the LICENSE file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Da\User\Form; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
use Da\User\Helper\SecurityHelper; |
|
17
|
|
|
use Da\User\Model\User; |
|
18
|
|
|
use Da\User\Traits\ContainerAwareTrait; |
|
19
|
|
|
use Yii; |
|
20
|
|
|
use yii\base\Model; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class GdprDeleteForm |
|
24
|
|
|
* @package Da\User\Form |
|
25
|
|
|
*/ |
|
26
|
|
|
class GdprDeleteForm extends Model |
|
27
|
|
|
{ |
|
28
|
|
|
use ContainerAwareTrait; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string User's password |
|
32
|
|
|
*/ |
|
33
|
|
|
public $password; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var SecurityHelper |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $securityHelper; |
|
38
|
|
|
/** |
|
39
|
|
|
* @var User |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $user; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param SecurityHelper $securityHelper |
|
45
|
|
|
* @param array $config |
|
46
|
|
|
*/ |
|
47
|
1 |
|
public function __construct(SecurityHelper $securityHelper, $config = []) |
|
48
|
|
|
{ |
|
49
|
1 |
|
$this->securityHelper = $securityHelper; |
|
50
|
1 |
|
parent::__construct($config); |
|
51
|
1 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
*/ |
|
56
|
1 |
|
public function rules() |
|
57
|
|
|
{ |
|
58
|
|
|
return [ |
|
59
|
1 |
|
'requiredFields' => [['password'], 'required'], |
|
60
|
|
|
'passwordValidate' => [ |
|
61
|
1 |
|
'password', |
|
62
|
|
|
function ($attribute) { |
|
63
|
1 |
|
if (!$this->securityHelper |
|
64
|
1 |
|
->validatePassword($this->password, $this->getUser()->password_hash) |
|
|
|
|
|
|
65
|
|
|
) { |
|
66
|
1 |
|
$this->addError($attribute, Yii::t('usuario', 'Invalid password')); |
|
67
|
|
|
} |
|
68
|
1 |
|
}, |
|
69
|
|
|
] |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return User|null|\yii\web\IdentityInterface |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function getUser() |
|
77
|
|
|
{ |
|
78
|
1 |
|
if ($this->user == null) { |
|
79
|
1 |
|
$this->user = Yii::$app->user->identity; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
1 |
|
return $this->user; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
1 |
|
public function attributeLabels() |
|
86
|
|
|
{ |
|
87
|
|
|
return [ |
|
88
|
1 |
|
'password' => Yii::t('usuario', 'Password'), |
|
89
|
|
|
]; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: