| | |
| | | import java.util.Map; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.SysConfig; |
| | | import com.moral.api.entity.UserLog; |
| | | 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; |
| | | import com.moral.constant.ResultMessage; |
| | | import com.moral.pojo.VerificationCode; |
| | |
| | | @Autowired |
| | | private SysConfigService sysConfigService; |
| | | |
| | | @Autowired |
| | | private UserLogService userLogService; |
| | | |
| | | @ApiOperation(value = "登陆", notes = "登陆") |
| | | @ApiImplicitParams({ |
| | | @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) { |
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); |
| | | public ResultMessage login(@RequestBody Map<String, Object> parameters, HttpServletRequest request) { |
| | | if (!(parameters.containsKey("account") && parameters.containsKey("password"))) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | Map<String, Object> result = userService.login(parameters); |
| | | if (!result.containsKey("data")) { |
| | | return ResultMessage.fail((int) result.get("code"), (String) result.get("msg")); |
| | | } |
| | | return ResultMessage.ok(result.get("data")); |
| | | Map<String, Object> data = (Map<String, Object>) result.get("data"); |
| | | Map<String, Object> userInfo = (Map<String, Object>) data.get("user"); |
| | | UserLog userLog = new UserLog(); |
| | | String ip = WebUtils.getIpAddr(request); |
| | | userLog.setIp(ip); |
| | | userLog.setOperateId((Integer) userInfo.get("userId")); |
| | | Map<String, Object> organization = (Map<String, Object>) userInfo.get("organization"); |
| | | userLog.setOrganizationId((Integer) organization.get("id")); |
| | | userLog.setContent(userInfo.get("account") + "登陆了"); |
| | | userLogService.save(userLog); |
| | | return ResultMessage.ok(data); |
| | | } |
| | | |
| | | @ApiOperation(value = "注销", notes = "注销") |
| | | @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); |
| | | public ResultMessage logout(@RequestBody Map<String, Object> parameters, HttpServletRequest request) { |
| | | if (!parameters.containsKey("uid")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | String userId = parameters.get("uid").toString(); |
| | | String token = request.getHeader("token"); |
| | | TokenUtils.destoryToken(userId, token); |
| | | TokenUtils.destoryToken(parameters.get("uid").toString(), token); |
| | | return ResultMessage.ok(); |
| | | } |
| | | |
| | |
| | | */ |
| | | |
| | | @ApiOperation(value = "获取验证码是否开启", notes = "获取验证码是否开启") |
| | | @RequestMapping(value = "verificationCodeConfig", method = RequestMethod.GET) |
| | | public ResultMessage verifyConfig() { |
| | | return null; |
| | | @RequestMapping(value = "verificationCode/config", method = RequestMethod.GET) |
| | | public void verifyConfig(HttpServletResponse response) { |
| | | QueryWrapper<SysConfig> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("type", Constants.VERIFICATION_TYPE); |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "获取验证码", notes = "获取验证码") |