Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@inject('userService')
service: IUserService;
/**
* GET /user/profile
*/
@get('/profile')
async profile(ctx) {
const res = await this.service.profile();
ctx.body = res.data;
}
/**
* POST /user/login
*/
@post('/login')
async login(ctx) {
const { username, password } = ctx.query;
if (username === 'admin' && password === 'admin') {
ctx.body = {
status: 200,
statusText: 'ok',
currentAuthority: 'admin',
};
} else if (username === 'user' && password === 'user') {
ctx.body = {
status: 200,
statusText: 'ok',
currentAuthority: 'user',
};
} else {
/**
* POST /user/register
*/
@post('/register')
async register(ctx) {
ctx.body = {
status: 200,
statusText: 'ok',
currentAuthority: 'user',
};
}
/**
* POST /user/logout
*/
@post('/logout')
async logout(ctx) {
ctx.body = {
status: 200,
statusText: 'ok',
currentAuthority: 'guest',
};
}
}
@post('/update')
async update(ctx) {
const id = parseInt(ctx.request.body.id, 10);
ctx.body = await this.postService.update(
id,
ctx.request.body.updates,
);
}
@post('/delete')
async delete(ctx) {
const id = parseInt(ctx.request.body.id, 10);
ctx.body = await this.postService.softDelete(id);
}
@post('/destroy')
async destroy(ctx) {
const id = parseInt(ctx.request.body.id, 10);
ctx.body = await this.postService.destroy(id);
}
}
* @description 注册用户,记录用户账户/密码/
* @router post /api/doRegist
* @request body registUserRequest *body
*/
@post('/doRegist')
async doRegist() {
this.ctx.body = 'doRegist' + await this.userService.getUser();
}
/**
* @summary 用户登录
* @description 用户登录
* @router post /api/doLogin
* @request body registUserRequest *body
*/
@post('/doLogin')
async doLogin() {
this.ctx.body = 'doLogin' + await this.userService.getUser();
}
}
statusText: 'ok',
currentAuthority: 'user',
};
} else {
ctx.body = {
status: 401,
statusText: 'unauthorized',
currentAuthority: 'guest',
};
}
}
/**
* POST /user/register
*/
@post('/register')
async register(ctx) {
ctx.body = {
status: 200,
statusText: 'ok',
currentAuthority: 'user',
};
}
/**
* POST /user/logout
*/
@post('/logout')
async logout(ctx) {
ctx.body = {
status: 200,
statusText: 'ok',
@get('/')
async index(ctx) {
const query = {
limit: parseInt(ctx.query.limit, 10) || 10,
offset: parseInt(ctx.query.offset, 10) || 0,
};
ctx.body = await this.postService.list(query);
}
@get('/find')
async show(ctx) {
ctx.body = await this.postService.find(parseInt(ctx.query.id, 10));
}
@post('/create')
async create(ctx) {
ctx.body = await this.postService.create(ctx.request.body);
}
@post('/update')
async update(ctx) {
const id = parseInt(ctx.request.body.id, 10);
ctx.body = await this.postService.update(
id,
ctx.request.body.updates,
);
}
@post('/delete')
async delete(ctx) {
const id = parseInt(ctx.request.body.id, 10);
@inject('userService')
service: IUserService;
/**
* GET /user/profile
*/
@get('/profile')
async profile() {
const res = await this.service.profile();
this.ctx.body = res.data;
}
/**
* POST /user/login
*/
@post('/login')
async login() {
const { username, password } = this.ctx.query;
if (username === 'admin' && password === 'admin') {
this.ctx.body = {
status: 200,
statusText: 'ok',
currentAuthority: 'admin',
};
} else if (username === 'user' && password === 'user') {
this.ctx.body = {
status: 200,
statusText: 'ok',
currentAuthority: 'user',
};
} else {
@controller('/api')
export default class APIController {
@inject()
ctx: Context;
@inject()
userService;
/**
* @summary 注册用户
* @description 注册用户,记录用户账户/密码/
* @router post /api/doRegist
* @request body registUserRequest *body
*/
@post('/doRegist')
async doRegist() {
this.ctx.body = 'doRegist' + await this.userService.getUser();
}
/**
* @summary 用户登录
* @description 用户登录
* @router post /api/doLogin
* @request body registUserRequest *body
*/
@post('/doLogin')
async doLogin() {
this.ctx.body = 'doLogin' + await this.userService.getUser();
}
}
/**
* POST /user/register
*/
@post('/register')
async register() {
this.ctx.body = {
status: 200,
statusText: 'ok',
currentAuthority: 'user',
};
}
/**
* POST /user/logout
*/
@post('/logout')
async logout() {
this.ctx.body = {
status: 200,
statusText: 'ok',
currentAuthority: 'guest',
};
}
}
@post('/create')
async create(ctx) {
ctx.body = await this.postService.create(ctx.request.body);
}
@post('/update')
async update(ctx) {
const id = parseInt(ctx.request.body.id, 10);
ctx.body = await this.postService.update(
id,
ctx.request.body.updates,
);
}
@post('/delete')
async delete(ctx) {
const id = parseInt(ctx.request.body.id, 10);
ctx.body = await this.postService.softDelete(id);
}
@post('/destroy')
async destroy(ctx) {
const id = parseInt(ctx.request.body.id, 10);
ctx.body = await this.postService.destroy(id);
}
}