| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.SysConfig; |
| | | import com.moral.api.service.SysConfigService; |
| | | import com.moral.api.service.UserLogService; |
| | | import com.moral.api.service.UserService; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | |
| | | @Autowired |
| | | private SysConfigService sysConfigService; |
| | | |
| | | @Autowired |
| | | private UserLogService userLogService; |
| | | |
| | | @ApiOperation(value = "登陆", notes = "登陆") |
| | | @RequestMapping(value = "login", method = RequestMethod.POST) |
| | | public ResultMessage login(@RequestBody Map<String, Object> parameters, HttpServletRequest request) { |
| | | public ResultMessage login(@RequestBody Map<String, Object> parameters) { |
| | | if (!(parameters.containsKey("account") && parameters.containsKey("password"))) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | Map<String, Object> result = userService.login(parameters); |
| | | if (!result.containsKey("data")) { |
| | | if (!result.containsKey("token")) { |
| | | return ResultMessage.fail((int) result.get("code"), (String) result.get("msg")); |
| | | } |
| | | Map<String, Object> data = (Map<String, Object>) result.get("data"); |
| | | return ResultMessage.ok(data); |
| | | return ResultMessage.ok(result); |
| | | } |
| | | |
| | | @ApiOperation(value = "退出", notes = "退出") |
| | | @RequestMapping(value = "logout", method = RequestMethod.POST) |
| | | @ApiOperation(value = "获取用户信息", notes = "获取用户信息") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") |
| | | }) |
| | | public ResultMessage logout(@RequestBody Map<String, Object> parameters, HttpServletRequest request) { |
| | | if (!parameters.containsKey("uid")) { |
| | | @RequestMapping(value = "getUserInfo", method = RequestMethod.POST) |
| | | public ResultMessage getUserInfo(HttpServletRequest request) { |
| | | String token = request.getHeader("token"); |
| | | Map<String, Object> result = userService.getUserInfo(token); |
| | | return ResultMessage.ok(result); |
| | | } |
| | | |
| | | @ApiOperation(value = "退出", notes = "退出") |
| | | @RequestMapping(value = "logout", method = RequestMethod.GET) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") |
| | | }) |
| | | public ResultMessage logout(Integer userId, HttpServletRequest request) { |
| | | if (userId == null) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | String token = request.getHeader("token"); |
| | | TokenUtils.destoryToken(parameters.get("uid").toString(), token); |
| | | TokenUtils.destoryToken(userId.toString(), token); |
| | | return ResultMessage.ok(); |
| | | } |
| | | |
| | | /** |
| | | * @Description: 获取验证码是否开启 |
| | | * @Param: [] |
| | | * @return: com.moral.constant.ResultMessage |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/3/18 |
| | | */ |
| | | |
| | | @ApiOperation(value = "获取验证码是否开启", notes = "获取验证码是否开启") |
| | | @RequestMapping(value = "verificationCode/config", method = RequestMethod.GET) |
| | | public void verifyConfig(HttpServletResponse response) { |
| | | public ResultMessage verifyConfig(HttpServletResponse response) { |
| | | QueryWrapper<SysConfig> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("type", Constants.VERIFICATION_TYPE); |
| | | queryWrapper.eq(Constants.FRONT_VERIFICATIONCODE_COLUMN, Constants.FRONT_ERIFICATIONCODE_VALUE); |
| | | SysConfig sysConfig = sysConfigService.getOne(queryWrapper); |
| | | String code = sysConfig.getCode(); |
| | | if (Constants.VERFICATIONCODE_OPEN.equals(code)) { |
| | | try { |
| | | response.sendRedirect("/verificationCode/get"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if (Constants.VERFICATIONCODE_OPEN.equals(sysConfig.getCode())) { |
| | | return new ResultMessage(ResponseCodeEnum.VERIFICATION_OPEN, null); |
| | | } |
| | | return new ResultMessage(ResponseCodeEnum.VERIFICATION_CLOSE, null); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取验证码", notes = "获取验证码") |