NoLoginController.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package com.fdkankan.fusion.controller;
  2. import cn.hutool.captcha.CaptchaUtil;
  3. import cn.hutool.captcha.LineCaptcha;
  4. import com.fdkankan.fusion.common.ResultData;
  5. import com.fdkankan.fusion.common.util.RedisKeyUtil;
  6. import com.fdkankan.fusion.common.util.StringUtils;
  7. import com.fdkankan.fusion.response.UserAddRequest;
  8. import com.fdkankan.fusion.service.ITmUserService;
  9. import com.fdkankan.redis.util.RedisUtil;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.*;
  13. import javax.servlet.http.HttpServletResponse;
  14. @RestController
  15. @RequestMapping("/notAuth")
  16. @Slf4j
  17. public class NoLoginController {
  18. @Autowired
  19. RedisUtil redisUtil;
  20. @Autowired
  21. ITmUserService tmUserService;
  22. @GetMapping("/getLoginAuthCode")
  23. public void getLoginCode(HttpServletResponse response){
  24. response.setHeader("Cache-Control", "no-store, no-cache");
  25. response.setContentType("image/jpeg");
  26. try {
  27. LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100,4,60);
  28. while (redisUtil.hasKey(String.format(RedisKeyUtil.loginAuthCode,lineCaptcha.getCode()))){
  29. lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100,4,60);
  30. }
  31. redisUtil.set(String.format(RedisKeyUtil.loginAuthCode,lineCaptcha.getCode()),lineCaptcha.getCode(),30);
  32. lineCaptcha.write(response.getOutputStream());
  33. response.getOutputStream().close();
  34. } catch (Exception e){
  35. log.info("生成登录验证码错误:",e);
  36. }
  37. }
  38. @PostMapping("/changePassword")
  39. public ResultData changePassword(@RequestBody UserAddRequest param){
  40. tmUserService.changePassword(param);
  41. return ResultData.ok();
  42. }
  43. @GetMapping("/getMsgAuthCode")
  44. public ResultData getMsgAuthCode(@RequestParam(name = "phoneNum") String phoneNum) {
  45. return ResultData.ok( tmUserService.getMsgAuthCode(phoneNum));
  46. }
  47. }