login.blade.php 3.7 KB

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