Esempio n. 1
0
 public function __construct($id, $module, $config = [])
 {
     $this->post = Yii::$app->request->post();
     // 加载数据库配置
     \Yii::$app->params['category'] = Config::article_category();
     \Yii::$app->params['tag'] = Config::article_tag();
     parent::__construct($id, $module, $config = []);
 }
 public function actionConfigClass()
 {
     if (is_array(Config::article_category())) {
         echo "Config::article_category()测试通过\n";
     }
     if (is_array(Config::article_tag())) {
         echo "Config::article_tag()测试通过\n";
     }
 }
Esempio n. 3
0
 public function __construct($id, $module, $config = [])
 {
     //用户是否登录判断
     if (isset($_COOKIE['LoginKey'])) {
         $cookie = $_COOKIE['LoginKey'];
         //LoginKey是登录凭证
         $sql = "select * from user where cookie = '{$cookie}'";
         $res = \Yii::$app->db->createCommand($sql)->queryAll();
         if ($res) {
             Yii::$app->view->params['user'] = $res[0];
             //已经登录用户,保存用户信息
         }
     }
     // 加载数据库配置
     \Yii::$app->params['category'] = Config::article_category();
     \Yii::$app->params['tag'] = Config::article_tag();
     parent::__construct($id, $module, $config = []);
 }
Esempio n. 4
0
 public function beforeAction($action)
 {
     //判断管理员是否登录
     //登录后的管理员会在客户端存下 access_token
     //该access_token 与 Cache里面的 admin_login 比对下,正确就是已登录管理员
     if ('/site/login.html' != $_SERVER['REQUEST_URI']) {
         if (!isset($_COOKIE['access_token'])) {
             header("Location:/site/login.html");
             exit;
         }
         // 暂时先注释掉,只要有access_token就可以登录了
         // 			$access_token = Cache::get('admin_login');
         // 			if($_COOKIE['access_token']!= $access_token){
         // 				header("Location:/site/login.html");
         // 				exit();
         // 			}
     }
     // 加载数据库配置
     \Yii::$app->params['category'] = Config::article_category();
     \Yii::$app->params['tag'] = Config::article_tag();
     $this->post_data = \Yii::$app->request->post();
 }
Esempio n. 5
0
 public function __construct($id, $module, $config = [])
 {
     $user = '';
     // 变量,数组,用户
     do {
         if (isset($_COOKIE['LoginKey'])) {
             $cookie = $_COOKIE['LoginKey'];
             debug($cookie, 'cookie');
             $sql = "select * from user where cookie = '{$cookie}'";
             $res = \Yii::$app->db->createCommand($sql)->queryAll();
             // 用户已经登录,跳出用户相关业务逻辑
             if ($res) {
                 Yii::$app->view->params['user'] = $res[0];
                 //已经登录用户,保存用户信息
                 break;
             }
         }
         //用户未登录,判断是否微信端
         //用户不使用微信
         if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === false) {
             break;
         }
         //用户使用微信
         $go_to_weixin = $this->actionGetWeixinCode();
         //用户打开mobile端,跳转到微信获取授权
         if (!isset($_GET['state'])) {
             header("location:{$go_to_weixin}");
             exit;
         }
         //微信用户授权后跳转回mobile端
         //未授权
         if (!isset($_GET['code'])) {
             //以游客身份登录?
             //提醒用户必须授权,不授权不让用
             break;
         }
         //已授权
         //获取特殊的获取用户信息的access_token
         $res = $this->_get_weixin_user_access_token($_GET['code']);
         //获取特殊access_token失败
         if (isset($res->errcode)) {
             debug("get access_token fail");
             break;
         }
         //获取成功
         //获取用户信息
         $userinfo = $this->_get_weixin_user_info($res);
         //获取用户信息失败
         if (!isset($userinfo->nickname)) {
             break;
         }
         // 已注册用户
         // 通过openid判断该用户是否是已经
         $user = User::find()->where("openid = '{$userinfo->openid}'")->one();
         //新注册用户
         if (!$user) {
             $user = new User();
             $user->openid = $userinfo->openid;
             $user->nickname = $userinfo->nickname;
             $user->sex = $userinfo->sex;
             $user->city = $userinfo->city;
             $user->province = $userinfo->province;
             $user->avatar = $userinfo->headimgurl;
             $user->register_time = date("Y-m-d H:i:s", time());
             $user->status = 0;
             $user->type = 0;
         }
         $user->cookie = User::Generate_cookie_key();
         // 用户保存失败
         $user->save();
         // 给前端发送秘钥
         $user = User::find()->where("id = '{$user->id}'")->asArray()->one();
         setCookie('LoginKey', $user['cookie'], time() + 3600);
         //已经登录用户,保存用户信息
         Yii::$app->view->params['user'] = $user;
     } while (false);
     // 使用微信js_sdk
     $this->use_js_sdk();
     // 加载数据库配置
     \Yii::$app->params['category'] = Config::article_category();
     \Yii::$app->params['tag'] = Config::article_tag();
     parent::__construct($id, $module, $config = []);
 }