Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $("#btn-cadastro").click(function(){
- var data = $("#myRegister").serialize();
- $.ajax({
- type : 'POST',
- url : 'conexao/cadastro.php',
- data : data,
- dataType: 'json',
- beforeSend: function()
- {
- $("#btn-cadastro").html('Validando ...');
- },
- success : function(response){
- if(response.erro == "0"){
- $("#pass-info3").css('display', 'none')
- $("#btn-cadastro").html('Entrar');
- $("#btn-cadastro").prop('disabled', true);
- setTimeout(function () {
- $("#pass-info3").removeClass( "weakpass" )
- $("#pass-info3").addClass( "goodpass" )
- $("#pass-info3").css('display', 'block')
- $("#pass-info3").html(response.mensagem);
- }, 4101);
- setTimeout(function () {
- window.location.href = "index.php";
- }, 6101);
- }else{
- if(response.erro == "1"){
- $("#pass-info3").css('display', 'none')
- $("#pass-info3").removeClass( "goodpass" )
- $("#pass-info3").addClass( "weakpass" )
- $("#btn-cadastro").prop('disabled', true);
- setTimeout(function () {
- $("#btn-cadastro").html('Entrar');
- $("#btn-cadastro").prop('disabled', false);
- $("#pass-info3").css('display', 'block')
- $("#pass-info3").html('<strong>Erro! </strong>' + response.mensagem);
- }, 500);
- }
- }
- }
- });
- });
- // Conexao com o Banco de Dados
- require_once("conexao.php");
- // Recebe os dados de cadastro
- $nome = (isset($_POST['nome'])) ? $_POST['nome'] : null;
- $email = (isset($_POST['email'])) ? $_POST['email'] : null;
- $telefone = (isset($_POST['telefone'])) ? $_POST['telefone'] : null;
- $senha = (isset($_POST['senha'])) ? $_POST['senha'] : null;
- $rsenha = (isset($_POST['rsenha'])) ? $_POST['rsenha'] : null;
- // Criptografa senha
- $custo = '08';
- $salt = 'Cf1f11ePArKlBJomM0F6aJ';
- $hash = crypt($senha, '$2a$' . $custo . '$' . $salt . '$');
- if (empty($nome) || empty($email) || empty($telefone) || empty($senha) || empty($rsenha)):
- $retorno = array('erro' => '1', 'mensagem' => 'Preencha todos os campos!');
- echo json_encode($retorno);
- else:
- $sql = 'SELECT * FROM usuarios WHERE email = :email';
- $stmt = $conexao->prepare($sql);
- $stmt->bindParam(':email', $email);
- $stmt->execute();
- $resposta1 = $stmt->fetch(PDO::FETCH_ASSOC);
- if (is_array($resposta1)):
- $retorno = array('erro' => '1', 'mensagem' => 'E-mail ja registrado!');
- echo json_encode($retorno);
- else:
- $sql2 = 'INSERT INTO usuarios(nome, email, telefone, senha) VALUES(:nome, :email, :telefone, :hash)';
- $stmt2 = $conexao->prepare($sql2);
- $stmt2->bindParam(':nome', $nome);
- $stmt2->bindParam(':email', $email);
- $stmt2->bindParam(':telefone', $telefone);
- $stmt2->bindParam(':hash', $hash);
- $resposta2 = $stmt2->execute();
- if( ! $resposta2 ):
- $retorno = array('erro' => '1', 'mensagem' => 'Não foi possivel completar o cadastro!');
- echo json_encode($retorno);
- else:
- $retorno = array('erro' => '0', 'mensagem' => 'Cadastrado com sucesso!');
- echo json_encode($retorno);
- endif;
- endif;
- endif;
- if (is_array($resposta1)):
- if (is_array($resposta1) && count($resposta1) > 0):
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement