User.ts 926 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import ApiController from './ApiController';
  2. class UserController extends ApiController {
  3. async register() {
  4. const createRule = {
  5. username: {
  6. type: 'string',
  7. min: 4,
  8. max: 32,
  9. trim: true,
  10. },
  11. password: {
  12. type: 'string',
  13. min: 32,
  14. max: 32,
  15. trim: true,
  16. },
  17. };
  18. const err = this.app.validator.validate(createRule, this.ctx.request.body);
  19. if (err) {
  20. return this.fail('不知道怎么返回');
  21. }
  22. const params = this.ctx.request.body;
  23. const user = await this.ctx.model.User.create({
  24. username: params.username,
  25. name: '',
  26. password: '123',
  27. salt: '123',
  28. });
  29. return this.success(user);
  30. }
  31. }
  32. export default UserController;