login.html 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. <title>PlateRecApp - 登录</title>
  7. <style>
  8. * { margin: 0; padding: 0; box-sizing: border-box; }
  9. body {
  10. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  11. background: #0f1419;
  12. color: #e1e8ed;
  13. min-height: 100vh;
  14. display: flex;
  15. align-items: center;
  16. justify-content: center;
  17. }
  18. .login-container {
  19. width: 100%;
  20. max-width: 400px;
  21. padding: 20px;
  22. }
  23. .login-card {
  24. background: #1a2332;
  25. border-radius: 12px;
  26. padding: 40px 32px;
  27. box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  28. border: 1px solid #2a3a4a;
  29. }
  30. .logo {
  31. text-align: center;
  32. margin-bottom: 32px;
  33. }
  34. .logo h1 {
  35. font-size: 24px;
  36. font-weight: 600;
  37. color: #4fc3f7;
  38. margin-bottom: 4px;
  39. }
  40. .logo p {
  41. font-size: 13px;
  42. color: #6b7b8d;
  43. }
  44. .form-group {
  45. margin-bottom: 20px;
  46. }
  47. .form-group label {
  48. display: block;
  49. font-size: 13px;
  50. color: #8899aa;
  51. margin-bottom: 6px;
  52. font-weight: 500;
  53. }
  54. .form-group input {
  55. width: 100%;
  56. padding: 12px 16px;
  57. background: #0f1419;
  58. border: 1px solid #2a3a4a;
  59. border-radius: 8px;
  60. color: #e1e8ed;
  61. font-size: 15px;
  62. transition: border-color 0.2s, box-shadow 0.2s;
  63. outline: none;
  64. }
  65. .form-group input:focus {
  66. border-color: #4fc3f7;
  67. box-shadow: 0 0 0 3px rgba(79,195,247,0.15);
  68. }
  69. .form-group input::placeholder {
  70. color: #4a5568;
  71. }
  72. .form-options {
  73. display: flex;
  74. justify-content: space-between;
  75. align-items: center;
  76. margin-bottom: 24px;
  77. font-size: 13px;
  78. }
  79. .remember-me {
  80. display: flex;
  81. align-items: center;
  82. gap: 6px;
  83. cursor: pointer;
  84. color: #8899aa;
  85. }
  86. .remember-me input[type="checkbox"] {
  87. width: 16px;
  88. height: 16px;
  89. accent-color: #4fc3f7;
  90. cursor: pointer;
  91. }
  92. .btn-login {
  93. width: 100%;
  94. padding: 12px;
  95. background: linear-gradient(135deg, #4fc3f7, #0288d1);
  96. border: none;
  97. border-radius: 8px;
  98. color: white;
  99. font-size: 15px;
  100. font-weight: 600;
  101. cursor: pointer;
  102. transition: opacity 0.2s, transform 0.1s;
  103. }
  104. .btn-login:hover { opacity: 0.9; }
  105. .btn-login:active { transform: scale(0.98); }
  106. .btn-login:disabled {
  107. opacity: 0.6;
  108. cursor: not-allowed;
  109. }
  110. .error-msg {
  111. background: rgba(239,68,68,0.1);
  112. border: 1px solid rgba(239,68,68,0.3);
  113. color: #f87171;
  114. padding: 10px 14px;
  115. border-radius: 8px;
  116. font-size: 13px;
  117. margin-bottom: 16px;
  118. display: none;
  119. }
  120. .error-msg.show { display: block; }
  121. .rate-limit-msg {
  122. background: rgba(245,158,11,0.1);
  123. border: 1px solid rgba(245,158,11,0.3);
  124. color: #fbbf24;
  125. padding: 10px 14px;
  126. border-radius: 8px;
  127. font-size: 13px;
  128. margin-bottom: 16px;
  129. display: none;
  130. }
  131. .footer {
  132. text-align: center;
  133. margin-top: 24px;
  134. font-size: 12px;
  135. color: #4a5568;
  136. }
  137. .loading-spinner {
  138. display: inline-block;
  139. width: 16px;
  140. height: 16px;
  141. border: 2px solid rgba(255,255,255,0.3);
  142. border-top-color: white;
  143. border-radius: 50%;
  144. animation: spin 0.6s linear infinite;
  145. margin-right: 8px;
  146. vertical-align: middle;
  147. }
  148. @keyframes spin { to { transform: rotate(360deg); } }
  149. @media (max-width: 480px) {
  150. .login-container { padding: 12px; }
  151. .login-card { padding: 24px 20px; }
  152. .logo h1 { font-size: 20px; }
  153. .form-group input { padding: 10px 12px; font-size: 14px; }
  154. .btn-login { padding: 10px; font-size: 14px; }
  155. }
  156. </style>
  157. </head>
  158. <body>
  159. <div class="login-container">
  160. <div class="login-card">
  161. <div class="logo">
  162. <h1>🔒 PlateRecApp</h1>
  163. <p>车牌识别管理系统</p>
  164. </div>
  165. <div id="error-msg" class="error-msg"></div>
  166. <div id="rate-limit-msg" class="rate-limit-msg"></div>
  167. <form id="login-form" autocomplete="off">
  168. <div class="form-group">
  169. <label for="username">用户名</label>
  170. <input type="text" id="username" name="username"
  171. placeholder="请输入用户名" required autofocus
  172. autocomplete="username">
  173. </div>
  174. <div class="form-group">
  175. <label for="password">密码</label>
  176. <input type="password" id="password" name="password"
  177. placeholder="请输入密码" required
  178. autocomplete="current-password">
  179. </div>
  180. <div class="form-options">
  181. <label class="remember-me">
  182. <input type="checkbox" id="remember" name="remember">
  183. 记住登录 (7天)
  184. </label>
  185. </div>
  186. <button type="submit" class="btn-login" id="btn-login">登 录</button>
  187. </form>
  188. <div class="footer">
  189. PlateRecApp v5.0 | Secure Login
  190. </div>
  191. </div>
  192. </div>
  193. <script>
  194. const form = document.getElementById('login-form');
  195. const btnLogin = document.getElementById('btn-login');
  196. const errorDiv = document.getElementById('error-msg');
  197. const rateLimitDiv = document.getElementById('rate-limit-msg');
  198. // Check if already logged in
  199. fetch('/api/auth/status')
  200. .then(r => r.json())
  201. .then(data => {
  202. if (data.authenticated) {
  203. const redirect = new URLSearchParams(window.location.search).get('redirect') || '/';
  204. window.location.href = redirect;
  205. }
  206. })
  207. .catch(() => {});
  208. form.addEventListener('submit', async (e) => {
  209. e.preventDefault();
  210. errorDiv.classList.remove('show');
  211. rateLimitDiv.classList.remove('show');
  212. btnLogin.disabled = true;
  213. btnLogin.innerHTML = '<span class="loading-spinner"></span>登录中...';
  214. const username = document.getElementById('username').value.trim();
  215. const password = document.getElementById('password').value;
  216. const remember = document.getElementById('remember').checked;
  217. try {
  218. const resp = await fetch('/api/auth/login', {
  219. method: 'POST',
  220. headers: { 'Content-Type': 'application/json' },
  221. body: JSON.stringify({ username, password, remember })
  222. });
  223. const data = await resp.json();
  224. if (resp.status === 429) {
  225. rateLimitDiv.textContent = data.message || '请求过于频繁,请稍后再试';
  226. rateLimitDiv.classList.add('show');
  227. } else if (resp.status === 401) {
  228. errorDiv.textContent = data.message || '用户名或密码错误';
  229. errorDiv.classList.add('show');
  230. document.getElementById('password').value = '';
  231. document.getElementById('password').focus();
  232. } else if (resp.status === 423) {
  233. errorDiv.textContent = data.message || '账户已锁定,请稍后再试';
  234. errorDiv.classList.add('show');
  235. } else if (data.success) {
  236. const redirect = new URLSearchParams(window.location.search).get('redirect') || '/';
  237. window.location.href = redirect;
  238. return;
  239. } else {
  240. errorDiv.textContent = data.message || '登录失败';
  241. errorDiv.classList.add('show');
  242. }
  243. } catch (err) {
  244. errorDiv.textContent = '网络错误,请重试';
  245. errorDiv.classList.add('show');
  246. }
  247. btnLogin.disabled = false;
  248. btnLogin.textContent = '登 录';
  249. });
  250. </script>
  251. </body>
  252. </html>