package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.service.SysLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.web.service.SysRegisterService;
import com.ruoyi.system.service.ISysConfigService;

/**
 * 注册验证
 * 
 * @author ruoyi
 */
@RestController
@Api(tags = "系统-完善信息")
public class SysRegisterController extends BaseController
{
    @Autowired
    private SysRegisterService registerService;

    @Autowired
    private SysLoginService sysLoginService;

    @PostMapping("/registry")
    @ApiOperation("注册完善")
    @Anonymous
    public AjaxResult registry(@RequestBody RegisterBody user)
    {
        String msg = registerService.register(user, null);
        if(StringUtils.isEmpty(msg)) {
            // 生成token
            AjaxResult ajax = AjaxResult.success();
            ajax.put(Constants.TOKEN, sysLoginService.loginInner(user.getUsername(), user.getPassword()));
            return ajax;
        }
        return error(msg);
    }

    @PostMapping("/improve")
    @ApiOperation("登陆完善")
    public AjaxResult improve(@RequestBody RegisterBody user)
    {
        String msg = registerService.register(user, SecurityUtils.getLoginUser());
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }
}
