Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. $("#btn-cadastro").click(function(){
  2.  
  3. var data = $("#myRegister").serialize();
  4.  
  5. $.ajax({
  6. type : 'POST',
  7. url : 'conexao/cadastro.php',
  8. data : data,
  9. dataType: 'json',
  10. beforeSend: function()
  11. {
  12. $("#btn-cadastro").html('Validando ...');
  13. },
  14. success : function(response){
  15. if(response.erro == "0"){
  16. $("#pass-info3").css('display', 'none')
  17. $("#btn-cadastro").html('Entrar');
  18. $("#btn-cadastro").prop('disabled', true);
  19. setTimeout(function () {
  20. $("#pass-info3").removeClass( "weakpass" )
  21. $("#pass-info3").addClass( "goodpass" )
  22. $("#pass-info3").css('display', 'block')
  23. $("#pass-info3").html(response.mensagem);
  24. }, 4101);
  25. setTimeout(function () {
  26. window.location.href = "index.php";
  27. }, 6101);
  28. }else{
  29. if(response.erro == "1"){
  30. $("#pass-info3").css('display', 'none')
  31. $("#pass-info3").removeClass( "goodpass" )
  32. $("#pass-info3").addClass( "weakpass" )
  33. $("#btn-cadastro").prop('disabled', true);
  34. setTimeout(function () {
  35. $("#btn-cadastro").html('Entrar');
  36. $("#btn-cadastro").prop('disabled', false);
  37. $("#pass-info3").css('display', 'block')
  38. $("#pass-info3").html('<strong>Erro! </strong>' + response.mensagem);
  39. }, 500);
  40. }
  41. }
  42. }
  43. });
  44. });
  45.  
  46. // Conexao com o Banco de Dados
  47. require_once("conexao.php");
  48.  
  49. // Recebe os dados de cadastro
  50. $nome = (isset($_POST['nome'])) ? $_POST['nome'] : null;
  51. $email = (isset($_POST['email'])) ? $_POST['email'] : null;
  52. $telefone = (isset($_POST['telefone'])) ? $_POST['telefone'] : null;
  53. $senha = (isset($_POST['senha'])) ? $_POST['senha'] : null;
  54. $rsenha = (isset($_POST['rsenha'])) ? $_POST['rsenha'] : null;
  55.  
  56. // Criptografa senha
  57. $custo = '08';
  58. $salt = 'Cf1f11ePArKlBJomM0F6aJ';
  59. $hash = crypt($senha, '$2a$' . $custo . '$' . $salt . '$');
  60.  
  61. if (empty($nome) || empty($email) || empty($telefone) || empty($senha) || empty($rsenha)):
  62. $retorno = array('erro' => '1', 'mensagem' => 'Preencha todos os campos!');
  63. echo json_encode($retorno);
  64. else:
  65.  
  66. $sql = 'SELECT * FROM usuarios WHERE email = :email';
  67. $stmt = $conexao->prepare($sql);
  68. $stmt->bindParam(':email', $email);
  69. $stmt->execute();
  70.  
  71. $resposta1 = $stmt->fetch(PDO::FETCH_ASSOC);
  72.  
  73. if (is_array($resposta1)):
  74. $retorno = array('erro' => '1', 'mensagem' => 'E-mail ja registrado!');
  75. echo json_encode($retorno);
  76. else:
  77. $sql2 = 'INSERT INTO usuarios(nome, email, telefone, senha) VALUES(:nome, :email, :telefone, :hash)';
  78. $stmt2 = $conexao->prepare($sql2);
  79. $stmt2->bindParam(':nome', $nome);
  80. $stmt2->bindParam(':email', $email);
  81. $stmt2->bindParam(':telefone', $telefone);
  82. $stmt2->bindParam(':hash', $hash);
  83. $resposta2 = $stmt2->execute();
  84.  
  85. if( ! $resposta2 ):
  86. $retorno = array('erro' => '1', 'mensagem' => 'Não foi possivel completar o cadastro!');
  87. echo json_encode($retorno);
  88. else:
  89. $retorno = array('erro' => '0', 'mensagem' => 'Cadastrado com sucesso!');
  90. echo json_encode($retorno);
  91. endif;
  92. endif;
  93. endif;
  94.  
  95. if (is_array($resposta1)):
  96.  
  97. if (is_array($resposta1) && count($resposta1) > 0):
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement