AppealController.java 5.5 KB

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