Browse Source

短信验证

zhoutg 6 years ago
parent
commit
3bfdb06572

+ 0 - 1
docs/002.数据库设计/sys-user.sql

@@ -15,7 +15,6 @@ CREATE TABLE `sys_user` (
   `modifier` varchar(20) NOT NULL DEFAULT '0' COMMENT '修改人,如果为0则表示纪录未修改',
   `username` varchar(255) NOT NULL DEFAULT '' COMMENT '用户名',
   `password` varchar(255) DEFAULT NULL COMMENT '用户密码',
-  `organization` varchar(255) DEFAULT NULL COMMENT '机构名称',
   `linkman` varchar(255) DEFAULT NULL COMMENT '联系人',
   `email` varchar(255) DEFAULT NULL COMMENT '邮箱',
   PRIMARY KEY (`id`),

+ 2 - 1
user-service/src/main/java/com/diagbot/config/ResourceServerConfigurer.java

@@ -28,7 +28,8 @@ public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
                 .regexMatchers(".*swagger.*",".*v2.*",".*webjars.*","/user/login.*","/user/registry.*","/user/test.*","/druid.*","/actuator.*","/hystrix.*","/hi.*","/test.*").permitAll()
                 .antMatchers("/userver/getImgVerification").permitAll()
                 .antMatchers("/userver/verifyImgVerification").permitAll()
-                .antMatchers("/userver/getSmsVerification").permitAll()
+                .antMatchers("/userver/getSmsWithRegister").permitAll()
+                .antMatchers("/userver/getSmsWithResetPassword").permitAll()
                 .antMatchers("/userver/verifySmsVerification").permitAll()
                 .antMatchers("/**").authenticated();
 //        .antMatchers("/**").permitAll();

+ 2 - 2
user-service/src/main/java/com/diagbot/config/security/UrlAccessDecisionManager.java

@@ -12,7 +12,6 @@ import org.springframework.stereotype.Service;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.Collection;
-import java.util.List;
 
 
 /**
@@ -42,7 +41,8 @@ public class UrlAccessDecisionManager implements AccessDecisionManager {
                 || matchers("/test/**", request)
                 || matchers("/userver/getImgVerification", request)
                 || matchers("/userver/verifyImgVerification", request)
-                || matchers("/userver/getSmsVerification", request)
+                || matchers("/userver/getSmsWithRegister", request)
+                || matchers("/userver/getSmsWithResetPassword", request)
                 || matchers("/userver/verifySmsVerification", request)
                 || matchers("/", request)){
                     return;

+ 0 - 14
user-service/src/main/java/com/diagbot/entity/User.java

@@ -62,11 +62,6 @@ public class User implements Serializable {
     private String username;
 
 
-    /**
-     * 组织机构
-     */
-    private String organization;
-
     /**
      * 联系人
      */
@@ -143,14 +138,6 @@ public class User implements Serializable {
         this.username = username;
     }
 
-    public String getOrganization() {
-        return organization;
-    }
-
-    public void setOrganization(String organization) {
-        this.organization = organization;
-    }
-
     public String getLinkman() {
         return linkman;
     }
@@ -178,7 +165,6 @@ public class User implements Serializable {
                 ", modifier='" + modifier + '\'' +
                 ", password='" + password + '\'' +
                 ", username='" + username + '\'' +
-                ", organization='" + organization + '\'' +
                 ", linkman='" + linkman + '\'' +
                 ", email='" + email + '\'' +
                 '}';

+ 1 - 0
user-service/src/main/java/com/diagbot/facade/UserFacade.java

@@ -54,6 +54,7 @@ public class UserFacade extends UserServiceImpl {
         String entryPassword= passwordEncoder.encode(user.getPassword());
         user.setPassword(entryPassword);
         this.save(user);
+        //TODO 添加机构信息
         return  user;
     }
 

+ 31 - 29
user-service/src/main/java/com/diagbot/facade/VerFacade.java

@@ -28,6 +28,8 @@ import org.springframework.stereotype.Component;
  */
 @Component
 public class VerFacade {
+
+    public final static int SMS_MINS = 3000; //短信验证码间隔为3分钟 //TODO 时间间隔先调大了,之后改为3
     @Autowired
     private ImgVerService imgVerService;
     @Autowired
@@ -69,10 +71,6 @@ public class VerFacade {
      */
     public Boolean getSmsVerification(SmsVerCreatVO smsVerCreatVO){
         //参数验证
-        if (null == smsVerCreatVO){
-            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
-                    "短信验证码创建信息不能为空!");
-        }
         if (StringUtil.isBlank(smsVerCreatVO.getImgId())){
             throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "图片验证码唯一标志不能为空!");
@@ -102,7 +100,7 @@ public class VerFacade {
             //验证是否超过三分钟
             SwsVerInfo swsVerInfoCheck = smsVerService.getSmsVerification(smsVerCreatVO.getMobile());
             if (null != swsVerInfoCheck){
-                if (DateUtil.after(DateUtil.addMinutes(swsVerInfoCheck.getCreateTime(), 3),
+                if (DateUtil.after(DateUtil.addMinutes(swsVerInfoCheck.getCreateTime(), VerFacade.SMS_MINS),
                         DateUtil.now())){
                     throw new CommonException(ServiceErrorCode.SMS_SEND_ERROR,
                             "同一用户三分钟之内不能重复发送验证短信,请三分钟之后再次发送!");
@@ -132,9 +130,13 @@ public class VerFacade {
      */
     public Boolean getSmsWithResetPassword(SmsVerCreatVO smsVerCreatVO){
         //参数验证
-        if (null == smsVerCreatVO){
+        if (StringUtil.isBlank(smsVerCreatVO.getImgId())){
             throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
-                    "短信验证码创建信息不能为空!");
+                    "图片验证码唯一标志不能为空!");
+        }
+        if (StringUtil.isBlank(smsVerCreatVO.getCode())){
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
+                    "图片验证码不能为空!");
         }
         if (StringUtil.isBlank(smsVerCreatVO.getMobile())){
             throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
@@ -152,7 +154,7 @@ public class VerFacade {
         //验证是否超过三分钟
         SwsVerInfo swsVerInfoCheck = smsVerService.getSmsVerification(smsVerCreatVO.getMobile());
         if (null != swsVerInfoCheck){
-            if (DateUtil.after(DateUtil.addMinutes(swsVerInfoCheck.getCreateTime(), 3),
+            if (DateUtil.after(DateUtil.addMinutes(swsVerInfoCheck.getCreateTime(), 3000), //TODO 方便测试先加大时间间隔
                     DateUtil.now())){
                 throw new CommonException(ServiceErrorCode.SMS_SEND_ERROR,
                         "同一用户三分钟之内不能重复发送验证短信,请三分钟之后再次发送!");
@@ -170,10 +172,11 @@ public class VerFacade {
         return smsVerService.createSmsVerification(swsVerInfo);
     }
 
+
     /**
      * 验证短信码
      * @param smsVerVerVO 短信验证码验证输入信息
-     * @return 用户信息是否注册到数据库
+     * @return 校验短信验证码是否通过
      */
     public Boolean verifySmsVerification(SmsVerVerVO smsVerVerVO){
         //参数验证
@@ -181,14 +184,14 @@ public class VerFacade {
             throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "短信验证码验证输入信息不能为空!");
         }
-        if (StringUtil.isBlank(smsVerVerVO.getImgId())){
-            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
-                    "图片验证码唯一标志不能为空!");
-        }
-        if (StringUtil.isBlank(smsVerVerVO.getCode())){
-            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
-                    "图片验证码不能为空!");
-        }
+//        if (StringUtil.isBlank(smsVerVerVO.getImgId())){
+//            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
+//                    "图片验证码唯一标志不能为空!");
+//        }
+//        if (StringUtil.isBlank(smsVerVerVO.getCode())){
+//            throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
+//                    "图片验证码不能为空!");
+//        }
         if (StringUtil.isBlank(smsVerVerVO.getMobile())){
             throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "用户电话不能为空!");
@@ -202,17 +205,17 @@ public class VerFacade {
                     "请输入正确的手机号!");
         }
         //验证图片验证码
-        ImgVerInfo imgVerInfo = new ImgVerInfo();
-        BeanUtil.copyProperties(smsVerVerVO, imgVerInfo);
-        Boolean imgVerRes = imgVerService.verifyImgVerification(imgVerInfo);
-        if (imgVerRes){
-            User bean = userFacade.getUserInfo(smsVerVerVO.getMobile());
-            if (bean != null){
-                throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "该号码已经被注册!");
-            }
-        } else {
-            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "输入图形验证码有误!");
-        }
+//        ImgVerInfo imgVerInfo = new ImgVerInfo();
+//        BeanUtil.copyProperties(smsVerVerVO, imgVerInfo);
+//        Boolean imgVerRes = imgVerService.verifyImgVerification(imgVerInfo);
+//        if (imgVerRes){
+//            User bean = userFacade.getUserInfo(smsVerVerVO.getMobile());
+//            if (bean != null){
+//                throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "该号码已经被注册!");
+//            }
+//        } else {
+//            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "输入图形验证码有误!");
+//        }
         //验证用户短信信息
         SwsVerInfo swsVerInfo = new SwsVerInfo();
         swsVerInfo.setMobile(smsVerVerVO.getMobile());
@@ -224,5 +227,4 @@ public class VerFacade {
         return true;
     }
 
-
 }

+ 2 - 2
user-service/src/main/java/com/diagbot/service/impl/ImgVerServiceImpl.java

@@ -121,9 +121,9 @@ public class ImgVerServiceImpl implements ImgVerService {
             }
         });
         if (imgVerInfoRes == null) {
-            log.info("用户图片验证信息不存在!");
+            log.info("用户图片验证信息不存在【imgId=" + imgVerInfo.getImgId() + "】!");
             throw new CommonException(CommonErrorCode.NOT_EXISTS,
-                    "用户图片验证信息不存在!");
+                    "用户图片验证信息不存在【imgId=" + imgVerInfo.getImgId() + "】!");
         }
         //判断是否是想要的对象
         if (!imgVerInfoRes.getImgId().equals(imgVerInfo.getImgId())) {

+ 2 - 2
user-service/src/main/java/com/diagbot/service/impl/SmsVerServiceImpl.java

@@ -179,9 +179,9 @@ public class SmsVerServiceImpl implements SmsVerService {
                     "用户电话不一致!");
         }
         if (!swsVerInfoRes.getCode().equals(swsVerInfo.getCode())) {
-            log.info("用户短信验证码不一致!用户电话:{},验证码:{}", swsVerInfo.getMobile(),swsVerInfo.getCode());
+            log.info("短信验证码输入有误!用户电话:{},验证码:{}", swsVerInfo.getMobile(),swsVerInfo.getCode());
             throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
-                    "用户短息验证码不一致!");
+                    "短信验证码输入有误!");
         }
         //判断是否过期
         if (!DateUtil.after(swsVerInfoRes.getExpireTime(), DateUtil.now())) {

+ 1 - 1
user-service/src/main/java/com/diagbot/vo/SmsVerCreatVO.java

@@ -17,7 +17,7 @@ import javax.validation.constraints.Size;
 public class SmsVerCreatVO extends ImgVerVerVO{
     //用户电话
     @NotBlank(message = "{mobile.not.null}")
-    @Pattern(regexp="^[0-9]\\\\d*$", message="手机号码必须是数字")
+    @Pattern(regexp="^[0-9]\\d*$", message="手机号码必须是数字")
     @Size(max=11, message = "手机号码最多11位")
     private String mobile;
 }

+ 3 - 3
user-service/src/main/java/com/diagbot/web/VerController.java

@@ -8,7 +8,6 @@ import com.diagbot.vo.SmsVerCreatVO;
 import com.diagbot.vo.SmsVerVerVO;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -32,7 +31,7 @@ public class VerController {
      * @return 图片验证码包括图片验证码唯一标志和图片信息
      */
     @ApiOperation(value = "获取图片验证码", notes = "获取图片验证码包括图片验证码唯一标志和图片信息")
-    @GetMapping("/getImgVerification")
+    @PostMapping("/getImgVerification")
     @SysLogger("getImgVerification")
     public RespDTO getImgVerification(){
         return   RespDTO.onSuc(verFacade.getImgVerification());
@@ -67,7 +66,7 @@ public class VerController {
      * @param smsVerVerVO 短信验证码验证输入信息
      * @return 用户信息是否注册到数据库
      */
-    @ApiOperation(value = "验证短信验证码", notes = "图片验证码唯一标志后,图形验证码,用户号码,用户验证码不能为空")
+    @ApiOperation(value = "验证短信验证码", notes = "用户号码,用户验证码不能为空")
     @PostMapping("/verifySmsVerification")
     @SysLogger("verifySmsVerification")
     public RespDTO verifySmsVerification(@RequestBody SmsVerVerVO smsVerVerVO){
@@ -86,4 +85,5 @@ public class VerController {
     public RespDTO getSmsWithResetPassword(@RequestBody @Valid SmsVerCreatVO smsVerCreatVO){
         return   RespDTO.onSuc(verFacade.getSmsWithResetPassword(smsVerCreatVO));
     }
+
 }

+ 0 - 1
user-service/src/main/resources/mapper/UserMapper.xml

@@ -13,7 +13,6 @@
         <result column="password" property="password" />
         <result column="username" property="username" />
         <result column="linkman" property="linkman" />
-        <result column="organization" property="organization" />
         <result column="email" property="email" />
     </resultMap>