AppealController.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. String token = getMobileToken(mobile);
  41. ModelMap data = new ModelMap("token", token);
  42. data.put("code", request.getSession().getAttribute("code"));
  43. return success(data);
  44. }
  45. /**
  46. * 校验验证码
  47. *
  48. * @author wangmh
  49. * @date 2018/1/16 10:44
  50. * @param mobile 手机号
  51. * @param token 验证码tokenId
  52. * @param code 验证码
  53. * @return
  54. */
  55. @RequestMapping(value = "/check/mobile", method = RequestMethod.POST)
  56. public ModelMap checkMobile(String mobile, @RequestParam String token, String code) {
  57. Token existToken = tokenService.findOne(token);
  58. if (existToken == null || existToken.isExpired()) {
  59. return error("验证码已过期,请重新获取");
  60. }
  61. // 校验验证码
  62. checkMobileCode(token, mobile, code);
  63. // 返回信息
  64. return success();
  65. }
  66. /**
  67. * 找回密码申述
  68. * @param appeal 申述信息
  69. * @param token 验证码tokenId
  70. * @param code 验证码
  71. * @return
  72. */
  73. @RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
  74. public ModelMap resetPwd(Appeal appeal, @RequestParam String token, String code, String password, @RequestParam(defaultValue = "sso") String appId) {
  75. checkAppeal(appeal);
  76. // 校验验证码
  77. checkMobileCode(token, appeal.getMobile(), code);
  78. appealService.submitResetPwd(appId, appeal, password);
  79. return success();
  80. }
  81. private void checkAppeal(Appeal appeal) {
  82. if (StringUtils.isEmpty(appeal.getMobile())) {
  83. throw new VisibleError("手机号不能为空");
  84. }
  85. if (StringUtils.isEmpty(appeal.getDescription())) {
  86. throw new VisibleError("申述说明不能为空");
  87. }
  88. if (StringUtils.isEmpty(appeal.getContactName())) {
  89. throw new VisibleError("姓名不能为空");
  90. }
  91. if (StringUtils.isEmpty(appeal.getContactTel())) {
  92. throw new VisibleError("联系电话不能为空");
  93. }
  94. if (StringUtils.isEmpty(appeal.getContactEmail())) {
  95. throw new VisibleError("电子邮箱不能为空");
  96. }
  97. }
  98. @RequestMapping(value = "/changeAdmin", method = RequestMethod.POST)
  99. public ModelMap changeAdmin(Appeal appeal, @RequestParam String token, String code, Userspace userspace, @RequestParam(defaultValue = "sso") String appId) {
  100. checkAppeal(appeal);
  101. // 校验验证码
  102. checkMobileCode(token, appeal.getMobile(), code);
  103. appealService.submitChangeAdmin(appId, appeal, userspace);
  104. // 发送短信和邮件通知审核人
  105. Setting mailReceiver = settingService.findOne("mailReceiverAfterRegister");
  106. Setting smsReceiver = settingService.findOne("smsReceiverAfterRegister");
  107. sendEmail("noticeManageAuditVendorMan", mailReceiver.getValue(), new ModelMap("adminName", appeal.getContactName()).addAttribute("enName", userspace.getBusinessCode()));
  108. sendSms("SmsNoticeManageAuditVendorMan", smsReceiver.getValue(), new Object[]{appeal.getContactName()});
  109. return success();
  110. }
  111. /**
  112. * 认证账号申述
  113. * @param appeal 申述信息
  114. * @param token 验证码tokenId
  115. * @param code 验证码
  116. * @param password 密码
  117. * @param appId 应用Id
  118. * @return
  119. */
  120. @RequestMapping(value = "/account", method = RequestMethod.POST)
  121. public ModelMap validAccount(Appeal appeal, String token, String code, String password, @RequestParam(defaultValue = "sso") String appId) {
  122. checkAppeal(appeal);
  123. // 校验token
  124. Token existToken = tokenService.findOne(token);
  125. if (existToken == null || existToken.isExpired()) {
  126. return error("验证码已过期,请重新获取");
  127. }
  128. // TODO 参数空检验
  129. // 校验验证码
  130. checkMobileCode(token, appeal.getMobile(), code);
  131. // 保存申述信息
  132. appeal.setFromApp(appId);
  133. appealService.submitValidAccount(appeal, password);
  134. return success();
  135. }
  136. }