Completed
Push — master ( 6ff6d1...70482c )
by Alexey
02:17
created

ResetPasswordAction::run()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
c 0
b 0
f 0
rs 8.439
cc 6
eloc 18
nc 4
nop 1
1
<?php
2
3
namespace yiicod\auth\actions\webUser;
4
5
use Yii;
6
use yii\base\Action;
7
use yii\base\Event;
8
use yii\base\InvalidParamException;
9
use yiicod\auth\actions\ActionEvent;
10
11
class ResetPasswordAction extends Action
12
{
13
    const EVENT_BEFORE_RESET_PASSWORD = 'beforeResetPassword';
14
    const EVENT_AFTER_RESET_PASSWORD = 'afterResetPassword';
15
    const EVENT_ERROR_RESET_PASSWORD = 'errorResetPassword';
16
17
    public $view = '@yiicod/yii2-auth/views/webUser/resetPassword';
18
19
    public function run($token)
20
    {
21
        $model = null;
22
        $resetPasswordFormClass = Yii::$app->get('auth')->modelMap['resetPasswordForm']['class'];
23
24
        $this->trigger(static::EVENT_BEFORE_RESET_PASSWORD, new ActionEvent($this, ['params' => ['model' => $model]]));
25
        try {
26
            $model = new $resetPasswordFormClass($token);
27
        } catch (InvalidParamException $e) {
1 ignored issue
show
Bug introduced by
The class yii\base\InvalidParamException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
28
            $this->trigger(static::EVENT_ERROR_RESET_PASSWORD, new ActionEvent($this, [
29
                'params' => [
30
                    'token' => $token,
31
                    'e' => $e
32
                ]
33
            ]));
34
        }
35
36
        if ($model instanceof $resetPasswordFormClass &&
37
            $model->load(Yii::$app->request->post()) &&
38
            $model->validate() &&
39
            $model->resetPassword()
40
        ) {
41
            $this->trigger(static::EVENT_AFTER_RESET_PASSWORD, new ActionEvent($this, ['params' => ['model' => $model]]));
42
        }
43
44
        return $this->controller->render($this->view, [
45
            'model' => $model,
46
        ]);
47
    }
48
49
    public function trigger($name, Event $event = null)
50
    {
51
        Yii::$app->trigger(sprintf('yiicod.auth.actions.webUser.ResetPasswordAction.%s', $name), $event);
52
        return parent::trigger($name, $event);
53
    }
54
}
55