Guest User

Untitled

a guest
Nov 24th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.18 KB | None | 0 0
  1. private function registerUser() {
  2.     if (!isset($this->_data['usn']) || !isset($this->_data['email']) || !isset($this->_data['ver'])) {
  3.       return false;
  4.     }
  5.     // send server version
  6.     $this->_responseString = sprintf("%s\n", self::VERSION);
  7.     // check versions
  8.     if (self::VERSION != base64_decode($this->_data['ver'])) {
  9.       $this->_responseString .= UPDATE_URL;
  10.       return false;
  11.     }  
  12.  
  13.    
  14.     $username = base64_decode($this->_data['usn']);
  15.     $email = base64_decode($this->_data['email']);
  16.     if (!preg_match(USERNAME_PATTERN, $username)) {
  17.       $this->_responseString .= 'Seu nick pode conter apenas caracteres alfanuméricos, "[" , "]" e "_" e não pode iniciar com um algarismo';
  18.       return false;
  19.     }
  20.  
  21.    
  22.     if (strlen($username) < MIN_USERNAME_LEN || strlen($username) > MAX_USERNAME_LEN) {
  23.       $this->_responseString .= sprintf('Seu login deve ter no mínimo %d caracteres e no máximo %d caracteres.', MIN_USERNAME_LEN, MAX_USERNAME_LEN);
  24.       return false;
  25.     }
  26.     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  27.       $this->_responseString .= 'É necessário informar um endereço de e-mail válido
  28.       para enviar sua senha.';
  29.       return false;
  30.     }
  31.     $sql = "SELECT *
  32.            FROM lobbyserver_users
  33.            WHERE username = '" . $this->_db->sql_escape($username) . "'";
  34.     if (!($result = $this->_db->sql_query($sql))) {
  35.       $this->_responseString .= 'Database error.';
  36.       return false;
  37.     }
  38.     if ($this->_db->sql_fetchrow($result)) {
  39.       $this->_responseString .= 'Esse nick já possui um dono. Escolha outro a seu gosto.';
  40.       return false;
  41.     }
  42.     $password = $this->generatePassword();
  43.     $message = sprintf(MAIL_MESSAGE, $username, $password);
  44.     if (mail($email, MAIL_SUBJECT, $message, sprintf("From: %s\r\n", MAIL_FROM))) {
  45.       $dt = new DateTime(null, new DateTimeZone('GMT'));
  46.       $sql_ary = array(
  47.         'username'    => $username,
  48.         'password'    => $password,
  49.         'email'       => $email
  50.         'registered'  => $dt->format('Y-m-d H:i:s')
  51.       );
  52.       $this->_db->sql_transaction('begin');
  53.       $sql = 'INSERT INTO lobbyserver_users ' . $this->_db->sql_build_array('INSERT', $sql_ary);
  54.       if (!$this->_db->sql_query($sql)) {
  55.         $this->_db->sql_transaction('rollback');
  56.         $this->_responseString .= 'Database error.';
  57.         return false;
  58.       }
  59.       if (!($userId = $this->_db->sql_nextid())) {
  60.         $this->_db->sql_transaction('rollback');
  61.         $this->_responseString .= 'Database error.';
  62.         return false;
  63.       }
  64.       $sql = 'INSERT INTO lobbyserver_ratings(uid,rating_type) values('.$userId.',0),('.$userId.',1);';
  65.       if (!$this->_db->sql_query($sql)) {
  66.         $this->_db->sql_transaction('rollback');
  67.         $this->_responseString .= 'Database error.';
  68.         return false;
  69.       }  
  70.       $this->_db->sql_transaction('commit');
  71.       $this->_responseString .= 'Sua senha foi enviada para o e-mail informado. Bem vindo ao Zone.AgeMania.';
  72.       return true;
  73.     } else {
  74.       $this->_responseString .= 'Não foi possível enviar sua senha. Avise algum operador(@) para consertar esse problema.';
  75.       return false;
  76.     }
  77.   }
Add Comment
Please, Sign In to add comment