package com.ruoyi.web.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.RegisterBody;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.SysRegisterService;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 注册验证
 *
 * @author ruoyi
 */
@RestController
public class SysRegisterController extends BaseController {
	@Autowired
	private SysRegisterService registerService;

	@Autowired
	private ISysConfigService configService;

	@PostMapping("/register")
	public Mono<AjaxResult> register(ServerWebExchange exchange, @RequestBody RegisterBody user) {
		return startMono(() -> {
			if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
				return errorMono("当前系统没有开启注册功能！");
			}
			return registerService.register(exchange, user).map(msg -> {
				return StringUtils.isEmpty(msg) ? success() : error(msg);
			});
		});

	}
}
