Guest User

Untitled

a guest
Dec 15th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. session_start();
  2. header('Access-Control-Allow-Origin: *');
  3. header('Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS');
  4. header('Access-Control-Allow-Headers: Content-Type');
  5.  
  6.  
  7. $postdata = file_get_contents("php://input");
  8.  
  9. if(isset($postdata) && !empty($postdata)) {
  10.  
  11. $request = json_decode($postdata);
  12. $username=trim($request->username);
  13. $password=trim($request->password);
  14.  
  15. if($username == 'admin' && $password == 'admin') {
  16. $_SESSION['user'] = 'admin';
  17. ?>
  18. {
  19. "success": true,
  20. "secret": "This is the secret no one knows but the admin"
  21. }
  22. <?php
  23. } else {
  24. ?>
  25. {
  26. "success": false,
  27. "message": "Invalid credentials"
  28. }
  29. <?php
  30. }
  31. } else {
  32. //var_dump($_POST)
  33. ?>
  34. {
  35. "success": false,
  36. "message": "Only POST access accepted"
  37. }
  38. <?php
  39.  
  40.  
  41. }
  42.  
  43. ?>
  44.  
  45. <?php
  46. session_start();
  47. header('Access-Control-Allow-Origin: *');
  48. header('Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS');
  49. header('Access-Control-Allow-Headers: Content-Type');
  50.  
  51. $user = $_SESSION['user'];
  52.  
  53. echo '{
  54. "message": "'.$user.'",
  55. "success": true
  56. }';
  57.  
  58.  
  59. ?>
  60.  
  61. ngOnInit() {
  62.  
  63.  
  64. this.auth.getUserDetails('admin','admin')
  65. .subscribe(
  66. data => {
  67. console.log('success',data);
  68. if(data.success){
  69.  
  70. }
  71. else{
  72. window.alert("invalid");
  73. }
  74.  
  75. },
  76. error=> {
  77. console.log('failed',error);
  78.  
  79.  
  80. }
  81. )
  82. var _this=this;
  83. setTimeout(function(){
  84.  
  85.  
  86. _this.user.getSomeData().subscribe(data=>{
  87.  
  88. console.log(data);
  89.  
  90. })
  91.  
  92. }, 3000);
  93.  
  94.  
  95. }
Add Comment
Please, Sign In to add comment