package com.trade.admin.system.controller;

import com.trade.admin.system.service.ISysConfigService;
import com.trade.common.core.domain.ResponseResult;
import com.trade.common.exception.ServiceException;
import com.trade.common.utils.StringUtils;
import com.trade.admin.system.domain.model.RegisterBody;
import com.trade.admin.system.service.ISysRegisterService;
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;

/**
 * 注册验证
 * 
 * @author WL
 */
@RestController
public class SysRegisterController extends BaseController {

    @Autowired
    private ISysRegisterService registerService;
    @Autowired
    private ISysConfigService configService;

    @PostMapping("/register")
    public ResponseResult register(@RequestBody RegisterBody user) {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
            throw new ServiceException("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }
}
