Example #1
0
 public function log($message, $type, $args = array())
 {
     $errorTypes = array(\Phalcon\Logger::WARNING, \Phalcon\Logger::ERROR, \Phalcon\Logger::ALERT, \Phalcon\Logger::CRITICAL, \Phalcon\Logger::EMERGENCE);
     if (in_array($type, $errorTypes, true)) {
         $this->logger = new \Phalcon\Logger\Adapter\File($this->filepath . ".wf");
     } else {
         $this->logger = new \Phalcon\Logger\Adapter\File($this->filepath);
     }
     $trace = debug_backtrace();
     $depth = count($trace) > 1 ? 1 : 0;
     $current = $trace[$depth];
     $file = basename($current['file']);
     $line = $current['line'];
     $ip = \BullSoft\Utility::getIP();
     unset($trace, $current);
     $message = preg_replace_callback('/%(\\w+)%/', function ($matches) use($file, $line, $ip, $message) {
         return ${$matches[1]};
     }, $this->template);
     if (!empty($args)) {
         if ((bool) getDI()->get('config')->application->debug) {
             $message .= PHP_EOL;
             foreach ($args as $arg) {
                 $message .= $this->logVar($arg);
             }
         } else {
             foreach ($args as $arg) {
                 $message .= ' ||| ';
                 $message .= json_encode($arg);
             }
         }
     }
     $this->logger->log($message, $type);
 }
 public function userInfo()
 {
     if (!$this->session->has(self::BULL_SOCIAL_SESSION_KEY)) {
         return false;
     }
     $socialCookie = $this->session->get(self::BULL_SOCIAL_SESSION_KEY);
     $socialOAuth = json_decode($socialCookie, true);
     $request = new \Buzz\Message\Request();
     $request->setHost("https://openapi.baidu.com");
     $request->setResource("/social/api/2.0/user/info?access_token=" . $socialOAuth['access_token']);
     $response = new \Buzz\Message\Response();
     $client = $this->getCurlClient();
     $client->send($request, $response);
     if (!$response->isOk()) {
         return false;
     }
     $socialUser = json_decode($response->getContent(), true);
     if (count($socialUser) < 3) {
         return false;
     }
     $socialUserModel = SocialUserModel::findFirst('social_uid=' . intval($socialUser['social_uid']));
     $time = date('Y-m-d H:i:s');
     if (empty($socialUserModel)) {
         $socialUserModel = new SocialUserModel();
         $socialUserModel->assign($socialUser);
         if ($socialUserModel->save() == false) {
             // foreach ($socialUserModel->getMessages() as $message) {
             // echo $message. "<br />";
             // }
             return false;
         }
     }
     if ($socialUserModel->user_id > 0) {
         $this->session->set('identity', $socialUserModel->user_id);
         return true;
     }
     try {
         $this->db->begin();
         $userModel = new UserModel();
         $userModel->username = '******' . \BullSoft\Utility::generateRandomString(8);
         $userModel->nickname = $socialUser['username'];
         $userModel->password = \BullSoft\Utility::generateRandomString();
         $userModel->photo = $socialUser['tinyurl'];
         $userModel->email = \BullSoft\Utility::generateRandomString(32) . "@";
         $userModel->level = 1;
         $userModel->is_active = 'N';
         $userModel->active_code = \BullSoft\Utility::generateRandomString(32);
         $userModel->addtime = $time;
         $userModel->modtime = $time;
         if ($userModel->save() == false) {
             /* foreach ($userModel->getMessages() as $message) { */
             /*     echo $message. "<br />"; */
             /* } */
             $this->db->rollback("不能保存用户!");
         }
         $socialUserModel->user_id = $userModel->id;
         if ($socialUserModel->save() == false) {
             /* foreach ($socialUserModel->getMessages() as $message) { */
             /*     echo $message. "<br />"; */
             /* } */
             $this->db->rollback("不能保存用户!");
         }
         $this->session->set('identity', $userModel->id);
         $this->db->commit();
     } catch (\Exception $e) {
         $this->db->rollback();
     }
     return true;
 }