Completed
Push — master ( 9c0f6d...e28c7c )
by Alexey
37:38
created

ResetPasswordAction::trigger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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\events\ResetPasswordErrorEvent;
10
use yiicod\auth\events\ResetPasswordEvent;
11
12
class ResetPasswordAction extends Action
13
{
14
    const EVENT_BEFORE_RESET_PASSWORD = 'beforeResetPassword';
15
    const EVENT_AFTER_RESET_PASSWORD = 'afterResetPassword';
16
    const EVENT_ERROR_RESET_PASSWORD = 'errorResetPassword';
17
18
    public $view = '@yiicod/yii2-auth/views/webUser/resetPassword';
19
20
    public function run($token)
21
    {
22
        $model = null;
23
        $resetPasswordFormClass = Yii::$app->get('auth')->modelMap['resetPasswordForm']['class'];
24
25
        Event::trigger(self::class, static::EVENT_BEFORE_RESET_PASSWORD, new ResetPasswordEvent($this, $model, ['sender' => $this]));
26
        try {
27
            $model = new $resetPasswordFormClass($token);
28
        } catch (InvalidParamException $e) {
29
            Event::trigger(self::class, static::EVENT_ERROR_RESET_PASSWORD, new ResetPasswordErrorEvent($this, $token, $e, ['sender' => $this]));
30
        }
31
32
        if ($model instanceof $resetPasswordFormClass &&
33
            $model->load(Yii::$app->request->post()) &&
34
            $model->validate() &&
35
            $model->resetPassword()
36
        ) {
37
            Event::trigger(self::class, static::EVENT_AFTER_RESET_PASSWORD, new ResetPasswordEvent($this, $model, ['sender' => $this]));
38
        }
39
40
        return $this->controller->render($this->view, [
41
            'model' => $model,
42
        ]);
43
    }
44
45
//    public function trigger($name, Event $event = null)
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
//    {
47
//        Yii::$app->trigger(sprintf('yiicod.auth.actions.webUser.ResetPasswordAction.%s', $name), $event);
48
49
//        return parent::trigger($name, $event);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
//    }
51
}
52