Advertisement
Guest User

Untitled

a guest
Dec 25th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. @{
  2. ViewBag.Title = "Home Page";
  3. }
  4.  
  5. <div class="jumbotron">
  6. <h1>Site</h1>
  7. <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
  8. <p><a href="https://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
  9. </div>
  10.  
  11. <!-- Modal -->
  12. <div id="myModal" class="modal fade" role="dialog">
  13. <div class="modal-dialog">
  14.  
  15. <!-- Modal content-->
  16. <div class="modal-content">
  17. <div class="modal-header">
  18. <button type="button" class="close" data-dismiss="modal">&times;</button>
  19. <h4 class="modal-title">Modal Header</h4>
  20. </div>
  21. <div class="modal-body form-group">
  22.  
  23. <label for="username">Username: </label>
  24. <input type="text" id="username" class="form-control" placeholder="username" value="test@test.com" />
  25. <br />
  26.  
  27. <label for="password">Password: </label>
  28. <input type="password" id="password" class="form-control" placeholder="password" value="123456" />
  29.  
  30. <br />
  31. <button id="enter" class="btn btn-success">Enter</button>
  32. </div>
  33. <div class="modal-footer">
  34. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  35. </div>
  36. </div>
  37.  
  38. </div>
  39. </div>
  40.  
  41. @section scripts {
  42.  
  43. <script>
  44.  
  45. var token = localStorage.getItem("token");
  46.  
  47. if (token) {
  48. getItems();
  49. }
  50. else {
  51. $("#myModal").modal('show')
  52. }
  53.  
  54. $('#enter').click(function () {
  55.  
  56. $.ajax(
  57. {
  58. url: 'http://localhost:58645/token',
  59. type: "POST",
  60. contentType: "application/x-www-form-urlencoded",
  61. dataType: "json",
  62. data:
  63. {
  64. username: $('#username').val(),
  65. password: $('#password').val(),
  66. grant_type: "password"
  67. }
  68. ,
  69. success: function (res) {
  70. localStorage.setItem("token", res.access_token);
  71. console.log("Токен збережено");
  72. },
  73. error: function () {
  74. alert("Error");
  75. }
  76.  
  77. }
  78. );
  79.  
  80. });
  81.  
  82.  
  83. function getItems() {
  84. $.ajax(
  85. {
  86. url: 'http://localhost:58645/api/values',
  87. type: "GET",
  88. success: function (res) {
  89. console.log(res);
  90. },
  91. error: function () {
  92. alert("Error");
  93. }
  94.  
  95. }
  96. );
  97. }
  98.  
  99.  
  100. </script>
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement