浏览代码

绿色通道认证Agency添加邮箱字段,开启邮箱与手机号正则验证

xuexiaobo 6 年之前
父节点
当前提交
096858f89c

+ 1 - 1
site/src/main/java/com/mooctest/crowd/site/anticorruption/UserAntiCorruption.java

@@ -8,7 +8,7 @@ import com.mooctest.crowd.domain.domainobject.User;
  * @date 2019-08-08 23:40
  */
 public interface UserAntiCorruption {
-    User register(String name, String mobile, String password);
+    User register(String name,String email, String mobile, String password);
 
     User getUserInfo(Long userId);
 }

+ 2 - 2
site/src/main/java/com/mooctest/crowd/site/anticorruption/impl/UserAntiCorruptionImpl.java

@@ -42,13 +42,13 @@ public class UserAntiCorruptionImpl implements UserAntiCorruption {
     private String userServiceUrl;
 
     @Override
-    public User register(String name, String mobile, String password) {
+    public User register(String name, String email, String mobile, String password) {
         HttpHeaders httpHeaders = new HttpHeaders();
         httpHeaders.setContentType(MediaType.APPLICATION_JSON);
         JSONObject params = new JSONObject();
         params.put("name", name);
         params.put("mobile", mobile);
-        params.put("email", name+"."+mobile+"@mooctest.net");
+        params.put("email", email);
         params.put("password", EncryptionUtil.encryptMD5(password));
         params.put("createTime", System.currentTimeMillis());
 

+ 7 - 0
site/src/main/java/com/mooctest/crowd/site/command/ApplyAgencyAuthCommand.java

@@ -6,6 +6,7 @@ import lombok.Data;
 import org.springframework.beans.BeanUtils;
 
 import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
 
 /**
  * @author: Diors.Po
@@ -15,8 +16,14 @@ import javax.validation.constraints.NotNull;
 @Data
 public class ApplyAgencyAuthCommand {
 
+    @NotNull(message = "邮箱不可为空")
+    @Pattern(regexp = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$", message = "邮箱非法")
+    private String email;
+
     @NotNull(message = "手机号不可为空")
+    @Pattern(regexp = "^1[3|4|5|7|8][0-9]\\d{4,8}$", message = "手机号非法")
     private String mobile;
+
     @NotNull(message = "机构名称不可为空")
     private String evaluationAgencyName;
     @NotNull(message = "银行卡号不可为空")

+ 8 - 1
site/src/main/java/com/mooctest/crowd/site/controller/AgencyController.java

@@ -5,7 +5,12 @@ import com.mooctest.crowd.site.command.ApplyAgencyAuthCommand;
 import com.mooctest.crowd.site.data.dto.UserDTO;
 import com.mooctest.crowd.site.service.AgencyService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+
 /**
  * @author: Diors.Po
  * @Email: 171256175@qq.com
@@ -24,7 +29,9 @@ public class AgencyController {
      * @return
      */
     @RequestMapping(value = "/greenChannel/agency", method = RequestMethod.POST)
-    public UserDTO generateAgency(@RequestBody ApplyAgencyAuthCommand command){
+    public UserDTO generateAgency(@RequestBody @Validated ApplyAgencyAuthCommand command, BindingResult result){
+        if (result.hasErrors())
+            throw new BaseException(result.getFieldError().getDefaultMessage());
         return agencyService.generateAgency(command);
     }
 

+ 9 - 9
site/src/main/java/com/mooctest/crowd/site/controller/advice/ExceptionAdvice.java

@@ -19,22 +19,22 @@ public class ExceptionAdvice {
 
     @ExceptionHandler(BaseException.class)
     @ResponseStatus(HttpStatus.BAD_REQUEST)
-    public ResponseMessage handleException(Exception e){
-        log.error("出错!", e);
+    public String handleException(Exception e){
+        log.error("访问出错:"+e.getMessage(), e);
         if (e instanceof AccountNotExistException){
-            return new ResponseMessage(ResponseConstant.FAIL, ResponseConstant.USER_NOT_EXISTS);
+            return ResponseConstant.USER_NOT_EXISTS;
         } else if (e instanceof CrowdTestProjectNotExistException){
-            return new ResponseMessage(ResponseConstant.FAIL, "项目不存在");
+            return "项目不存在";
         } else if (e instanceof CrowdTestTaskNotExistException){
-            return new ResponseMessage(ResponseConstant.FAIL, "任务不存在");
+            return "任务不存在";
         } else if (e instanceof CrowdTestReportNotExistException){
-            return new ResponseMessage(ResponseConstant.FAIL, "报告不存在");
+            return "报告不存在";
         } else if (e instanceof CrowdTestTaskNoPriceException){
-            return new ResponseMessage(ResponseConstant.FAIL, "项目未设置价格");
+            return "项目未设置价格";
         } else if (e instanceof PasswordErrorException){
-            return new ResponseMessage(ResponseConstant.UNAUTH, "密码错误");
+            return "密码错误";
         } else
-            return new ResponseMessage(ResponseConstant.FAIL, e.getMessage());
+            return e.getMessage();
     }
 
     @ExceptionHandler(UnauthorizedException.class)

+ 2 - 1
site/src/main/java/com/mooctest/crowd/site/data/vo/UserVO.java

@@ -19,7 +19,8 @@ public class UserVO {
     private String name;
     private String userName;
     private String gender;
-    private String mobileNum;
+    private String email;
+    private String mobile;
     private String password;
     private String province;
     private String city;

+ 3 - 2
site/src/main/java/com/mooctest/crowd/site/service/impl/AgencyServiceImpl.java

@@ -57,8 +57,8 @@ public class AgencyServiceImpl implements AgencyService {
             log.info("电话号码不存在,可以生成新用户");
         }
         if (mobileExists)
-            throw new BaseException("手机号码已经存在,无法生成新用户");
-        User user = userAnti.register(command.getEvaluationAgencyName(), command.getMobile(), command.getMobile());
+            throw new BaseException("手机号码已经存在,请直接登录");
+        User user = userAnti.register(command.getEvaluationAgencyName(),command.getEmail(), command.getMobile(), command.getMobile());
         EvaluationAgency agency = command.toAgency();
         List<Role> roles = new ArrayList<>();
         roles.add(userRepo.getRole("evaluationAgency"));
@@ -72,6 +72,7 @@ public class AgencyServiceImpl implements AgencyService {
         userDTO.setUserVO(new UserVO(userRepo.getByID(user.getId())));
         userDTO.setAgencyVO(new AgencyVO(userRepo.getByID(user.getId()).getEvaluationAgency()));
         userDTO.getUserVO().setPassword(command.getMobile());
+        userDTO.getUserVO().setEmail(command.getEmail());
         return userDTO;
     }