BackEndAuthFilter.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace app\common\filters;
  3. use Yii;
  4. use yii\base\ActionFilter;
  5. class BackEndAuthFilter extends ActionFilter
  6. {
  7. public function beforeAction($action)
  8. {
  9. //未登录或COOKIE认证失败
  10. $identityInfo = Yii::$app->controller->getIdentityInfo();
  11. if($identityInfo=='token'){
  12. Yii::$app->controller->showMessage(array('class'=>'warning','message'=>Yii::t('admin','please login backend system'),'url'=>'','time'=>300000));
  13. return false;
  14. }
  15. if(!empty($identityInfo)&&is_array($identityInfo))
  16. {
  17. if(sys_auth($identityInfo['cookieHash'],'DECODE')!=$identityInfo['user_name'])
  18. {
  19. 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));
  20. return false;
  21. }
  22. }
  23. else
  24. {
  25. 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));
  26. return false;
  27. }
  28. return true;
  29. }
  30. }