Example #1
0
 /**
  * on dispatch before hook
  * 
  * @param Request $request
  * @param Response $response
  */
 public static function on_dispatch_before(Request $request, Response $response)
 {
     // 检查q是否在白名单中
     $loginIgnore = false;
     $q = $request->q();
     if (!empty($q)) {
         foreach (self::$loginWhiteList as $key) {
             if (SimPHP::qMatchPattern($key, $q)) {
                 $loginIgnore = true;
                 break;
             }
         }
     }
     // 检查登录状态
     if (!$loginIgnore && !Member::isLogined()) {
         import('user/*');
         $user_Controller = new User_Controller();
         $user_Controller->login($request, $response);
         exit;
     }
     //读取最新用户信息以客户端缓存
     global $user;
     if ($user->uid) {
         $uinfo = Member::getTinyInfoByUid($user->uid, FALSE);
         $user->openid = $uinfo['openid'];
         $user->unionid = $uinfo['unionid'];
         $user->subscribe = $uinfo['subscribe'];
         $user->username = $uinfo['username'];
         $user->nickname = $uinfo['nickname'];
         $user->sex = $uinfo['sex'];
         $user->logo = $uinfo['logo'];
         //$user->ec_user_id= $uinfo['ec_user_id'];
         /*
         if (!$request->is_hashreq()) { //不是hash request,则查看购物车是否有商品
           $cartNum = Goods::getUserCartNum($user->ec_user_id);
           $user->ec_cart_num = $cartNum;
         }
         */
     }
 }
Example #2
0
 /**
  * Check q & menu pattern whether match
  * 
  * @param string $pattern
  * @param string $q
  * @return boolean
  */
 public static function qMatchPattern($pattern, $q = NULL)
 {
     if (!isset($q)) {
         $q = Request::q();
     }
     $match = false;
     if ($pattern == $q) {
         $match = true;
     } else {
         if (preg_match(SimPHP::genMenuRegexp($pattern), $q)) {
             $match = true;
         }
     }
     return $match;
 }