1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace yrc\forms; |
4
|
|
|
|
5
|
|
|
use Base32\Base32; |
6
|
|
|
use Yii; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @class ChangeEmail |
10
|
|
|
* The form for validating the activation form |
11
|
|
|
*/ |
12
|
|
|
abstract class ChangeEmail extends \yii\base\Model |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* The new email to be changed |
16
|
|
|
* @var string $email |
17
|
|
|
*/ |
18
|
|
|
public $email; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The user's current password |
22
|
|
|
* @var string $password |
23
|
|
|
*/ |
24
|
|
|
public $password; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The user whose information we want to change |
28
|
|
|
* @var User $user |
|
|
|
|
29
|
|
|
*/ |
30
|
|
|
private $user; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Sets the user object |
34
|
|
|
* @param User $user |
35
|
|
|
*/ |
36
|
|
|
public function setUser($user) |
37
|
|
|
{ |
38
|
|
|
$this->user = $user; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Validation rules |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
public function rules() |
46
|
|
|
{ |
47
|
|
|
return [ |
48
|
|
|
[['email', 'password'], 'required'], |
49
|
|
|
[['email'], 'email'], |
50
|
|
|
[['email'], 'validateNewEmail'], |
51
|
|
|
[['password'], 'validatePassword'] |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Validates the email address |
57
|
|
|
* @inheritdoc |
58
|
|
|
*/ |
59
|
|
|
public function validateNewEmail($attributes, $params) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
if (!$this->hasErrors()) { |
62
|
|
|
if ($this->user === null) { |
63
|
|
|
throw new \yii\base\Exception('User object not set. Unable to proceed.'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if ($this->email === $this->user->email) { |
67
|
|
|
$this->addError('email', Yii::t('yrc', 'You cannot change your email to your current email address')); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if (!$this->hasErrors()) { |
71
|
|
|
// Clone the user object to verify the email can be set |
72
|
|
|
$mock = clone $this->user; |
73
|
|
|
$mock->email = $this->email; |
74
|
|
|
if (!$mock->validate()) { |
75
|
|
|
$this->addError('email', $mock->getFirstError('email')); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
unset($mock); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Validates the user's current password |
85
|
|
|
* @inheritdoc |
86
|
|
|
*/ |
87
|
|
|
public function validatePassword($attributes, $params) |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
if (!$this->hasErrors()) { |
90
|
|
|
if ($this->user === null) { |
91
|
|
|
throw new \Exception('User object not set. Unable to proceed.'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if (!$this->user->validatePassword($this->password)) { |
95
|
|
|
$this->addError('password', Yii::t('yrc', 'The provided password is not valid')); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Changes the user's email address |
102
|
|
|
* @return boolean |
103
|
|
|
*/ |
104
|
|
|
public function change() |
105
|
|
|
{ |
106
|
|
|
if ($this->validate()) { |
107
|
|
|
$oldEmail = $this->user->email; |
|
|
|
|
108
|
|
|
$this->user->email = $this->email; |
109
|
|
|
|
110
|
|
|
// Validation check |
111
|
|
|
if ($this->user->validate()) { |
112
|
|
|
if ($this->user->save()) { |
113
|
|
|
return true; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$this->addError('email', $this->user->getError('email')); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return false; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths