@@ 10-50 (lines=41) @@ | ||
7 | use yii\base\Event; |
|
8 | use yiicod\auth\actions\ActionEvent; |
|
9 | ||
10 | class LoginAction extends Action |
|
11 | { |
|
12 | const EVENT_BEFORE_LOGIN = 'beforeLogin'; |
|
13 | const EVENT_AFTER_LOGIN = 'afterLogin'; |
|
14 | const EVENT_ERROR_LOGIN = 'errorLogin'; |
|
15 | ||
16 | public $view = '@yiicod/yii2-auth/views/webUser/login'; |
|
17 | ||
18 | /** |
|
19 | * Model scenario |
|
20 | * @var |
|
21 | */ |
|
22 | public $scenario; |
|
23 | ||
24 | public function run() |
|
25 | { |
|
26 | $loginFormClass = Yii::$app->get('auth')->modelMap['loginForm']['class']; |
|
27 | $model = new $loginFormClass($this->scenario); |
|
28 | ||
29 | $isLoad = $model->load(Yii::$app->request->post()); |
|
30 | ||
31 | $this->trigger(static::EVENT_BEFORE_LOGIN, new ActionEvent($this, ['params' => ['model' => $model]])); |
|
32 | ||
33 | if ($isLoad) { |
|
34 | if ($model->login()) { |
|
35 | $this->trigger(static::EVENT_AFTER_LOGIN, new ActionEvent($this, ['params' => ['model' => $model]])); |
|
36 | } else { |
|
37 | $this->trigger(static::EVENT_ERROR_LOGIN, new ActionEvent($this, ['params' => ['model' => $model]])); |
|
38 | } |
|
39 | } |
|
40 | return $this->controller->render($this->view, [ |
|
41 | 'model' => $model, |
|
42 | ]); |
|
43 | } |
|
44 | ||
45 | public function trigger($name, Event $event = null) |
|
46 | { |
|
47 | Yii::$app->trigger(sprintf('yiicod.auth.actions.webUser.LoginAction.%s', $name), $event); |
|
48 | return parent::trigger($name, $event); |
|
49 | } |
|
50 | } |
|
51 |
@@ 10-53 (lines=44) @@ | ||
7 | use yii\base\Event; |
|
8 | use yiicod\auth\actions\ActionEvent; |
|
9 | ||
10 | class RequestPasswordResetAction extends Action |
|
11 | { |
|
12 | const EVENT_AFTER_REQUEST_PASSWORD_RESET = 'afterRequestPasswordReset'; |
|
13 | const EVENT_BEFORE_REQUEST_PASSWORD_RESET = 'beforeRequestPasswordReset'; |
|
14 | const EVENT_ERROR_REQUEST_PASSWORD_RESET = 'errorRequestPasswordReset'; |
|
15 | ||
16 | public $view = '@yiicod/yii2-auth/views/webUser/requestPasswordResetToken'; |
|
17 | ||
18 | /** |
|
19 | * Model scenario |
|
20 | * @var |
|
21 | */ |
|
22 | public $scenario; |
|
23 | ||
24 | public function run() |
|
25 | { |
|
26 | $passwordResetRequestFormClass = Yii::$app->get('auth')->modelMap['passwordResetRequestForm']['class']; |
|
27 | $model = new $passwordResetRequestFormClass($this->scenario); |
|
28 | ||
29 | $isLoad = $model->load(Yii::$app->request->post()); |
|
30 | ||
31 | $this->trigger(static::EVENT_BEFORE_REQUEST_PASSWORD_RESET, new ActionEvent($this, ['params' => ['model' => $model]])); |
|
32 | ||
33 | if ($isLoad) { |
|
34 | if ($model->validate()) { |
|
35 | if ($model->resetPassword()) { |
|
36 | $this->trigger(static::EVENT_AFTER_REQUEST_PASSWORD_RESET, new ActionEvent($this, ['params' => ['model' => $model]])); |
|
37 | } else { |
|
38 | $this->trigger(static::EVENT_ERROR_REQUEST_PASSWORD_RESET, new ActionEvent($this, ['params' => ['model' => $model]])); |
|
39 | } |
|
40 | } |
|
41 | } |
|
42 | ||
43 | return $this->controller->render($this->view, [ |
|
44 | 'model' => $model, |
|
45 | ]); |
|
46 | } |
|
47 | ||
48 | public function trigger($name, Event $event = null) |
|
49 | { |
|
50 | Yii::$app->trigger(sprintf('yiicod.auth.actions.webUser.RequestPasswordResetAction.%s', $name), $event); |
|
51 | return parent::trigger($name, $event); |
|
52 | } |
|
53 | } |
|
54 |