Advertisement
Guest User

Untitled

a guest
Jul 1st, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. <script type="text/javascript">
  2. $(function() {
  3. $("#loginForm").submit(function(event) {
  4. $("#success").css("display", "block"), $('#success').html("Autenticando...");
  5. $('#info').hide();
  6. $('.form-group').hide();
  7.  
  8. var rootUrl = "<?php echo URL_BASE; ?>";
  9.  
  10. var username = $("#username").val();
  11. var password = $("#password").val();
  12.  
  13. $.ajax( {
  14. method: "POST",
  15. url: "api/login.php",
  16. dataType: "JSON",
  17. data: $(this).serialize(),
  18. success: function(i) {
  19. if (i["status"] == "success") {
  20. $("#error").css("display", "none");
  21. location.href = rootUrl + "/options/?welcome=true";
  22. } else {
  23. if (i["status"] == "error") {
  24. $("#error").css("display", "block"), $("#error").html(i["message"]);
  25. $("#success").css("display", "none"), $("#success").empty();
  26. $(".form-group").show();
  27. $("#info").show();
  28. return false;
  29. }
  30. }
  31. }, error: function (error) { console.log(error); }
  32. });
  33. return false;
  34. });
  35. });
  36. </script>
  37.  
  38. if (isset($cookies['auth_token'])) {
  39.  
  40. Cookies::set('auth_token', $cookies['auth_token']);
  41. Cookies::set('user', $ttrUsername);
  42. Cookies::set('pass', $ttrPassword);
  43.  
  44. $_SESSION[SITE_NAME . '_SESSION'] = $ttrUsername;
  45.  
  46. echo json_encode(array(
  47. "status" => "success",
  48. "message" => "Autenticação bem sucedida, estamos te redirecionando.",
  49. ));
  50.  
  51. } else {
  52. echo json_encode(
  53. array(
  54. "status" => "error",
  55. 'message'=> "Não foi possível autenticar com o Twitter.",
  56. ));
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement