示例#1
0
 function approveUser($login, $pass, $createIP)
 {
     if ($this->checkPass($pass, $login)) {
         #ПРОВЕРЯЕМ ПРАВИЛЬНОСТЬ ПАРОЛЯ
         $ip = 0;
         $time = time() + 60 * 2;
         $this->hash = md5($this->generateCode(10));
         if ($createIP) {
             $ip = ip2long($_SERVER['REMOTE_ADDR']);
         }
         $this->prepareQuery("INSERT INTO sessions SET user_id=:id, time=:time, hash=:hash, ip=:ip");
         /*$this->prepareQuery("UPDATE user SET hash=:hash, ip=:ip WHERE id=:id");*/
         $this->query->bindParam(':hash', $this->hash);
         $this->query->bindParam(':ip', $ip);
         $this->query->bindParam(':id', $this->thisUser['user_id']);
         $this->query->bindParam(':time', $time);
         // Два часа!
         $this->executeQuery_Simple();
         $this->createCookie();
         // Создаем куки
         /*            $this->deleteOldSessions(); // Удаляем устаревшие сессии*/
         return true;
     } else {
         $this->errors['password_login'] = '******';
         // class из bootstrap
         Authorization::logOut();
         return false;
     }
 }
示例#2
0
 public function mainApproveLogin()
 {
     if (isset($_COOKIE['user_id']) and isset($_COOKIE['hash'])) {
         $this->prepareQuery("SELECT * FROM sessions WHERE user_id = :id AND hash=:hash LIMIT 1");
         $this->query->bindParam(':id', intval($_COOKIE['user_id']));
         $this->query->bindParam(':hash', $_COOKIE['hash']);
         $userData = $this->executeQuery_Row();
         if ($userData['hash'] !== $_COOKIE['hash'] or $userData['user_id'] !== $_COOKIE['user_id'] or long2ip($userData['ip']) !== $_SERVER['REMOTE_ADDR'] and $userData['user_id'] !== "0" or $userData['time'] < time()) {
             #в этом случае сносим существующие куки
             $this->deleteSessions();
             Authorization::logOut();
             return false;
         } else {
             return true;
         }
     } else {
         return false;
     }
 }
 public function actionLog_out()
 {
     Authorization::logOut();
 }