Guest User

Untitled

a guest
Nov 22nd, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. [HttpPost("IsAuthenticated")]
  2. public IActionResult IsAuthenticated([FromBody] IsAuthenticatedRequest request) {
  3. var hash = _userService.IsAuthenticated(HttpContext, request);
  4. switch (hash) {
  5. case "200":
  6. case "401":
  7. return new StatusCodeResult(Convert.ToInt32(hash));
  8. default:
  9. if (HttpContext.Request.Cookies.Contains("TEST")) {
  10. HttpContext.Response.Cookies.Delete("TEST");
  11. }
  12. HttpContext.Response.Cookies.Append("Test", hash, new CookieOptions() {
  13. HttpOnly = true,
  14. Secure = true,
  15. IsEssential = true,
  16. Domain = "localhost",
  17. Expires = new DateTimeOffset(DateTime.Now).AddMinutes(20.0)
  18. });
  19. return new StatusCodeResult(200);
  20. }
  21. }
  22.  
  23. {
  24. "/api/*": {
  25. "target": "https://localhost:5001",
  26. "secure": false,
  27. "topLevel": "debug",
  28. "changeOrigin": true
  29. },
  30. "/login.html": {
  31. "target": "http://localhost:4200/assets/pages",
  32. "secure": false
  33. },
  34. "/": {
  35. "target": "http://localhost:4200",
  36. "secure": false
  37. }
  38. }
  39.  
  40. var paramString = "{username: "test", password: "test"}";
  41. var xhttp = new XMLHttpRequest();
  42. xhttp.onreadystatechange = function() {
  43. if (this.readyState == 4 && this.status == 200) {
  44. window.location.href = "/";
  45. } else if (this.status == 401) {
  46. alert("1");
  47. }
  48. };
  49. xhttp.open("POST", "/api/UserService/IsAuthenticated", true);
  50. xhttp.withCredentials = true;
  51. xhttp.setRequestHeader("Content-type", "application/json-patch+json");
  52. xhttp.setRequestHeader("Access-Control-Allow-Origin", "*");
  53. xhttp.setRequestHeader("Access-Control-Allow-Credentials", "true");
  54. xhttp.send(paramString);
Add Comment
Please, Sign In to add comment