login.blade.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta name="csrf-token" content="{{ csrf_token() }}">
  7. <title>相册系统登录</title>
  8. <style>
  9. body {
  10. background-color: #2B2C30;
  11. display: flex;
  12. justify-content: center;
  13. align-items: center;
  14. height: 100vh;
  15. margin: 0;
  16. font-family: Arial, sans-serif;
  17. }
  18. .login-wrapper {
  19. text-align: center;
  20. }
  21. .logo {
  22. margin-bottom: 20px; /* 调整 logo 与 login-container 的间距 */
  23. }
  24. .logo img {
  25. width: 150px;
  26. height: 150px;
  27. }
  28. .login-container {
  29. background-color: #fff;
  30. padding: 20px;
  31. border-radius: 8px;
  32. box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  33. text-align: center;
  34. }
  35. .login-container h2 {
  36. margin-bottom: 20px;
  37. }
  38. .login-container input[type="text"],
  39. .login-container input[type="password"] {
  40. width: 80%;
  41. padding: 10px;
  42. margin: 10px 0;
  43. border: 1px solid #ccc;
  44. border-radius: 4px;
  45. }
  46. .login-container button {
  47. margin-top: 20px;
  48. width: 40%;
  49. padding: 10px;
  50. background-color: #4CAF50;
  51. color: white;
  52. border: none;
  53. border-radius: 4px;
  54. cursor: pointer;
  55. }
  56. .login-container button:hover {
  57. background-color: #45a049;
  58. }
  59. </style>
  60. </head>
  61. <body>
  62. <!-- 登录表单 -->
  63. <form method="POST" action="/post-login" id="loginForm">
  64. <div class="login-wrapper">
  65. <div class="logo">
  66. <img src="/static/images/logo.png" alt="logo">
  67. </div>
  68. <div class="login-container">
  69. <h2>登录</h2>
  70. <input type="text" name="username" placeholder="用户名" required>
  71. <input type="password" name="password" placeholder="密码" required>
  72. <div style="color:red;" id="errorMsg"></div>
  73. <button type="submit">登录</button>
  74. </div>
  75. </div>
  76. </form>
  77. <script src="/static/js/jquery-3.7.0.min.js"></script>
  78. <script>
  79. $(document).ready(function() {
  80. // ajaj登录表单提交
  81. $('#loginForm').submit(function(e) {
  82. var username = $('input[name="username"]').val();
  83. var password = $('input[name="password"]').val();
  84. // 获取 CSRF 令牌
  85. var csrfToken = $('meta[name="csrf-token"]').attr('content');
  86. $.ajax({
  87. url: '/post-login',
  88. type: 'POST',
  89. headers: {
  90. 'X-CSRF-TOKEN': csrfToken // 添加 CSRF 令牌到请求头
  91. },
  92. data: {
  93. username: username,
  94. password: password
  95. },
  96. success: function(res) {
  97. if (res.status == 'success') {
  98. window.location.href = '/index';
  99. } else {
  100. $('#errorMsg').html(res.message);
  101. }
  102. },
  103. error: function(err) {
  104. console.log(err);
  105. }
  106. });
  107. return false; // 阻止表单默认提交事件
  108. });
  109. });
  110. </script>
  111. </body>
  112. </html>