login.html 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <html>
  2. <head>
  3. <title>Login</title>
  4. <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
  5. </script>
  6. </head>
  7. <body>
  8. <h1>User Login</h1>
  9. <p>Username:</p>
  10. <input id="username" type="text">
  11. <p>Password:</p>
  12. <input id="password" type="password">
  13. <br>
  14. <br>
  15. <button onclick="handleLogin()">Login</button>
  16. <script>
  17. function handleLogin() {
  18. var username = $("#username").val();
  19. var password = $("#password").val();
  20. $.ajax({
  21. url: "/login",
  22. data: {username: username, password: password},
  23. success: function(value){
  24. var response = JSON.parse(value)
  25. if (response.Success == true){
  26. alert("Sucess! You have logged in!");
  27. window.location.href = '/logout.html'+'#'+username;
  28. }else{
  29. if (response.Repeat == true){
  30. alert("Alert: " + username + " has already loggged in, please logged in with a different account!")
  31. } else{
  32. alert("Incorrect Username/Password!");
  33. }
  34. }
  35. }
  36. });
  37. }
  38. </script>
  39. </body>
  40. </html>