AppealController.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.service.*;
  7. import com.uas.sso.support.SystemSession;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.ui.ModelMap;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestMethod;
  12. import org.springframework.web.bind.annotation.RequestParam;
  13. import org.springframework.web.bind.annotation.RestController;
  14. /**
  15. * @author wangmh
  16. * @create 2018-01-16 8:50
  17. * @desc 申述controller
  18. **/
  19. @RestController
  20. @RequestMapping("/appeal")
  21. public class AppealController extends BaseController {
  22. private static final int IMAGE_MAX_SIZE = 5 * 1024 * 1024;
  23. @Autowired
  24. private UserService userService;
  25. @Autowired
  26. private UserspaceService userspaceService;
  27. @Autowired
  28. private AppealService appealService;
  29. /**
  30. * 获取手机号验证码
  31. *
  32. * @author wangmh
  33. * @date 2018/1/16 10:37
  34. * @param mobile 手机号
  35. * @return 验证码tokenId
  36. */
  37. @RequestMapping(value = "/check/mobile", method = RequestMethod.GET)
  38. public ModelMap checkMobile(String mobile) {
  39. String token = getMobileToken(mobile);
  40. ModelMap data = new ModelMap("token", token);
  41. data.put("code", request.getSession().getAttribute("code"));
  42. return success(data);
  43. }
  44. /**
  45. * 校验验证码
  46. *
  47. * @author wangmh
  48. * @date 2018/1/16 10:44
  49. * @param mobile 手机号
  50. * @param token 验证码tokenId
  51. * @param code 验证码
  52. * @return
  53. */
  54. @RequestMapping(value = "/check/mobile", method = RequestMethod.POST)
  55. public ModelMap checkMobile(String mobile, @RequestParam String token, String code) {
  56. Token existToken = tokenService.findOne(token);
  57. if (existToken == null || existToken.isExpired()) {
  58. return error("验证码已过期,请重新获取");
  59. }
  60. // 校验验证码
  61. checkMobileCode(token, mobile, code);
  62. // 返回信息
  63. return success();
  64. }
  65. /**
  66. * 找回密码申述
  67. * @param appeal 申述信息
  68. * @param token 验证码tokenId
  69. * @param code 验证码
  70. * @return
  71. */
  72. @RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
  73. public ModelMap resetPwd(Appeal appeal, @RequestParam String token, String code, String password, @RequestParam(defaultValue = "sso") String appId) {
  74. // 获取申述人,将修改的账号作为申述人
  75. User user = userService.findByMobile(appeal.getMobile());
  76. if (user == null) {
  77. return error("该手机号未注册");
  78. }
  79. Long submitterUU = user.getUserUU();
  80. // 校验token
  81. Token existToken = tokenService.findOne(token);
  82. if (existToken == null || existToken.isExpired()) {
  83. return error("验证码已过期,请重新获取");
  84. }
  85. // TODO 参数空检验
  86. // 校验验证码
  87. checkMobileCode(token, appeal.getMobile(), code);
  88. // 保存申述信息
  89. appeal.setSubmitterUU(submitterUU);
  90. appeal.setFromApp(appId);
  91. appealService.submitResetPwd(appeal, password);
  92. return success();
  93. }
  94. @RequestMapping(value = "/changeAdmin", method = RequestMethod.POST)
  95. public ModelMap changeAdmin(Appeal appeal, @RequestParam String token, String code, Userspace userspace, @RequestParam(defaultValue = "sso") String appId) {
  96. // 校验token
  97. Token existToken = tokenService.findOne(token);
  98. if (existToken == null || existToken.isExpired()) {
  99. return error("验证码已过期,请重新获取");
  100. }
  101. // 校验企业信息
  102. Userspace checkSpace = userspaceService.findBySpaceName(userspace.getSpaceName());
  103. if (checkSpace == null) {
  104. return error("该企业未被注册,请确认");
  105. }
  106. // TODO 参数空检验
  107. // 校验验证码
  108. checkMobileCode(token, appeal.getMobile(), code);
  109. // 保存申述信息,把新管理员当作申请人
  110. User submitter = userService.findByMobile(appeal.getMobile());
  111. appeal.setSubmitterUU(submitter == null ? null : submitter.getUserUU());
  112. appeal.setFromApp(appId);
  113. appealService.submitChangeAdmin(appeal, userspace, checkSpace.getSpaceUU());
  114. // 发送短信和邮件通知审核人
  115. Setting mailReceiver = settingService.findOne("mailReceiverAfterRegister");
  116. Setting smsReceiver = settingService.findOne("smsReceiverAfterRegister");
  117. sendEmail("noticeManageAuditVendorMan", mailReceiver.getValue(), new ModelMap("adminName", appeal.getContactName()).addAttribute("enName", userspace.getBusinessCode()));
  118. sendSms("SmsNoticeManageAuditVendorMan", smsReceiver.getValue(), new Object[]{appeal.getContactName()});
  119. return success();
  120. }
  121. @RequestMapping(value = "/account", method = RequestMethod.POST)
  122. public ModelMap validAccount(Appeal appeal, String token, String code, String password, @RequestParam(defaultValue = "sso") String appId) {
  123. // 校验用户是否登录
  124. SSOToken ssoToken = SSOHelper.getToken(request);
  125. if (ssoToken == null) {
  126. return error("用户未登录");
  127. }
  128. UserAccount userAccount = JSON.parseObject(ssoToken.getData(), UserAccount.class);
  129. if (userAccount == null) {
  130. return error("用户未登录");
  131. }
  132. // 校验token
  133. Token existToken = tokenService.findOne(token);
  134. if (existToken == null || existToken.isExpired()) {
  135. return error("验证码已过期,请重新获取");
  136. }
  137. // TODO 参数空检验
  138. // 校验验证码
  139. checkMobileCode(token, appeal.getMobile(), code);
  140. // 保存申述信息
  141. appeal.setFromApp(appId);
  142. appealService.submitValidAccount(appeal, password);
  143. return success();
  144. }
  145. }