login.blade.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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: #ed9027;
  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: 120px;
  26. height: 120px;
  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. font-size: 16px;
  37. margin-bottom: 20px;
  38. font-weight: normal;
  39. }
  40. .login-container input[type="text"],
  41. .login-container input[type="password"] {
  42. width: 80%;
  43. padding: 10px;
  44. margin: 10px 0;
  45. border: 1px solid #ccc;
  46. border-radius: 4px;
  47. box-sizing: border-box;
  48. transition: border-color 0.3s ease;
  49. }
  50. .login-container button {
  51. margin-top: 20px;
  52. width: 40%;
  53. padding: 10px;
  54. background-color: #4CAF50;
  55. color: white;
  56. border: none;
  57. border-radius: 4px;
  58. cursor: pointer;
  59. }
  60. .login-container button:hover {
  61. background-color: #45a049;
  62. }
  63. /* 取消默认 focus 样式并自定义 */
  64. .login-container input:focus {
  65. outline: none; /* 取消默认的蓝色轮廓 */
  66. border-color: #fbb141; /* 自定义聚焦时的边框颜色 */
  67. }
  68. </style>
  69. </head>
  70. <body>
  71. <!-- 登录表单 -->
  72. <form method="POST" action="/post-login" id="loginForm">
  73. <div class="login-wrapper">
  74. <div class="logo">
  75. <img src="/static/images/logo.png" alt="logo">
  76. </div>
  77. <div class="login-container">
  78. <h2>美特柏产品资料共享图库</h2>
  79. <input type="text" name="username" placeholder="用户名" required>
  80. <input type="password" name="password" placeholder="密码" required>
  81. <div style="color:red;" id="errorMsg"></div>
  82. <button type="submit">登录</button>
  83. </div>
  84. </div>
  85. </form>
  86. <script src="/static/js/jquery-3.7.0.min.js"></script>
  87. <script>
  88. $(document).ready(function() {
  89. // ajaj登录表单提交
  90. $('#loginForm').submit(function(e) {
  91. var username = $('input[name="username"]').val();
  92. var password = $('input[name="password"]').val();
  93. // 获取 CSRF 令牌
  94. var csrfToken = $('meta[name="csrf-token"]').attr('content');
  95. $.ajax({
  96. url: '/post-login',
  97. type: 'POST',
  98. headers: {
  99. 'X-CSRF-TOKEN': csrfToken // 添加 CSRF 令牌到请求头
  100. },
  101. data: {
  102. username: username,
  103. password: password
  104. },
  105. success: function(res) {
  106. if (res.status == 'success') {
  107. window.location.href = '/main';
  108. } else {
  109. $('#errorMsg').html(res.message);
  110. }
  111. },
  112. error: function(err) {
  113. console.log(err);
  114. }
  115. });
  116. return false; // 阻止表单默认提交事件
  117. });
  118. });
  119. </script>
  120. </body>
  121. </html>