Advertisement
Guest User

Untitled

a guest
Dec 31st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. this.http.post(this.loginURL, requestBody, options)
  2.  
  3. Route::get('patientlogin','UploadController@login');
  4.  
  5. public function login(Request $request){
  6. // error_reporting(-1); // prints every error, warning, etc
  7. error_reporting(0); // no output at all
  8.  
  9. // set content-type of response to json
  10. header('Content-Type: application/json');
  11.  
  12. // import Auth class and custom functions
  13. // require_once('custom_functions.php');
  14.  
  15.  
  16. $LOGIN_LOG_FILE = "login1.log";
  17. $AUTH_HEADERS_FILE = "auth-headers1.txt";
  18.  
  19.  
  20. /*
  21. php://input is raw input, regardless of header field "content-type"
  22. The PHP superglobal $_POST, only is supposed to wrap data that is either
  23. application/x-www-form-urlencoded or multipart/form-data-encoded
  24. http://stackoverflow.com/a/8893792
  25.  
  26. When sending only a JSON, $_POST etc will not be populated and php://input has to be used
  27. in the php scripts
  28. http://stackoverflow.com/questions/1282909/php-post-array-empty-upon-form-submission
  29. http://php.net/manual/de/wrappers.php.php
  30. */
  31.  
  32.  
  33.  
  34. $content = $request->instance();
  35. $json_raw = $content->json()->all();
  36. $json = json_decode($json_raw, true);
  37.  
  38.  
  39. /* <-- DEBUGGING START TODO delete */
  40. //read the header, where username and password are supposed to be in
  41. $headers = apache_request_headers();
  42.  
  43. //print the contents of the headers array in a neat structure and log them
  44. $headersPrintable = print_r($headers, true);
  45. file_put_contents($AUTH_HEADERS_FILE, $headersPrintable, FILE_APPEND);
  46.  
  47. $request = print_r($_REQUEST, true);
  48. $post = print_r($_POST, true);
  49. file_put_contents("auth-req.txt", $request, FILE_APPEND);
  50. file_put_contents("auth-post.txt", $post, FILE_APPEND);
  51.  
  52. file_put_contents("auth-req-json.txt", $json_raw, FILE_APPEND);
  53. file_put_contents("auth-req-json_decoded.txt", $json, FILE_APPEND);
  54. /* DEBUGGING END --> */
  55.  
  56. $valid = false;
  57. $username = "";
  58.  
  59. //check if username and passord exist in the json-decoded version of php://input
  60. if(array_key_exists("username", $json) && array_key_exists("password", $json)) {
  61. $username = $json["username"];
  62. $password = $json["password"];
  63. $valid = Auth::checkCredentials($username, $password);
  64. }
  65.  
  66. $response = array(
  67. "username" => $username,
  68. "valid" => $valid
  69. );
  70.  
  71. echo json_encode($response);
  72.  
  73. //exit();
  74.  
  75. }
  76.  
  77. polyfills.js:1 POST http://ip/patientlogin 500 (Internal Server Error)
  78.  
  79. MethodNotAllowedHttpException in RouteCollection.php line 218:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement