123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace app\common\filters;
- use Yii;
- use yii\base\ActionFilter;
- class BackEndAuthFilter extends ActionFilter
- {
- public function beforeAction($action)
- {
- //未登录或COOKIE认证失败
- $identityInfo = Yii::$app->controller->getIdentityInfo();
- if($identityInfo=='token'){
- Yii::$app->controller->showMessage(array('class'=>'warning','message'=>Yii::t('admin','please login backend system'),'url'=>'','time'=>300000));
- return false;
- }
- if(!empty($identityInfo)&&is_array($identityInfo))
- {
- if(sys_auth($identityInfo['cookieHash'],'DECODE')!=$identityInfo['user_name'])
- {
- Yii::$app->controller->showMessage(array('class'=>'warning','message'=>Yii::t('admin','please login backend system'),'url'=>Yii::$app->controller->createRealUrl('admin/default/login'),'time'=>3000));
- return false;
- }
- }
- else
- {
- Yii::$app->controller->showMessage(array('class'=>'warning','message'=>Yii::t('admin','please login backend system'),'url'=>Yii::$app->controller->createRealUrl('admin/default/login'),'time'=>3000));
- return false;
- }
- return true;
- }
- }
|