ResetPasswordAction   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 23 6
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
        $resetPasswordFormClass = Yii::$app->get('auth')->modelMap['resetPasswordForm']['class'];
23
24
        Event::trigger(self::class, static::EVENT_BEFORE_RESET_PASSWORD, new ResetPasswordEvent($this, $token, ['sender' => $this]));
25
        try {
26
            $model = new $resetPasswordFormClass($token);
27
        } catch (InvalidParamException $e) {
28
            Event::trigger(self::class, static::EVENT_ERROR_RESET_PASSWORD, new ResetPasswordErrorEvent($this, $token, $e, ['sender' => $this]));
29
        }
30
31
        if ($model instanceof $resetPasswordFormClass &&
32
            $model->load(Yii::$app->request->post()) &&
33
            $model->validate() &&
34
            $model->resetPassword()
35
        ) {
36
            Event::trigger(self::class, static::EVENT_AFTER_RESET_PASSWORD, new ResetPasswordEvent($this, $model, ['sender' => $this]));
37
        }
38
39
        return $this->controller->render($this->view, [
40
            'model' => $model,
41
        ]);
42
    }
43
}
44