jinpengyong
2021-03-22 2dfd3bbb1b4976f0702b1adede273ad6c6939436
screen-api/src/main/java/com/moral/api/controller/LoginController.java
@@ -6,20 +6,23 @@
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.moral.api.entity.Group;
import com.moral.api.service.GroupService;
import com.moral.api.service.SysConfigService;
import com.moral.api.service.UserService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.pojo.VerificationCode;
import com.moral.util.KaptchaUtils;
import com.moral.util.TokenUtils;
import com.moral.util.WebUtils;
@@ -32,12 +35,12 @@
    private UserService userService;
    @Autowired
    private GroupService groupService;
    private SysConfigService sysConfigService;
    @ApiOperation(value = "登陆", notes = "登陆")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "账户", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "password", value = "密码", required = false, paramType = "query", dataType = "String")
            @ApiImplicitParam(name = "account", value = "账户", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "login", method = RequestMethod.POST)
    public ResultMessage login(HttpServletRequest request) {
@@ -47,13 +50,17 @@
        }
        Map<String, Object> result = userService.login(parameters);
        if (!result.containsKey("data")) {
            return ResultMessage.fail(Integer.parseInt(result.get("code").toString()), result.get("msg").toString());
            return ResultMessage.fail((int) result.get("code"), (String) result.get("msg"));
        }
        return ResultMessage.ok(result.get("data"));
    }
    @ApiOperation(value = "注销", notes = "注销")
    @RequestMapping(value = "logout", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "账户", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    public ResultMessage logout(HttpServletRequest request) {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        if (!parameters.containsKey("uid")) {
@@ -65,20 +72,41 @@
        return ResultMessage.ok();
    }
    @ApiOperation(value = "添加组", notes = "添加组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupName", value = "组名", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "addGroup", method = RequestMethod.POST)
    private ResultMessage addGroup(Group group, HttpServletRequest request) {
        String currentUserId = request.getHeader("uid");
        Map<String, Object> map = groupService.addGroup(group, currentUserId);
        String msg = map.get("msg").toString();
        boolean flag = Boolean.parseBoolean(map.get("flag").toString());
        if (flag) {
            return ResultMessage.ok(msg);
        }
        return ResultMessage.fail(msg);
    /**
     * @Description: 获取验证码是否开启
     * @Param: []
     * @return: com.moral.constant.ResultMessage
     * @Author: 陈凯裕
     * @Date: 2021/3/18
     */
    @ApiOperation(value = "获取验证码是否开启", notes = "获取验证码是否开启")
    @RequestMapping(value = "verificationCodeConfig", method = RequestMethod.GET)
    public ResultMessage verifyConfig() {
        return null;
    }
    @ApiOperation(value = "获取验证码", notes = "获取验证码")
    @RequestMapping(value = "verificationCode/get", method = RequestMethod.GET)
    public ResultMessage getVerificationCode() {
        VerificationCode verificationCode = null;
        try {
            verificationCode = KaptchaUtils.createVerificationCode();
        } catch (IOException e) {
            log.error(e.getMessage());
        }
        if (ObjectUtils.isEmpty(verificationCode))
            return ResultMessage.fail();
        return ResultMessage.ok(verificationCode);
    }
    @ApiOperation(value = "校验验证码", notes = "校验验证码")
    @RequestMapping(value = "verificationCode/verify", method = RequestMethod.GET)
    public ResultMessage gverifyVerificationCode(VerificationCode verificationCode) {
        if (!verificationCode.valid())
            return ResultMessage.fail();
        if (KaptchaUtils.verify(verificationCode))
            return ResultMessage.ok();
        return ResultMessage.fail();
    }
}