Example #1
0
 /**
  * @param $user User
  */
 public function logout($user)
 {
     $key_manager = new KeyManager();
     list($user_id, $access_key) = $key_manager->getPair($_SESSION['ts_sid']);
     $this->removeAccessKey($user, $access_key);
     $this->removeSession('ts_sid');
     $this->removeCookie('ts_sid');
     $this->result = true;
 }
Example #2
0
 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');
             }
         }
     }
 }
Example #3
0
 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;
 }