Browse Source
- Added AuthController for user registration, login, and fetching user details. - Introduced JobController for managing scheduled jobs, including listing, starting, stopping, and updating job frequency. - Created StatusController to provide a simple health check endpoint. - Implemented session middleware for managing user sessions. - Developed login and registration pages with form handling and validation.feat/collect
17 changed files with 3329 additions and 113 deletions
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
@ -0,0 +1,14 @@ |
|||
import session from 'koa-session'; |
|||
|
|||
export default (app) => { |
|||
const CONFIG = { |
|||
key: 'koa:sess', // cookie key
|
|||
maxAge: 86400000, // 1天
|
|||
httpOnly: true, |
|||
signed: true, |
|||
rolling: false, |
|||
renew: false, |
|||
}; |
|||
app.keys = app.keys || ['koa3-demo-session-secret']; |
|||
return session(CONFIG, app); |
|||
}; |
|||
@ -0,0 +1,31 @@ |
|||
extends /layouts/page.pug |
|||
|
|||
block content |
|||
.login-container |
|||
h2 登录 |
|||
form#loginForm(action="/login" method="post") |
|||
.form-group |
|||
label(for="username") 用户名 |
|||
input#username(type="text" name="username" required placeholder="请输入用户名") |
|||
.form-group |
|||
label(for="password") 密码 |
|||
input#password(type="password" name="password" required placeholder="请输入密码") |
|||
button(type="submit") 登录 |
|||
script. |
|||
document.getElementById('loginForm').onsubmit = async function(e) { |
|||
e.preventDefault(); |
|||
const form = e.target; |
|||
const data = Object.fromEntries(new FormData(form)); |
|||
const res = await fetch(form.action, { |
|||
method: 'POST', |
|||
headers: { 'Content-Type': 'application/json' }, |
|||
body: JSON.stringify(data) |
|||
}); |
|||
const result = await res.json(); |
|||
if(result.success) { |
|||
alert('登录成功'); |
|||
window.location.href = '/'; |
|||
} else { |
|||
alert(result.message || '登录失败'); |
|||
} |
|||
} |
|||
@ -0,0 +1,94 @@ |
|||
doctype html |
|||
html |
|||
head |
|||
meta(charset="UTF-8") |
|||
meta(name="viewport", content="width=device-width, initial-scale=1.0") |
|||
title 注册 |
|||
style. |
|||
body { |
|||
background: #f5f7fa; |
|||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; |
|||
} |
|||
.register-container { |
|||
max-width: 400px; |
|||
margin: 60px auto; |
|||
background: #fff; |
|||
border-radius: 10px; |
|||
box-shadow: 0 2px 16px rgba(0,0,0,0.08); |
|||
padding: 32px 28px 24px 28px; |
|||
} |
|||
.register-title { |
|||
text-align: center; |
|||
font-size: 2rem; |
|||
margin-bottom: 24px; |
|||
color: #333; |
|||
font-weight: 600; |
|||
} |
|||
.form-group { |
|||
margin-bottom: 18px; |
|||
} |
|||
label { |
|||
display: block; |
|||
margin-bottom: 6px; |
|||
color: #555; |
|||
font-size: 1rem; |
|||
} |
|||
input[type="text"], |
|||
input[type="email"], |
|||
input[type="password"] { |
|||
width: 100%; |
|||
padding: 10px 12px; |
|||
border: 1px solid #d1d5db; |
|||
border-radius: 6px; |
|||
font-size: 1rem; |
|||
background: #f9fafb; |
|||
transition: border 0.2s; |
|||
} |
|||
input:focus { |
|||
border-color: #409eff; |
|||
outline: none; |
|||
} |
|||
.register-btn { |
|||
width: 100%; |
|||
padding: 12px 0; |
|||
background: linear-gradient(90deg, #409eff 0%, #66b1ff 100%); |
|||
color: #fff; |
|||
border: none; |
|||
border-radius: 6px; |
|||
font-size: 1.1rem; |
|||
font-weight: 600; |
|||
cursor: pointer; |
|||
margin-top: 10px; |
|||
transition: background 0.2s; |
|||
} |
|||
.register-btn:hover { |
|||
background: linear-gradient(90deg, #66b1ff 0%, #409eff 100%); |
|||
} |
|||
.login-link { |
|||
display: block; |
|||
text-align: right; |
|||
margin-top: 14px; |
|||
color: #409eff; |
|||
text-decoration: none; |
|||
font-size: 0.95rem; |
|||
} |
|||
.login-link:hover { |
|||
text-decoration: underline; |
|||
body |
|||
.register-container |
|||
.register-title 注册账号 |
|||
form(action="/register" method="post") |
|||
.form-group |
|||
label(for="username") 用户名 |
|||
input(type="text" id="username" name="username" required placeholder="请输入用户名") |
|||
.form-group |
|||
label(for="email") 邮箱 |
|||
input(type="email" id="email" name="email" required placeholder="请输入邮箱") |
|||
.form-group |
|||
label(for="password") 密码 |
|||
input(type="password" id="password" name="password" required placeholder="请输入密码") |
|||
.form-group |
|||
label(for="confirm_password") 确认密码 |
|||
input(type="password" id="confirm_password" name="confirm_password" required placeholder="请再次输入密码") |
|||
button.register-btn(type="submit") 注册 |
|||
a.login-link(href="/login") 已有账号?去登录 |
|||
Loading…
Reference in new issue