Example #1
0
 public static function authAdmin($login = false, $password = false)
 {
     if ($login) {
         $auth = true;
     } else {
         if (!session_id()) {
             session_start();
         }
         if (!empty($_SESSION["auth_login"]) && !empty($_SESSION["auth_password"])) {
             $login = $_SESSION["auth_login"];
             $password = $_SESSION["auth_password"];
         } else {
             return;
         }
         $auth = false;
     }
     $user = new AdminDB();
     if ($auth) {
         $password = self::hash($password, Config::SECRET);
     }
     $select = new Select();
     $select->from(self::$table, array("COUNT(id)"))->where("`login` = " . self::$db->getSQ(), array($login))->where("`password` = " . self::$db->getSQ(), array($password));
     $count = self::$db->selectCell($select);
     if ($count) {
         $user->loadOnLogin($login);
         if ($user->activation != "") {
             throw new Exception("ERROR_ACTIVATE_USER");
         }
         if ($auth) {
             $user->login();
         }
         return $user;
     }
     if ($auth) {
         throw new Exception("ERROR_AUTH_USER");
     }
 }