package com.ghy.web.controller.system;

import com.ghy.common.core.domain.dto.SysUserAddDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.core.domain.entity.SysUser;
import com.ghy.common.utils.StringUtils;
import com.ghy.framework.shiro.service.SysRegisterService;
import com.ghy.system.service.ISysConfigService;

import javax.validation.Valid;

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

    @Autowired
    private ISysConfigService configService;

    @GetMapping("/register")
    public String register()
    {
        return "register";
    }

    @PostMapping("/register")
    @ResponseBody
    public AjaxResult ajaxRegister(@Valid SysUserAddDTO userAddDTO)
    {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
        {
            return error("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(userAddDTO);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }
}
