Example #1
0
 /**
  * 获取配置项
  *
  * @return void
  * @author
  **/
 public static function get_config()
 {
     // Cache
     $cache = Yii::$app->cache;
     $data = $cache->get("config/get_config");
     if ($data === false) {
         $data = Config::find()->select(['config_name', 'config_value'])->asArray()->all();
         $data = ['Config' => ArrayHelper::map($data, 'config_name', 'config_value')];
         $data['Config']['platform_info'] = WechatPlatform::getInfo($data['Config']['site_platform']);
         $cache->set("config/get_config", $data);
     }
     $model = new Config();
     $model->load($data);
     return $model;
 }
 /**
  * 初始化方法
  *
  * @return void
  * @author
  **/
 public function init()
 {
     $this->on('beforeAction', function ($event) {
         $deny_uri = ['login', 'js-config', 'registercode', 'findpasswordcode', 'findpasswordcode', 'get-area', 'find-pass'];
         if (Yii::$app->getUser()->isGuest) {
             $request = Yii::$app->getRequest();
             if (!($request->getIsAjax() || $this->_search_values($deny_uri, $request->getUrl()))) {
                 Yii::$app->getUser()->setReturnUrl($request->getUrl());
             }
         }
     });
     // View
     Event::on(View::className(), View::EVENT_BEFORE_RENDER, function () {
         Yii::$app->view->params['global_user'] = $this->get_user();
         Yii::$app->view->params['global_config'] = Config::get_config();
         Yii::$app->view->title = $this->config->site_title;
     });
 }
Example #3
0
 /**
  * 更新平台的Token配置项目
  *
  * @return void
  * @author
  **/
 public function updatePfToken($xml = null, $force = false)
 {
     // Xml
     $xml = $xml ?: $this->getLatestTicket();
     // 清除所有Token缓存
     if ($force) {
         $this->wechat->clearCache();
     }
     // Ticket
     $ticket = $this->wechat->getVerifyTicket($xml, false);
     $query = Yii::$app->db->createCommand()->update('{{%wechat_platform}}', ['component_verify_ticket' => $ticket, 'updated_at' => time()], ['pf_id' => $this->pf_id])->execute();
     // Access token
     $access_token = $this->wechat->getComponentAccessToken();
     if ($this->pf_info->component_access_token != $access_token) {
         Yii::$app->db->createCommand()->update('{{%wechat_platform}}', ['component_access_token' => $access_token, 'updated_at' => time()], ['pf_id' => $this->pf_id])->execute();
     }
     // Auth code
     $pre_auth_code = $this->wechat->getPreAuthCode();
     if ($this->pf_info->pre_auth_code != $pre_auth_code) {
         Yii::$app->db->createCommand()->update('{{%wechat_platform}}', ['pre_auth_code' => $pre_auth_code, 'updated_at' => time()], ['pf_id' => $this->pf_id])->execute();
     }
     if ($query) {
         // 清除配置文件缓存
         Config::clearCache();
         return true;
     }
 }
Example #4
0
 /**
  * undocumented function
  *
  * @return void
  * @author
  **/
 public function actionSignup()
 {
     if (Yii::$app->user->getIsGuest()) {
         $model = new Service();
         $mConfig = new Config();
         $signup_status = 'invite';
         switch ($mConfig->getConfigValue(Config::SIGNUP_STATUS)) {
             //注册状态
             case Config::SIGNUP_OPEN:
                 $signup_status = 'signup';
                 break;
             case Config::SIGNUP_INVITE:
                 $signup_status = 'invite';
                 break;
             default:
                 Yii::$app->session->setFlash('error', '已关闭注册!');
                 return $this->redirect('signin');
                 break;
         }
         $model->setScenario($signup_status);
         if ($model->load($params = Yii::$app->request->post()) && $model->save()) {
             //邀请码处理
             $serviceInfo = $params['Service'];
             if (isset($serviceInfo['invite']) && $serviceInfo['invite']) {
                 $mInvite = Invite::findOne(['invite_code' => $serviceInfo['invite'] ?: NUll]);
                 $invite['Invite'] = ['invite_service_id' => $model->service_id, 'invite_username' => $model->service_username, 'invite_mobile' => $model->service_mobile, 'invite_active' => 1, 'updated_at' => time()];
                 $mInvite->load($invite);
                 $mInvite->save();
             }
             //注册成功默认角色
             $auth = Yii::$app->authManager;
             $authorRole = $auth->getRole('service');
             $auth->assign($authorRole, $model->service_id);
             Yii::$app->session->setFlash('success', '您已成功注册,请登录!');
             return $this->redirect('signin');
         } else {
             return $this->render('signup', ['model' => $model, 'signup_status' => $signup_status]);
         }
     } else {
         return $this->redirect(['admin/index']);
     }
 }