forked from meolu/walle-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventBootstrap.php
37 lines (32 loc) · 901 Bytes
/
EventBootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/**
* Created by PhpStorm.
* User: wushuiyong
* Date: 15/8/14
* Time: 下午5:41
*/
namespace app\components;
use Yii;
use yii\base\BootstrapInterface;
class EventBootstrap implements BootstrapInterface
{
public function bootstrap($app) {
$this->event();
}
public function event() {
Yii::$app->on(\yii\base\Application::EVENT_BEFORE_ACTION, function ($event) {
$aid = $event->action->id;
$cid = $event->action->controller->id;
if (Yii::$app->user->id) return true;
if ($cid == 'site') {
return true;
}
if (!Yii::$app->request->getIsAjax()) {
Yii::$app->response->redirect('site/login');
Yii::$app->end();
}
$event->isValid = false;
throw new \Exception(yii::t('w', 'need login'));
});
}
}