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)); }