2023-06-27 09:29:43 +08:00
|
|
|
import {
|
|
|
|
|
ALL,
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Inject,
|
|
|
|
|
Post,
|
|
|
|
|
Provide,
|
2024-07-15 00:30:33 +08:00
|
|
|
} from '@midwayjs/core';
|
|
|
|
|
import { BaseController } from '../../../basic/base-controller.js';
|
|
|
|
|
import { Constants } from '../../../basic/constants.js';
|
|
|
|
|
import { UserService } from '../../authority/service/user-service.js';
|
|
|
|
|
import { UserEntity } from '../../authority/entity/user.js';
|
|
|
|
|
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
|
2023-06-27 09:29:43 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
@Provide()
|
|
|
|
|
@Controller('/api/')
|
|
|
|
|
export class RegisterController extends BaseController {
|
|
|
|
|
@Inject()
|
|
|
|
|
userService: UserService;
|
2024-06-16 00:20:02 +08:00
|
|
|
|
|
|
|
|
@Inject()
|
|
|
|
|
sysSettingsService: SysSettingsService;
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/register', { summary: Constants.per.guest })
|
|
|
|
|
public async register(
|
|
|
|
|
@Body(ALL)
|
|
|
|
|
user: UserEntity
|
|
|
|
|
) {
|
2024-06-16 00:20:02 +08:00
|
|
|
const sysPublicSettings = await this.sysSettingsService.getPublicSettings();
|
|
|
|
|
if (sysPublicSettings.registerEnabled === false) {
|
|
|
|
|
throw new Error('当前站点已禁止自助注册功能');
|
|
|
|
|
}
|
2023-06-27 09:29:43 +08:00
|
|
|
const newUser = await this.userService.register(user);
|
|
|
|
|
return this.ok(newUser);
|
|
|
|
|
}
|
|
|
|
|
}
|