コード例 #1
0
ファイル: Authorization.php プロジェクト: Kangaro97/PalmUp
 public function signIn()
 {
     $auth_model = new AuthorizationModel($this->db);
     $user_object = array('domain' => empty($this->data['domain']) ? 'id' . $this->data['id'] : $this->data['domain'], 'first_name' => empty($this->data['first_name']) ? ' ' : $this->data['first_name'], 'href' => empty($this->data['href']) ? 'http://vk.com' : $this->data['href'], 'id' => $this->data['id'], 'last_name' => empty($this->data['last_name']) ? ' ' : $this->data['last_name'], 'photo' => empty($this->data['photo']) ? ' ' : $this->data['photo']);
     foreach ($user_object as $value) {
         if (empty($value)) {
             return;
         }
     }
     $auth_model->setUserObject($user_object);
     $auth_model->auth();
     $result = $auth_model->getResult();
     if ($result) {
         $user = new User($this->db);
         $user->allocateUserByVkId(intval($user_object['id']));
         $key_manager = new KeyManager();
         $access_key = $this->generateKey();
         $key = $key_manager->createKey($user->getId(), $access_key);
         $user->addAccessKey($access_key);
         $this->setCookie('ts_sid', $key, time() + 365 * 24 * 3600, '/', 'twosphere.ru');
         $this->setSession('ts_sid', $key);
     }
     $this->result = $result;
 }
コード例 #2
0
ファイル: ApiManager.php プロジェクト: Kangaro97/PalmUp
 protected function createAccessToken($params)
 {
     $params = $params['request'];
     $time = time();
     $vk_access_token = $params['vk_access_token'];
     $auth = new AuthorizationModel($this->db);
     $auth->toggleApi();
     $auth->setAuthParams(array('access_token' => $vk_access_token));
     $auth->auth();
     $result = $auth->getResult();
     if (!$result) {
         throw new InvalidVkAccessTokenException($params);
     }
     $user = $auth->getUser();
     $too_many_requests = $this->db->query("SELECT * FROM `api_users` WHERE `creation_time` + " . self::DEFAULT_BAN_TIME_TOKEN . " > ?i AND `user_id` = ?i", $time, $user->getId());
     if ($too_many_requests->num_rows) {
         throw new TooManyCreaturesTokenException($params);
     }
     $access_token = $this->createRandomToken();
     $this->db->query("INSERT INTO `api_users` (`user_id`, `access_token`, `creation_time`, `creation_ip`) VALUES (?i, ?s, ?i, ?s)", $user->getId(), $access_token, $time, $_SERVER['REMOTE_ADDR']);
     return array("response" => array("access_token" => $access_token));
 }