Advertisement
Guest User

Untitled

a guest
Nov 27th, 2016
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. app.factory('LoginService', function($http, $location, SessionService) {
  2. return {
  3. login: function(data, scope) {
  4. $http({
  5. method: 'GET',
  6. url: 'http://localhost:8888/www/webservice/login.php',
  7. data: {'login': data.login, 'password': data.password}
  8. }).then(function successCallback(response) {
  9. alert(JSON.stringify(response));
  10. // this callback will be called asynchronously
  11. // when the response is available
  12. }, function errorCallback(response) {
  13. alert(JSON.stringify(response));
  14. // called asynchronously if an error occurs
  15. // or server returns response with an error status.
  16. });
  17. }
  18. }
  19. });
  20.  
  21. <?php header('Access-Control-Allow-Origin: *'); ?>
  22. <?php header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); ?>
  23. <?php header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT'); ?>
  24. <?php
  25. $postdata = file_get_contents("php://input");
  26. $request = json_decode($postdata);
  27. $login = $request->login;
  28. $senha = $request->password;
  29.  
  30. $user = 'root';
  31. $password = 'root';
  32. $db = 'CURRICULO';
  33. $host = 'localhost';
  34. $port = 3306;
  35.  
  36. //Open a new connection to the MySQL server
  37. $mysqli = new mysqli($host, $user, $password, $db, $port);
  38.  
  39. //Output any connection error
  40. if ($mysqli->connect_error) {
  41. die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
  42. }
  43.  
  44. //MySqli Select Query
  45. $query = "SELECT * FROM Usuarios WHERE Login = '$login' AND Senha = '$senha'";
  46. echo "$query";
  47. $results = $mysqli->query($query);
  48. $rows = array();
  49.  
  50. while($row = $results->fetch_array()) {
  51. $Id = $row["Id"];
  52. $Login = $row["Login"];
  53. $Tipo = $row["Tipo"];
  54.  
  55. $rows[] = array('Id' => $Id, 'Login' => $Login, 'Tipo' => $Tipo);
  56. }
  57.  
  58. //Frees the memory associated with a result
  59. $results->free();
  60. // close connection
  61. $mysqli->close();
  62.  
  63. echo json_encode($rows);
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement