FrontEndAuthFilter.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace app\common\filters;
  3. use Yii;
  4. use yii\base\ActionFilter;
  5. class FrontEndAuthFilter extends ActionFilter
  6. {
  7. public function beforeAction($action)
  8. {
  9. //未登录或COOKIE认证失败
  10. $identityInfo = Yii::$app->controller->getIdentityInfo();
  11. if(defined('IN_WAP')&&IN_WAP==TRUE)
  12. {
  13. $loginUrl = \app\common\components\SiteUrl::loginhome();
  14. }
  15. else
  16. {
  17. $loginUrl = \app\common\components\SiteUrl::login();
  18. }
  19. if(!empty($identityInfo)&&is_array($identityInfo))
  20. {
  21. if(sys_auth($identityInfo['cookieHash'],'DECODE')!=$identityInfo['user_name'])
  22. {
  23. Yii::$app->controller->showMessage(array('class'=>'warning','message'=>'您还没有登录,请先登录!','url'=>$loginUrl,'time'=>0));
  24. return false;
  25. }
  26. }
  27. else
  28. {
  29. Yii::$app->controller->showMessage(array('class'=>'warning','message'=>'您还没有登录,请先登录!','url'=>$loginUrl,'time'=>0));
  30. return false;
  31. }
  32. return true;
  33. }
  34. }