Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @{
- ViewBag.Title = "Home Page";
- }
- <div class="jumbotron">
- <h1>Site</h1>
- <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
- <p><a href="https://asp.net" class="btn btn-primary btn-lg">Learn more »</a></p>
- </div>
- <!-- Modal -->
- <div id="myModal" class="modal fade" role="dialog">
- <div class="modal-dialog">
- <!-- Modal content-->
- <div class="modal-content">
- <div class="modal-header">
- <button type="button" class="close" data-dismiss="modal">×</button>
- <h4 class="modal-title">Modal Header</h4>
- </div>
- <div class="modal-body form-group">
- <label for="username">Username: </label>
- <input type="text" id="username" class="form-control" placeholder="username" value="test@test.com" />
- <br />
- <label for="password">Password: </label>
- <input type="password" id="password" class="form-control" placeholder="password" value="123456" />
- <br />
- <button id="enter" class="btn btn-success">Enter</button>
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
- </div>
- </div>
- </div>
- </div>
- @section scripts {
- <script>
- var token = localStorage.getItem("token");
- if (token) {
- getItems();
- }
- else {
- $("#myModal").modal('show')
- }
- $('#enter').click(function () {
- $.ajax(
- {
- url: 'http://localhost:58645/token',
- type: "POST",
- contentType: "application/x-www-form-urlencoded",
- dataType: "json",
- data:
- {
- username: $('#username').val(),
- password: $('#password').val(),
- grant_type: "password"
- }
- ,
- success: function (res) {
- localStorage.setItem("token", res.access_token);
- console.log("Токен збережено");
- },
- error: function () {
- alert("Error");
- }
- }
- );
- });
- function getItems() {
- $.ajax(
- {
- url: 'http://localhost:58645/api/values',
- type: "GET",
- success: function (res) {
- console.log(res);
- },
- error: function () {
- alert("Error");
- }
- }
- );
- }
- </script>
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement