feat: 初始化应用修改

This commit is contained in:
2025-02-23 10:22:06 +08:00
parent c61999e2a4
commit 4e080a0b93
5 changed files with 81 additions and 25 deletions

View File

@@ -4,3 +4,5 @@ import './org.ts';
import './me.ts';
import './update.ts'
import './init.ts'

34
src/routes/user/init.ts Normal file
View File

@@ -0,0 +1,34 @@
import { UserServices } from '@/models/user.ts';
import { app } from '@/app.ts';
app
.route({
path: 'user',
key: 'init',
})
.define(async (ctx) => {
const { password } = ctx.query.data || {};
if (!password) {
ctx.throw(500, 'root password are required');
}
const res = await UserServices.initializeUser(password);
ctx.body = res;
})
.addTo(app);
app
.route({
path: 'user',
key: 'createDemo',
middleware: ['auth'],
})
.define(async (ctx) => {
const { username, password } = ctx.query.data || {};
if (!username && username.startsWith('demo')) {
ctx.throw(500, 'username are required, and must start with demo');
}
const res = await UserServices.createDemoUser(username, password);
ctx.body = res;
})
.addTo(app);

View File

@@ -1,6 +1,7 @@
import { app } from '@/app.ts';
import { Org } from '@/models/org.ts';
import { User } from '@/models/user.ts';
import { domain } from '@/modules/domain.ts';
app
.route({
@@ -38,12 +39,6 @@ app
if (!user && email) {
user = await User.findOne({ where: { email } });
}
console.log('user logiin', ctx.query);
console.log('user logiin', user);
console.log(
'users',
(await User.findAll()).map((u) => u.username),
);
if (!user) {
ctx.throw(500, 'Login Failed');
}
@@ -53,7 +48,7 @@ app
const token = await user.createToken(null, loginType);
ctx.res.cookie('token', token.token, {
maxAge: token.expireTime,
domain: 'xiongxiao.me',
domain: { domain },
sameSite: 'lax',
httpOnly: true,
});
@@ -69,7 +64,7 @@ app
.define(async (ctx) => {
ctx.res.cookie('token', '', {
maxAge: 0,
domain: 'xiongxiao.me',
domain: `${domain}`,
sameSite: 'lax',
httpOnly: true,
});