Created
June 2, 2018 14:14
-
-
Save apertaoxis/6d6b0b044308491072ecf27dd35a410f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| define('ROOT', rtrim($_SERVER['DOCUMENT_ROOT'], '/')); | |
| require ROOT.'/src/config.inc.php'; | |
| sleep(2); | |
| $nome = trim(post('nome', FILTER_SANITIZE_STRING)); | |
| $email = strtolower(post('email', FILTER_SANITIZE_EMAIL)); | |
| $senhas = [post('senha'), post('senha2')]; | |
| $nascimento = convert_date(post('nascimento'), 'Y-m-d'); | |
| $genero = post('genero'); | |
| $cidade = post('cidade'); | |
| $oCidade = post('outraCidade'); | |
| $noty = post('mala') ? 1 : 0; | |
| $aid = ''; | |
| // Host do email | |
| $host = substr(strstr($email, '@'), 1); | |
| // Pega o id do afiliado, se houver | |
| if (cookie('afiliadoId')) { | |
| $aid = cookie('afiliadoId'); | |
| } | |
| // Altera a cidade SE a cidade do usuário for diferente das disponíveis. | |
| if ($cidade == "Outra") { | |
| $cidade = $oCidade; | |
| } | |
| // Retorna erro se o nome ou sobrenome estiver vazio. | |
| if (empty($nome)) { | |
| echo 'jQuery.metroLoadingKill();jQuery("#erro").html("<i class=\"fa fa-exclamation-triangle\"></i> Informe seu nome").fadeIn(); console.log("erro");'; | |
| exit; | |
| } | |
| // Retorna erro se o email for inválido | |
| if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
| echo 'jQuery.metroLoadingKill();jQuery("#erro").html("<i class=\"fa fa-exclamation-triangle\"></i> Informe um email válido.").fadeIn(); console.log("erro");'; | |
| exit; | |
| } | |
| // Retorna erro se não encontrar o HOST | |
| if (false == getmxrr($host, $mxhost)) { | |
| echo '$.metroLoadingKill();jQuery("#erro").html("<i class=\"fa fa-exclamation-triangle\"></i> Informe um email válido.").fadeIn(); $("#email-cadastro").focus().parent("div").addClass("has-error");'; | |
| exit; | |
| } | |
| // Verifica se a senha tem pelo menos 6 caracteres | |
| if (!isset($senhas[0][5])) { | |
| echo 'jQuery.metroLoadingKill();jQuery("#erro").html("<i class=\"fa fa-exclamation-triangle\"></i> Sua senha esta muito curta.").fadeIn(); console.log("erro");'; | |
| exit; | |
| } | |
| // Verifica se as senhas inseridas são iguais | |
| if($senhas[0] != $senhas[1]) { | |
| echo 'jQuery.metroLoadingKill();jQuery("#erro").html("<i class=\"fa fa-exclamation-triangle\"></i> A senha não confere.").fadeIn(); console.log("erro");'; | |
| exit; | |
| } | |
| // Verifica se o usuário tem mais de 18 anos | |
| if (idade($nascimento) < 18) { | |
| echo 'jQuery.metroLoadingKill();jQuery("#erro").html("<i class=\"fa fa-exclamation-triangle\"></i> Desculpe, seu cadastro foi recusado.").fadeIn();'; | |
| exit; | |
| } | |
| // Verifica se foi informado o genero (masc/fem) | |
| if (empty($genero)) { | |
| echo 'jQuery.metroLoadingKill();jQuery("#erro").html("<i class=\"fa fa-exclamation-triangle\"></i> Informe seu gênero.").fadeIn(); console.log("erro");'; | |
| exit; | |
| } | |
| // Verifica se foi informado a Cidade | |
| if (empty($cidade)) { | |
| echo 'jQuery.metroLoadingKill();jQuery("#erro").html("<i class=\"fa fa-exclamation-triangle\"></i> Informe sua cidade.").fadeIn(); console.log("erro");'; | |
| exit; | |
| } | |
| // Busca o email no banco de dados | |
| $sql = $pdo->prepare("SELECT email FROM _usuario WHERE email = :email"); | |
| $sql->bindValue(':email', $email); | |
| $sql->execute(); | |
| $num = $sql->rowCount(); | |
| // Retorna erro se o email já estiver cadastrado | |
| if ($num) { | |
| echo 'jQuery.metroLoadingKill();jQuery("#erro").html("<i class=\"fa fa-exclamation-triangle\"></i> E-mail já cadastrado.").fadeIn(); console.log("erro");'; | |
| exit; | |
| } | |
| // Gera o token para confirmação de cadastro | |
| $token = new codigo(60); | |
| $token->maior = true; | |
| $token = $token->create("SELECT id FROM _usuario WHERE tokenCadastro = ?"); | |
| // Codifica a senha | |
| $password = password_hash($senhas[0], PASSWORD_DEFAULT); | |
| // Inserindo no BD | |
| $sql = $pdo->prepare("INSERT INTO _usuario (nome, email, dataNascimento, cidade, genero, dataCadastro, ipCadastro, tokenCadastro, senha, afiliadoId) VALUES (:nome, :email, :data, :cidade, :genero, now(), :ip, :token, :senha, :afiliado)"); | |
| $sql->bindValue(':nome', $nome); | |
| $sql->bindValue(':email', $email); | |
| $sql->bindValue(':data', $nascimento); | |
| $sql->bindValue(':cidade', $cidade); | |
| $sql->bindValue(':genero', $genero); | |
| $sql->bindValue(':ip', address()); | |
| $sql->bindValue(':token', $token); | |
| $sql->bindValue(':senha', $password); | |
| $sql->bindValue(':afiliado', $aid); | |
| $sql->execute(); | |
| $num = $sql->rowCount(); | |
| if (!$num) { | |
| echo 'jQuery.metroLoadingKill();jQuery("#erro").html("<i class=\"fa fa-exclamation-triangle\"></i> Ocorreu um erro ao salvar seu dados. Tente novamente mais tarde.").fadeIn();'; | |
| exit; | |
| } | |
| // Link para confirmar o cadastro | |
| $link = 'https://'.$servidor->siteDomain.'confirmar-cadastro.php?token='.$token.'&email='.rawurlencode($email); | |
| // Pega o HTML para gerar o email | |
| $template = new EmailTemplate; | |
| $template->setLink($link); | |
| // Envia o email | |
| $envio = email($email, 'Cadastro Concluído', $template->welcome()); | |
| $text = 'jQuery.metroLoadingKill();jQuery("#erro").html("<i class=\"fa fa-exclamation-triangle\"></i> Seu cadastro foi efetuado mais não conseguimos lhe enviar o email de confirmação. Tente fazer login.").fadeIn(); console.log("erro");'; | |
| if ($envio) { | |
| $text = "jQuery.metroLoadingKill();jQuery('#erro').hide();jQuery('#sucesso').fadeIn();$('#form-cadastro').find('input,textarea,select').each(function(){ $(this).val('').parent('div').removeClass('has-error'); $(this).text('').parent('div').removeClass('has-error');}); ga('send', 'event', 'Cadastros', 'Cadastro de Usuário'); "; | |
| } | |
| echo $text; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment