Advertisement
NeonDriver

Untitled

Apr 18th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.52 KB | None | 0 0
  1. <div class="userInfo" style="display:none;">
  2.     <p>Вы вошли как: <span class="userName"></span></p>
  3.     <input type="button" value="Выйти" id="logOut" />
  4. </div>
  5. <div class="loginForm">
  6.     <h3>Вход на сайт</h3>
  7.     <label>Введите email</label><br />
  8.     <input type="email" id="emailLogin" /> <br /><br />
  9.     <label>Введите пароль</label><br />
  10.     <input type="password" id="passwordLogin" /><br /><br />
  11.     <input type="submit" id="submitLogin" value="Логин" />
  12. </div>
  13.  
  14. <script
  15.  src="https://code.jquery.com/jquery-3.2.1.min.js"
  16.  integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
  17.  crossorigin="anonymous"></script>
  18. <script type="text/javascript">
  19.     $(function () {
  20.         //...........................
  21.  
  22.         var tokenKey = "tokenInfo";
  23.         $('#submitLogin').click(function (e) {
  24.             e.preventDefault();
  25.             var loginData = {
  26.                 grant_type: 'password',
  27.                 username: $('#emailLogin').val(),
  28.                 password: $('#passwordLogin').val()
  29.             };
  30.  
  31.             $.ajax({
  32.                 type: 'POST',
  33.                 url: 'http://134.249.120.107/Token',
  34.                 data: loginData,
  35.                 success: function(data) {
  36.                     console.log(data.access_token);
  37.                 }
  38.             });
  39.         });
  40.  
  41.         $('#logOut').click(function (e) {
  42.             e.preventDefault();
  43.             sessionStorage.removeItem(tokenKey);
  44.         });
  45.     })
  46. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement