Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. $(document).ready( function() {
  2.  
  3. $('#logar').click(function(){
  4. var username = $("#username").val();
  5. var password = $("#password").val();
  6.  
  7. $.ajax({
  8.  
  9. url: 'controllers/Login.php',
  10. data: "username=" +username + "&password="+password ,
  11. type: 'GET',
  12. success: function(output) {
  13. alert(output);
  14. if(output != ''){
  15. window.location.href = "http://bravetech.com.br/politizar/representante.php";
  16. }
  17. else {
  18. alert('não logou');
  19. }
  20. }
  21. })
  22. });
  23. });
  24.  
  25. $username = $_GET['username'];
  26. $password = $_GET['password'];
  27. //echo "<script>alert('$username');</script>";
  28. //admin@bravetech.com.br
  29. //admin
  30. session_name("start");
  31. session_start("start");
  32.  
  33. $data = array(
  34. "username" => $username,
  35. "password" => $password
  36. );
  37.  
  38. $data_string = json_encode($data);
  39. $ch = curl_init('http://politizar.azurewebsites.net/api/account/login');
  40. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  41. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  42. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  43. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  44. 'Content-Type: application/json',
  45. 'Content-Length: ' . strlen($data_string))
  46. );
  47.  
  48. $result = curl_exec($ch);
  49. curl_close($ch);
  50. $dados = json_decode($result, true);
  51. //print_r($dados);
  52. $access = $dados['object']['access_token'];
  53. $sucess = $dados['isValid'];
  54.  
  55. //echo $sucess;
  56. //echo "<script>alert('$sucess');</script>";
  57. if($sucess) {
  58. // echo "<script>alert('$sucess');</script>";
  59.  
  60. $_SESSION['username'] = $username;
  61. $_SESSION['password'] = $password;
  62. }
  63. else {
  64. session_destroy();
  65. //echo "<script>alert('Nao foi');</script>";
  66. unset ($_SESSION['username']);
  67. unset ($_SESSION['password']);
  68. }
  69. echo $sucess;
  70.  
  71. session_start("start");
  72. $representantes = listarRepresentante();
  73.  
  74. echo $_SESSION['username'];
  75.  
  76. session_start("start");
  77. if((!isset ($_SESSION['username']) == true) and (!isset ($_SESSION['password']) == true))
  78. {
  79. unset($_SESSION['username']);
  80. unset($_SESSION['password']);
  81. header('location:index.php');
  82. }
  83.  
  84. $user = $_SESSION['username'];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement