AppealController.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package com.uas.sso.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.uas.sso.SSOHelper;
  4. import com.uas.sso.SSOToken;
  5. import com.uas.sso.entity.*;
  6. import com.uas.sso.exception.AccountException;
  7. import com.uas.sso.exception.VisibleError;
  8. import com.uas.sso.service.*;
  9. import com.uas.sso.support.SystemSession;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.ui.ModelMap;
  12. import org.springframework.util.Assert;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import org.springframework.web.bind.annotation.RequestParam;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import java.util.Optional;
  18. /**
  19. * @author wangmh
  20. * @create 2018-01-16 8:50
  21. * @desc 申述controller
  22. **/
  23. @RestController
  24. @RequestMapping("/appeal")
  25. public class AppealController extends BaseController {
  26. private static final int IMAGE_MAX_SIZE = 5 * 1024 * 1024;
  27. @Autowired
  28. private UserService userService;
  29. @Autowired
  30. private UserspaceService userspaceService;
  31. @Autowired
  32. private AppealService appealService;
  33. /**
  34. * 获取手机号验证码
  35. *
  36. * @author wangmh
  37. * @date 2018/1/16 10:37
  38. * @param mobile 手机号
  39. * @return 验证码tokenId
  40. */
  41. @RequestMapping(value = "/check/mobile", method = RequestMethod.GET)
  42. public ModelMap checkMobile(String mobile) {
  43. String token = getMobileToken(mobile);
  44. ModelMap data = new ModelMap("token", token);
  45. data.put("code", request.getSession().getAttribute("code"));
  46. return success(data);
  47. }
  48. /**
  49. * 校验验证码
  50. *
  51. * @author wangmh
  52. * @date 2018/1/16 10:44
  53. * @param mobile 手机号
  54. * @param token 验证码tokenId
  55. * @param code 验证码
  56. * @return
  57. */
  58. @RequestMapping(value = "/check/mobile", method = RequestMethod.POST)
  59. public ModelMap checkMobile(String mobile, @RequestParam String token, String code) {
  60. Token existToken = tokenService.findOne(token);
  61. if (existToken == null || existToken.isExpired()) {
  62. return error("验证码已过期,请重新获取");
  63. }
  64. // 校验验证码
  65. checkMobileCode(token, mobile, code);
  66. // 返回信息
  67. return success();
  68. }
  69. /**
  70. * 找回密码申述
  71. * @param appeal 申述信息
  72. * @param token 验证码tokenId
  73. * @param code 验证码
  74. * @return
  75. */
  76. @RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
  77. public ModelMap resetPwd(Appeal appeal, @RequestParam String token, String code, String password, @RequestParam(defaultValue = "sso") String appId) {
  78. // 校验验证码
  79. checkMobileCode(token, appeal.getMobile(), code);
  80. appealService.submitResetPwd(appId, appeal, password);
  81. return success();
  82. }
  83. @RequestMapping(value = "/changeAdmin", method = RequestMethod.POST)
  84. public ModelMap changeAdmin(Appeal appeal, @RequestParam String token, String code, Userspace userspace, @RequestParam(defaultValue = "sso") String appId) {
  85. // 校验验证码
  86. checkMobileCode(token, appeal.getMobile(), code);
  87. appealService.submitChangeAdmin(appId, appeal, userspace);
  88. // 发送短信和邮件通知审核人
  89. Setting mailReceiver = settingService.findOne("mailReceiverAfterRegister");
  90. Setting smsReceiver = settingService.findOne("smsReceiverAfterRegister");
  91. sendEmail("noticeManageAuditVendorMan", mailReceiver.getValue(), new ModelMap("adminName", appeal.getContactName()).addAttribute("enName", userspace.getBusinessCode()));
  92. sendSms("SmsNoticeManageAuditVendorMan", smsReceiver.getValue(), new Object[]{appeal.getContactName()});
  93. return success();
  94. }
  95. /**
  96. * 认证账号申述
  97. * @param appeal 申述信息
  98. * @param token 验证码tokenId
  99. * @param code 验证码
  100. * @param password 密码
  101. * @param appId 应用Id
  102. * @return
  103. */
  104. @RequestMapping(value = "/account", method = RequestMethod.POST)
  105. public ModelMap validAccount(Appeal appeal, String token, String code, String password, @RequestParam(defaultValue = "sso") String appId) {
  106. // 校验token
  107. Token existToken = tokenService.findOne(token);
  108. if (existToken == null || existToken.isExpired()) {
  109. return error("验证码已过期,请重新获取");
  110. }
  111. // TODO 参数空检验
  112. // 校验验证码
  113. checkMobileCode(token, appeal.getMobile(), code);
  114. // 保存申述信息
  115. appeal.setFromApp(appId);
  116. appealService.submitValidAccount(appeal, password);
  117. return success();
  118. }
  119. }