package com.uas.sso.controller; import com.uas.sso.entity.*; import com.uas.sso.exception.VisibleError; import com.uas.sso.service.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ui.ModelMap; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** * @author wangmh * @create 2018-01-16 8:50 * @desc 申述controller **/ @RestController @RequestMapping("/appeal") public class AppealController extends BaseController { private static final int IMAGE_MAX_SIZE = 5 * 1024 * 1024; @Autowired private UserService userService; @Autowired private UserspaceService userspaceService; @Autowired private AppealService appealService; /** * 获取手机号验证码 * * @author wangmh * @date 2018/1/16 10:37 * @param mobile 手机号 * @return 验证码tokenId */ @RequestMapping(value = "/check/mobile", method = RequestMethod.GET) public ModelMap checkMobile(String mobile) { if (StringUtils.isEmpty(mobile)) { return error("手机号不能为空"); } String token = getMobileToken(mobile); ModelMap data = new ModelMap("token", token); data.put("code", request.getSession().getAttribute("code")); return success(data); } /** * 校验验证码 * * @author wangmh * @date 2018/1/16 10:44 * @param mobile 手机号 * @param token 验证码tokenId * @param code 验证码 * @return */ @RequestMapping(value = "/check/mobile", method = RequestMethod.POST) public ModelMap checkMobile(String mobile, @RequestParam String token, String code) { Token existToken = tokenService.findOne(token); if (existToken == null || existToken.isExpired()) { return error("验证码已过期,请重新获取"); } // 校验验证码 checkMobileCode(token, mobile, code); // 返回信息 return success(); } /** * 找回密码申述 * @param appeal 申述信息 * @param token 验证码tokenId * @param code 验证码 * @return */ @RequestMapping(value = "/resetPwd", method = RequestMethod.POST) public ModelMap resetPwd(Appeal appeal, @RequestParam String token, String code, String password, @RequestParam(defaultValue = "sso") String appId) { checkAppeal(appeal); // 校验验证码 checkMobileCode(token, appeal.getMobile(), code); appealService.submitResetPwd(appId, appeal, password); return success(); } private void checkAppeal(Appeal appeal) { if (StringUtils.isEmpty(appeal.getMobile())) { throw new VisibleError("手机号不能为空"); } if (StringUtils.isEmpty(appeal.getDescription())) { throw new VisibleError("申述说明不能为空"); } if (StringUtils.isEmpty(appeal.getContactName())) { throw new VisibleError("姓名不能为空"); } if (StringUtils.isEmpty(appeal.getContactTel())) { throw new VisibleError("联系电话不能为空"); } if (StringUtils.isEmpty(appeal.getContactEmail())) { throw new VisibleError("电子邮箱不能为空"); } } @RequestMapping(value = "/changeAdmin", method = RequestMethod.POST) public ModelMap changeAdmin(Appeal appeal, @RequestParam String token, String code, Userspace userspace, @RequestParam(defaultValue = "sso") String appId) { checkAppeal(appeal); // 校验验证码 checkMobileCode(token, appeal.getMobile(), code); appealService.submitChangeAdmin(appId, appeal, userspace); // 发送短信和邮件通知审核人 Setting mailReceiver = settingService.findOne("mailReceiverAfterRegister"); Setting smsReceiver = settingService.findOne("smsReceiverAfterRegister"); sendEmail("noticeManageAuditVendorMan", mailReceiver.getValue(), new ModelMap("adminName", appeal.getContactName()).addAttribute("enName", userspace.getBusinessCode())); sendSms("SmsNoticeManageAuditVendorMan", smsReceiver.getValue(), new Object[]{appeal.getContactName()}); return success(); } /** * 认证账号申述 * @param appeal 申述信息 * @param token 验证码tokenId * @param code 验证码 * @param password 密码 * @param appId 应用Id * @return */ @RequestMapping(value = "/account", method = RequestMethod.POST) public ModelMap validAccount(Appeal appeal, String token, String code, String password, @RequestParam(defaultValue = "sso") String appId) { checkAppeal(appeal); // 校验token Token existToken = tokenService.findOne(token); if (existToken == null || existToken.isExpired()) { return error("验证码已过期,请重新获取"); } // TODO 参数空检验 // 校验验证码 checkMobileCode(token, appeal.getMobile(), code); // 保存申述信息 appeal.setFromApp(appId); appealService.submitValidAccount(appeal, password); return success(); } }