Пример #1
0
 /**
  * Конструктор
  * 
  * @param integer $id Необязательный параметр. Если NULL, то берутся данные
  * пользователя который вошёл в систему (сессии), иначе по ID другого пользователя
  * @return User
  */
 public final function __construct($id = NULL)
 {
     if (self::$instance != true) {
         throw new UserException(UserException::CREATION, 0);
     }
     MySQLConnector::__construct();
     secureStartSession();
     if ($id == NULL || $id == $_SESSION["user"]["id"]) {
         if (!isset($_SESSION["user"])) {
             $userSignOut = new UserSignInOut();
             if ($userSignOut->checkIfSave()) {
                 $uId = (int) $_COOKIE["id"];
                 $this->_sql->query("SELECT `mail`,`password` FROM `SITE_USERS` WHERE `id`={$uId}");
                 $secArr = $this->_sql->GetRows();
                 $mailSec = $secArr[0]["mail"];
                 $pass = $secArr[0]["password"];
                 if (md5($uId) . md5($mailSec) != $_COOKIE["sec"]) {
                     throw new UserException("", UserException::USR_NOT_AUTENT);
                 } else {
                     $userSignOut->authentication($mailSec, $pass, false, true);
                     $this->setData($_SESSION["user"]);
                     $this->isOnline = true;
                 }
             } else {
                 throw new UserException("", UserException::USR_NOT_AUTENT);
             }
         } else {
             $this->setData($_SESSION["user"]);
             $this->isOnline = true;
             $this->checkLastTime(parent::$updateInterval);
         }
     } else {
         try {
             $this->other = true;
             $this->setData($this->getDataFromDb($id));
         } catch (Exception $ex) {
             throw new UserException($id, UserException::USR_NOT_EXSIST);
         }
     }
 }