示例#1
0
 public function Register()
 {
     try {
         if ($_POST['user'] and $_POST['pass'] and $_POST['email']) {
             $db = new Connect();
             $this->user = $db->real_escape_string($_POST['user']);
             $this->email = $db->real_escape_string($_POST['email']);
             $this->pass = sha1($_POST['pass']);
             $sql = $db->query("SELECT usuario,email FROM usuarios \n                WHERE usuario='{$this->user}' OR email='{$this->email}' LIMIT 1;");
             if ($db->rows($sql) == 0) {
                 $sql2 = $db->query("SELECT COUNT(id) FROM usuarios LIMIT 1;");
                 $top = $db->recorrer($sql2);
                 $top = $top[0] + 1;
                 $sql3 = $db->query("INSERT INTO usuarios (usuario,password,email,faccion,top) \n                    VALUES ('{$this->user}','{$this->pass}','{$this->email}','1','{$top}');");
                 $sql4 = $db->query("SELECT MAX(id) AS id FROM usuarios LIMIT 1;");
                 $id = $db->recorrer($sql4);
                 $id = $id[0];
                 $db->liberar($sql, $sql2, $sql3, $sql4);
                 require 'core/models/class.GeneratePlanet.php';
                 $planeta = new GeneratePlanet();
                 $planeta->RegisterPlanet($id);
                 $planet = $db->query("SELECT id_planeta FROM planetas WHERE id_dueno='{$id}' LIMIT 1;");
                 $id_planet = $db->recorrer($planet);
                 $id_planet = $id_planet[0];
                 $_SESSION['id_planet'] = $id_planet;
                 $_SESSION['user'] = $this->user;
                 $_SESSION['id'] = $id;
                 unset($sql, $sql2, $sql3, $sql4, $top, $db, $id, $this->email, $this->pass);
                 echo 1;
                 $db->liberar($planet);
                 $db->close();
             } else {
                 $dato = $db->recorrer($sql);
                 $db->liberar($sql);
                 $db->close();
                 $lng = new Lang();
                 if (strtolower($dato[1]) == strtolower($this->email) and strtolower($dato[0]) != strtolower($this->user)) {
                     throw new Exception($lng->e_email_existe);
                 } else {
                     if (strtolower($dato[1]) != strtolower($this->email) and strtolower($dato[0]) == strtolower($this->user)) {
                         throw new Exception($lng->e_user_existe);
                     } else {
                         throw new Exception($lng->e_user_email_existe);
                     }
                 }
                 unset($sql, $db, $lng, $dato, $this->user, $this->email, $this->pass);
             }
         } else {
             throw new Exception('error');
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     exit;
 }
示例#2
0
 public function Register()
 {
     if (!empty($_POST['user']) and !empty($_POST['pass']) and !empty($_POST['email'])) {
         $db = new Connect();
         $this->user = $db->real_escape_string($_POST['user']);
         $this->email = $db->real_escape_string($_POST['email']);
         $this->pass = sha1($_POST['pass']);
         $sql = $db->query("SELECT usuario,email FROM usuarios \n            WHERE usuario='{$this->user}' OR email='{$this->email}' LIMIT 1;");
         if ($db->rows($sql) == 0) {
             $sql2 = $db->query("SELECT COUNT(id) FROM usuarios LIMIT 1;");
             $top = $db->recorrer($sql2);
             $top = $top[0] + 1;
             $sql3 = $db->query("INSERT INTO usuarios (usuario,password,email,faccion,top) \n                VALUES ('{$this->user}','{$this->pass}','{$this->email}','1','{$top}');");
             $sql4 = $db->query("SELECT MAX(id) AS id FROM usuarios LIMIT 1;");
             $id = $db->recorrer($sql4);
             $id = $id[0];
             $db->liberar($sql, $sql2, $sql3, $sql4);
             require 'core/models/class.GeneratePlanet.php';
             $planeta = new GeneratePlanet();
             $planeta->RegisterPlanet($id);
             $planet = $db->query("SELECT id_planeta FROM planetas WHERE id_dueno='{$id}' LIMIT 1;");
             $id_planet = $db->recorrer($planet);
             $id_planet = $id_planet[0];
             $_SESSION['id_planet'] = $id_planet;
             $_SESSION['user'] = $this->user;
             $_SESSION['id'] = $id;
             $login = '******';
             $db->liberar($planet);
             $db->close();
             unset($sql, $sql2, $sql3, $sql4, $top, $db, $id, $this->email, $this->pass);
         } else {
             $dato = $db->recorrer($sql);
             $db->liberar($sql);
             $db->close();
             $lng = new Lang();
             if (strtolower($dato[1]) == strtolower($this->email) and strtolower($dato[0]) != strtolower($this->user)) {
                 $login = $lng->e_email_existe;
             } else {
                 if (strtolower($dato[1]) != strtolower($this->email) and strtolower($dato[0]) == strtolower($this->user)) {
                     $login = $lng->e_user_existe;
                 } else {
                     $login = $lng->e_user_email_existe;
                 }
             }
             unset($sql, $db, $lng, $dato, $this->user, $this->email, $this->pass);
         }
     } else {
         $lng = new Lang();
         $login = $lng->e_datos_vac;
         unset($lng);
     }
     echo $login;
     unset($login);
 }