public function payPayeer($params = array()) { if (empty($this->params)) { $this->params = $params; } $params = $this->params; if (isset($params['m_operation_id']) && isset($params['m_sign'])) { $m_key = self::PAYEER_SECRET; $arHash = array($params['m_operation_id'], $params['m_operation_ps'], $params['m_operation_date'], $params['m_operation_pay_date'], $params['m_shop'], $params['m_orderid'], $params['m_amount'], $params['m_curr'], $params['m_desc'], $params['m_status'], $m_key); $sign_hash = strtoupper(hash('sha256', implode(':', $arHash))); if ($params['m_sign'] == $sign_hash && $params['m_status'] == 'success') { if (empty($params['m_orderid'])) { return; } $m_orderid = $params['m_orderid']; list($user_id, $salt) = explode('_', $m_orderid); $user = new User($this->db); $user->allocateUserById(intval($user_id)); $subscription_days = $this->getSubDaysByAmount(intval($params['m_amount'])); $user->addDaysToSubscription($subscription_days); $this->db->query("INSERT INTO `payments` (operation_id, user_id, amount, datetime, sender, label, days)\n VALUES(?i, ?i, '{$params['m_amount']}', ?s, ?s, ?s, ?i)", $params['m_operation_id'], $user->getId(), $params['m_operation_pay_date'], 'payeer:' . $params['m_operation_ps'], $params['m_orderid'] . '.' . $params['m_curr'], $subscription_days); $this->db->query("COMMIT"); $this->success = true; } } }
public function check() { $key = !empty($_SESSION['ts_sid']) ? $_SESSION['ts_sid'] : !1; if (!$key) { $cookies = Application::$request_variables['cookie']; $cookie_key = !empty($cookies['ts_sid']) ? $cookies['ts_sid'] : !1; if ($cookie_key) { $key_manager = new KeyManager(); list($user_id, $access_key) = $key_manager->getPair($cookie_key); if (!is_numeric($user_id)) { $this->removeCookie('ts_sid'); return; } $user = new User($this->db); $user->allocateUserById($user_id); if (!$user->accessKeyExists($access_key)) { $this->removeCookie('ts_sid'); return; } $this->setSession('ts_sid', $cookie_key); $this->user_row = $user->getObject(); $this->result = !$user->isEmpty(); } } else { $key_manager = new KeyManager(); $user_id = $key_manager->getPair($key)[0]; $user = new User($this->db); $user->allocateUserById($user_id); $this->user_row = $user->getObject(); $this->result = !$user->isEmpty(); } if ($this->result) { $user = new User($this->db, $this->user_row); if ($user->hasSubscription()) { setcookie('hs_sid', $this->generateCode(), time() + 365 * 24 * 3600, '/', 'twosphere.ru'); } else { if (isset($_COOKIE['hs_sid'])) { setcookie('hs_sid', '', 0, '/', 'twosphere.ru'); } } } }
public function run($method, $params) { $this->params = $params[$this->request_type]; $api_user = $this->getApiUser($this->params); $user = new User($this->db); $user->allocateUserById($api_user['user_id']); if (!$user->hasSubscription() && !in_array($method, self::$methods_without_sub)) { throw new NoSubscriptionException($this->params); } $microtime = microtime(true); if ($this->isBannedUser($api_user) && $this->expiredBanUser($api_user)) { $this->unbanUser($api_user); } if (!$this->isBannedUser($api_user)) { if ($api_user['recent_activity'] + self::DEFAULT_PERIOD >= $microtime) { $api_user['recent_count_activity']++; } else { $api_user['recent_count_activity'] = 1; $api_user['recent_activity'] = $microtime; $this->clearUserState($api_user); } if ($api_user['recent_count_activity'] > self::DEFAULT_MAX_QUERIES) { $api_user['ban'] = !0; $api_user['unlock_time'] = time() + self::DEFAULT_BAN_TIME; $this->banUser($api_user); } else { $this->incrementUserCountActivity($api_user); } if (!$this->isBannedUser($api_user)) { $this->updateUserStats($api_user, $method); $this->params['user'] = $user; $methods = new RequestHandler($this->db); return array("response" => $methods->{$method}($this->params)); } else { throw new TooManyRequestException($this->params, $api_user['unlock_time']); } } else { throw new TooManyRequestException($this->params, $api_user['unlock_time']); } }
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; }
public function getUser() { $user_vk_id = $this->vk_object['id']; $user = new User($this->db); $user->allocateUserByVkId($user_vk_id); return $user; }