Total Complexity | 7 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
15 | class ChangePassword extends Model |
||
16 | { |
||
17 | public $oldPassword; |
||
18 | public $newPassword; |
||
19 | public $retypePassword; |
||
20 | |||
21 | /** |
||
22 | * @inheritdoc |
||
23 | */ |
||
24 | public function rules() |
||
25 | { |
||
26 | return [ |
||
27 | [['oldPassword', 'newPassword', 'retypePassword'], 'required'], |
||
28 | [['oldPassword'], 'validatePassword'], |
||
29 | [['newPassword'], 'string', 'min' => 6], |
||
30 | [['retypePassword'], 'compare', 'compareAttribute' => 'newPassword'], |
||
31 | ]; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Validates the password. |
||
36 | * This method serves as the inline validation for password. |
||
37 | */ |
||
38 | public function validatePassword() |
||
39 | { |
||
40 | /* @var $user User */ |
||
41 | $user = Yii::$app->user->identity; |
||
42 | if (!$user || !$user->validatePassword($this->oldPassword)) { |
||
|
|||
43 | $this->addError('oldPassword', 'Incorrect old password.'); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Change password. |
||
49 | * |
||
50 | * @return User|null the saved model or null if saving fails |
||
51 | */ |
||
52 | public function change() |
||
65 | } |
||
66 | } |
||
67 |