Issues (75)

app/Http/Api/Backend/Form/ChangePasswordForm.php (1 issue)

Labels
Severity
1
<?php
2
namespace App\Http\Api\Backend\Form;
3
4
use common\validators\PasswordValidator;
0 ignored issues
show
The type common\validators\PasswordValidator was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use Yii;
6
7
class ChangePasswordForm extends UserForm
8
{
9
    /**
10
     * @var string $password current password.
11
     */
12
    public $password;
13
14
    /**
15
     * @var string $new_password new password.
16
     */
17
    public $new_password;
18
19
    public function rules()
20
    {
21
        return array_merge(parent::rules(), [
22
            [['password', 'new_password'], 'trim'],
23
            [['password', 'new_password'], 'required'],
24
            [['password', 'new_password'], 'string'],
25
            ['password', 'validatePassword'],
26
            ['new_password', 'compare', 'compareAttribute' => 'password', 'operator' => '!='],
27
            ['new_password', PasswordValidator::class],
28
        ]);
29
    }
30
31
    public function validatePassword($attribute)
32
    {
33
        $user = $this->getUser();
34
        if (!$user || !$user->validatePassword($this->$attribute)) {
35
            $this->addError($attribute, Yii::t('app', 'Original password is incorrect'));
36
        }
37
    }
38
39
    protected function handleInternal()
40
    {
41
        $user = $this->getUser();
42
        $user->setPassword($this->new_password);
43
        if (!$user->save()) {
44
            Yii::error($user->getErrors());
45
            throw new \RuntimeException('Unable to change password');
46
        }
47
    }
48
}
49