Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function registerUser() {
- if (!isset($this->_data['usn']) || !isset($this->_data['email']) || !isset($this->_data['ver'])) {
- return false;
- }
- // send server version
- $this->_responseString = sprintf("%s\n", self::VERSION);
- // check versions
- if (self::VERSION != base64_decode($this->_data['ver'])) {
- $this->_responseString .= UPDATE_URL;
- return false;
- }
- $username = base64_decode($this->_data['usn']);
- $email = base64_decode($this->_data['email']);
- if (!preg_match(USERNAME_PATTERN, $username)) {
- $this->_responseString .= 'Seu nick pode conter apenas caracteres alfanuméricos, "[" , "]" e "_" e não pode iniciar com um algarismo';
- return false;
- }
- if (strlen($username) < MIN_USERNAME_LEN || strlen($username) > MAX_USERNAME_LEN) {
- $this->_responseString .= sprintf('Seu login deve ter no mínimo %d caracteres e no máximo %d caracteres.', MIN_USERNAME_LEN, MAX_USERNAME_LEN);
- return false;
- }
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $this->_responseString .= 'É necessário informar um endereço de e-mail válido
- para enviar sua senha.';
- return false;
- }
- $sql = "SELECT *
- FROM lobbyserver_users
- WHERE username = '" . $this->_db->sql_escape($username) . "'";
- if (!($result = $this->_db->sql_query($sql))) {
- $this->_responseString .= 'Database error.';
- return false;
- }
- if ($this->_db->sql_fetchrow($result)) {
- $this->_responseString .= 'Esse nick já possui um dono. Escolha outro a seu gosto.';
- return false;
- }
- $password = $this->generatePassword();
- $message = sprintf(MAIL_MESSAGE, $username, $password);
- if (mail($email, MAIL_SUBJECT, $message, sprintf("From: %s\r\n", MAIL_FROM))) {
- $dt = new DateTime(null, new DateTimeZone('GMT'));
- $sql_ary = array(
- 'username' => $username,
- 'password' => $password,
- 'email' => $email
- 'registered' => $dt->format('Y-m-d H:i:s')
- );
- $this->_db->sql_transaction('begin');
- $sql = 'INSERT INTO lobbyserver_users ' . $this->_db->sql_build_array('INSERT', $sql_ary);
- if (!$this->_db->sql_query($sql)) {
- $this->_db->sql_transaction('rollback');
- $this->_responseString .= 'Database error.';
- return false;
- }
- if (!($userId = $this->_db->sql_nextid())) {
- $this->_db->sql_transaction('rollback');
- $this->_responseString .= 'Database error.';
- return false;
- }
- $sql = 'INSERT INTO lobbyserver_ratings(uid,rating_type) values('.$userId.',0),('.$userId.',1);';
- if (!$this->_db->sql_query($sql)) {
- $this->_db->sql_transaction('rollback');
- $this->_responseString .= 'Database error.';
- return false;
- }
- $this->_db->sql_transaction('commit');
- $this->_responseString .= 'Sua senha foi enviada para o e-mail informado. Bem vindo ao Zone.AgeMania.';
- return true;
- } else {
- $this->_responseString .= 'Não foi possível enviar sua senha. Avise algum operador(@) para consertar esse problema.';
- return false;
- }
- }
Add Comment
Please, Sign In to add comment