Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. $captcha = filter_input(INPUT_POST, 'captchaResponse'); // get the captchaResponse parameter sent from our ajax
  2.  
  3.  
  4. if (!$captcha) {
  5. echo 'no captcha';
  6. }
  7. $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=YOUR-SECRET-KEY-HERE&response=" . $captcha);
  8.  
  9. if ($response . success == false) {
  10. //echo 'SPAM';
  11. // http_response_code(401); // It's SPAM! RETURN SOME KIND OF ERROR
  12. echo 'spam';
  13. } else {
  14. // Everything is ok and you can proceed by executing your login, signup, update etc scripts
  15. echo 'captcha good';
  16. }
  17.  
  18. //LOGIN FORM
  19. $("#admin_loginForm").submit(function(event) {
  20.  
  21. $('#loginResult').html('Please wait...');
  22.  
  23.  
  24. /* Send the request to teh server */
  25. $.ajax({
  26. type: 'POST', // The request type POST or GET
  27. url: "inc/functions.inc.php", // The URL to the controller
  28. dataType: 'html', // The data type json, html, img etc...
  29. async: true, // async or sync
  30. /* The main request body */
  31. data: {
  32. action: "logIn", // The action that we are catching at controller.php
  33. username: $('#username').val(), // Get the username user input
  34. password: $('#password').val(), // Get the password user input
  35. captchaResponse: $("#g-recaptcha-response").val()
  36. },
  37. success: function (data) {
  38. if(data == "false") {
  39. $('#loginResult').html('Enter your username & password!');
  40. }
  41.  
  42. else {
  43. alert('all good');
  44. }
  45.  
  46. },
  47.  
  48.  
  49. error: function (XMLHttpRequest, textStatus, errorThrown) {
  50. /* If something goes wrong we're comming here */
  51. alert(errorThrown);
  52. }
  53.  
  54. });
  55.  
  56.  
  57. });
  58.  
  59. $action = filter_input(INPUT_POST, 'action');
  60. if($action == "logIn") {
  61.  
  62. $username = filter_input(INPUT_POST, 'username');
  63. $password = filter_input(INPUT_POST, 'password');
  64.  
  65. if(empty($username)) {
  66. echo 'false';
  67. }
  68.  
  69. else if(empty($password)) {
  70. echo 'false';
  71. }
  72.  
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement