Browse Source

申述空参数校验

wangmh 7 years ago
parent
commit
83e7f5a98c

+ 25 - 9
sso-server/src/main/java/com/uas/sso/controller/AppealController.java

@@ -1,24 +1,16 @@
 package com.uas.sso.controller;
 
-import com.alibaba.fastjson.JSON;
-import com.uas.sso.SSOHelper;
-import com.uas.sso.SSOToken;
 import com.uas.sso.entity.*;
-import com.uas.sso.exception.AccountException;
 import com.uas.sso.exception.VisibleError;
 import com.uas.sso.service.*;
-import com.uas.sso.support.SystemSession;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.ui.ModelMap;
-import org.springframework.util.Assert;
+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;
 
-import java.util.Optional;
-
-
 /**
  * @author wangmh
  * @create 2018-01-16 8:50
@@ -48,6 +40,9 @@ public class AppealController extends BaseController {
      */
     @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"));
@@ -87,14 +82,34 @@ public class AppealController extends BaseController {
      */
     @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);
 
@@ -119,6 +134,7 @@ public class AppealController extends BaseController {
      */
     @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()) {