temp
This commit is contained in:
34
assistant/src/routes/user/index.ts
Normal file
34
assistant/src/routes/user/index.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { app, assistantConfig } from '../../app.ts';
|
||||
|
||||
app.route({
|
||||
path: 'admin',
|
||||
key: 'login',
|
||||
description: '管理员用户登录',
|
||||
}).define(async (ctx) => {
|
||||
const { username, password } = ctx.query;
|
||||
const query = assistantConfig.query;
|
||||
const auth = assistantConfig.getConfig().auth;
|
||||
const res = await query.post({
|
||||
path: 'user',
|
||||
key: 'login',
|
||||
data: {
|
||||
username,
|
||||
password,
|
||||
},
|
||||
})
|
||||
if (res.code !== 200) {
|
||||
return ctx.throw(401, 'login failed');
|
||||
}
|
||||
const loginUser = res.data.username;
|
||||
if (auth.username && loginUser !== auth.username) {
|
||||
return ctx.throw(403, 'login user is not admin user');
|
||||
}
|
||||
if (!auth.username) {
|
||||
// 初始管理员账号
|
||||
auth.username = 'admin';
|
||||
assistantConfig.setConfig({ auth });
|
||||
}
|
||||
// 保存配置
|
||||
|
||||
ctx.body = res.data;
|
||||
}).addTo(app);
|
||||
Reference in New Issue
Block a user