35 lines
782 B
TypeScript
35 lines
782 B
TypeScript
import { User } 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 User.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 User.createDemoUser(username, password);
|
|
ctx.body = res;
|
|
})
|
|
.addTo(app);
|