MCPcopy Create free account
hub / github.com/diyhi/bbs / validate

Method validate

src/main/java/cms/validator/user/UserValidator.java:31–196  ·  view source on GitHub ↗
(Object obj, Errors errors)

Source from the content-addressed store, hash-verified

29 }
30
31 public void validate(Object obj, Errors errors) {//对目标类对象进行校验,错误记录在errors中
32 User user = (User) obj;
33
34 if(user.getType() != null){
35 if(user.getType().equals(10)){//10:本地账号密码用户
36 if(user.getAccount() != null && !user.getAccount().trim().isEmpty()){
37 if(!Verification.isNumericLettersUnderscore(user.getAccount().trim())){
38 errors.rejectValue("account","errors.common", new String[]{"账号只能输入由数字、26个英文字母或者下划线组成"},"");
39 }
40 if(user.getAccount().length()>30){
41 errors.rejectValue("account","errors.common", new String[]{"账号不能超过30个字符"},"");
42 }
43 User u1 = userRepository.findUserByAccount(user.getAccount().trim());
44 if(u1 != null){
45 errors.rejectValue("account","errors.common", new String[]{"该账号已注册"},"");
46 }
47
48 User u2 = userRepository.findUserByNickname(user.getAccount().trim());
49 if(u2 != null){
50 errors.rejectValue("account","", new String[]{"该账号不能和其他用户呢称相同"},"");
51 }
52 }else{
53 errors.rejectValue("account","errors.common", new String[]{"请填写账号"},"");
54 }
55 if(user.getIssue() == null || user.getIssue().trim().isEmpty()){
56 errors.rejectValue("issue","errors.common", new String[]{"密码提示问题不能为空"},"");
57 }else{
58 if(user.getIssue().length()>50){
59 errors.rejectValue("issue","errors.common", new String[]{"密码提示问题不能超过50个字符"},"");
60 }
61
62 }
63 if(user.getAnswer() == null || user.getAnswer().trim().isEmpty()){
64 errors.rejectValue("answer","errors.common", new String[]{"密码提示答案不能为空"},"");
65 }else{
66 if(user.getAnswer().length()>50){
67 errors.rejectValue("answer","errors.common", new String[]{"密码提示答案不能超过50个字符"},"");
68 }
69 }
70 //手机
71 if(user.getMobile() != null && !user.getMobile().trim().isEmpty()){
72 if(user.getMobile().trim().length() >18){
73 errors.rejectValue("mobile","errors.common", new String[]{"手机号码超长"},"");
74 }else{
75 boolean mobile_verification = Verification.isPositiveInteger(Strings.CS.removeStart(user.getMobile().trim(), "+"));//正整数
76 if(!mobile_verification){
77 errors.rejectValue("mobile","errors.common", new String[]{"手机号码不正确"},"");
78 }
79 }
80 }
81 if(user.getEmail() != null && !user.getEmail().trim().isEmpty()){
82 if(!Verification.isEmail(user.getEmail().trim())){
83
84 errors.rejectValue("email","errors.common", new String[]{"Email地址不正确"},"");
85 }
86 if(user.getEmail().trim().length()>90){
87 errors.rejectValue("password","errors.common", new String[]{"Email地址不能超过90个字符"},"");
88 }

Callers

nothing calls this directly

Calls 13

isPositiveIntegerMethod · 0.95
isEmailMethod · 0.95
getNicknameMethod · 0.80
getPasswordMethod · 0.80
getTypeMethod · 0.65
findUserByAccountMethod · 0.65
findUserByNicknameMethod · 0.65
getPointMethod · 0.65
equalsMethod · 0.45

Tested by

no test coverage detected