Advertisement
Guest User

Untitled

a guest
Nov 15th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. var $lg_username=$('#login_username').val();
  2. var $lg_password=$('#login_password').val();
  3. var $lg_lemb=$('#login_lemb').val();
  4. var $responseG = grecaptcha.getResponse();
  5. if($responseG.length == 0){
  6. msgChange($('#div-login-msg'), $('#icon-login-msg'), $('#text-login-msg'), "error", "glyphicon-remove", "reCAPTCHA obrigatório!");
  7. } else {
  8.  
  9. if ($lg_username == "" && $lg_password == "") {
  10. msgChange($('#div-login-msg'), $('#icon-login-msg'), $('#text-login-msg'), "error", "glyphicon-remove", "Ambos os campos são obrigatórios!");
  11. } else {
  12. $.post( $("body").attr("data-url") + "/login", { email: $lg_username, senha: $lg_password, lembre: $lg_lemb, response: grecaptcha.getResponse() }).done(function( data ) {
  13. alert(data);
  14. data.split("|");
  15. msgChange($('#div-login-msg'), $('#icon-login-msg'), $('#text-login-msg'), data['0'], data['1'], data['2']);
  16. if(data['0']==success){
  17. setTimeout("window.location='"+ $("body").attr("data-url-full") +"'",2000);
  18. }
  19. });
  20. }
  21. }
  22.  
  23. class GoogleRecaptcha
  24. {
  25. /* Google recaptcha API url */
  26. private $google_url = "https://www.google.com/recaptcha/api/siteverify";
  27. private $secret = 'minhachavescretaaqui';
  28.  
  29. public function VerifyCaptcha($response)
  30. {
  31. $url = $this->google_url."?secret=".$this->secret.
  32. "&response=".$response;
  33.  
  34. $curl = curl_init();
  35. curl_setopt($curl, CURLOPT_URL, $url);
  36. curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  37. curl_setopt($curl, CURLOPT_TIMEOUT, 15);
  38. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, TRUE);
  39. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  40. $curlData = curl_exec($curl);
  41.  
  42. curl_close($curl);
  43.  
  44. $res = json_decode($curlData, TRUE);
  45. if($res['success'] == 'true')
  46. return TRUE;
  47. else
  48. return FALSE;
  49. }
  50.  
  51. }
  52.  
  53. if($_SERVER["REQUEST_METHOD"] == "POST")
  54. {
  55. $response = $_POST['response'];
  56.  
  57. if(!empty($response))
  58. {
  59. $cap = new GoogleRecaptcha();
  60. $verified = $cap->VerifyCaptcha($response);
  61.  
  62. if($verified) {
  63. echo "success|glyphicon-ok|Logando, aguarde...";
  64. } else {
  65. echo utf8_encode("error|glyphicon-remove|Usuário e ou senha inválidos!");
  66. }
  67.  
  68. } else {
  69. echo utf8_encode("error|glyphicon-remove|reCAPTCHA inválido!");
  70. }
  71. } else {
  72. echo utf8_encode("error|glyphicon-remove|reCAPTCHA é obrigatório!");
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement