提交 4d26ffb4 编写于 作者: NoSubject's avatar NoSubject

Merge branch 'feature/用户注册可填写邮箱' into 'wrdp'

[人员组织]用户注册可填写邮箱

See merge request o2oa/o2oa!3483
...@@ -36,6 +36,7 @@ class ActionCreate extends BaseAction { ...@@ -36,6 +36,7 @@ class ActionCreate extends BaseAction {
String codeAnswer = wi.getCodeAnswer(); String codeAnswer = wi.getCodeAnswer();
String captcha = wi.getCaptcha(); String captcha = wi.getCaptcha();
String captchaAnswer = wi.getCaptchaAnswer(); String captchaAnswer = wi.getCaptchaAnswer();
String mail = wi.getMail();
if (StringUtils.equals(com.x.base.core.project.config.Person.REGISTER_TYPE_DISABLE, if (StringUtils.equals(com.x.base.core.project.config.Person.REGISTER_TYPE_DISABLE,
Config.person().getRegister())) { Config.person().getRegister())) {
throw new ExceptionDisableRegist(); throw new ExceptionDisableRegist();
...@@ -52,6 +53,14 @@ class ActionCreate extends BaseAction { ...@@ -52,6 +53,14 @@ class ActionCreate extends BaseAction {
if (this.mobileExisted(emc, mobile)) { if (this.mobileExisted(emc, mobile)) {
throw new ExceptionMobileExist(mobile); throw new ExceptionMobileExist(mobile);
} }
if(StringUtils.isNotBlank(mail)){
if (!StringTools.isMail(mail)) {
throw new ExceptionInvalidMail(mail);
}
if(this.mailExisted(emc, mail)){
throw new ExceptionMailExist(mail);
}
}
if (!password.matches(Config.person().getPasswordRegex())) { if (!password.matches(Config.person().getPasswordRegex())) {
throw new ExceptionInvalidPassword(Config.person().getPasswordRegexHint()); throw new ExceptionInvalidPassword(Config.person().getPasswordRegexHint());
} }
...@@ -73,7 +82,7 @@ class ActionCreate extends BaseAction { ...@@ -73,7 +82,7 @@ class ActionCreate extends BaseAction {
throw new ExceptionInvalidCaptcha(); throw new ExceptionInvalidCaptcha();
} }
} }
this.register(business, name, password, genderType, mobile); this.register(business, name, password, genderType, mobile, mail);
Wo wo = new Wo(); Wo wo = new Wo();
wo.setValue(true); wo.setValue(true);
result.setData(wo); result.setData(wo);
...@@ -81,13 +90,14 @@ class ActionCreate extends BaseAction { ...@@ -81,13 +90,14 @@ class ActionCreate extends BaseAction {
} }
} }
private void register(Business business, String name, String password, GenderType genderType, String mobile) private void register(Business business, String name, String password, GenderType genderType, String mobile, String mail)
throws Exception { throws Exception {
Person o = new Person(); Person o = new Person();
o.setName(name); o.setName(name);
business.person().setPassword(o, password); business.person().setPassword(o, password);
o.setGenderType(genderType); o.setGenderType(genderType);
o.setMobile(mobile); o.setMobile(mobile);
o.setMail(mail);
business.entityManagerContainer().beginTransaction(Person.class); business.entityManagerContainer().beginTransaction(Person.class);
business.entityManagerContainer().persist(o, CheckPersistType.all); business.entityManagerContainer().persist(o, CheckPersistType.all);
business.entityManagerContainer().commit(); business.entityManagerContainer().commit();
...@@ -97,25 +107,28 @@ class ActionCreate extends BaseAction { ...@@ -97,25 +107,28 @@ class ActionCreate extends BaseAction {
@FieldDescribe("用户名称.") @FieldDescribe("用户名称.")
private String name; private String name;
@FieldDescribe("性别.男:m,女:f,未知:d") @FieldDescribe("性别.男:m,女:f,未知:d")
private GenderType genderType; private GenderType genderType;
@FieldDescribe("密码.") @FieldDescribe("密码.")
private String password; private String password;
@FieldDescribe("必填,手机号.") @FieldDescribe("必填,手机号.")
private String mobile; private String mobile;
@FieldDescribe("手机认证码") @FieldDescribe("手机认证码")
private String codeAnswer; private String codeAnswer;
@FieldDescribe("图片认证码") @FieldDescribe("图片认证码")
private String captchaAnswer; private String captchaAnswer;
@FieldDescribe("图片认证编号") @FieldDescribe("图片认证编号")
private String captcha; private String captcha;
@FieldDescribe("邮件地址(非必填).")
private String mail;
public String getName() { public String getName() {
return name; return name;
} }
...@@ -172,9 +185,16 @@ class ActionCreate extends BaseAction { ...@@ -172,9 +185,16 @@ class ActionCreate extends BaseAction {
this.captcha = captcha; this.captcha = captcha;
} }
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
} }
public static class Wo extends WrapBoolean { public static class Wo extends WrapBoolean {
} }
} }
\ No newline at end of file
...@@ -49,4 +49,18 @@ abstract class BaseAction extends StandardJaxrsAction { ...@@ -49,4 +49,18 @@ abstract class BaseAction extends StandardJaxrsAction {
return false; return false;
} }
} }
}
\ No newline at end of file Boolean mailExisted(EntityManagerContainer emc, String mail) throws Exception {
EntityManager em = emc.get(Person.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<Person> root = cq.from(Person.class);
Predicate p = cb.equal(root.get(Person_.mail), mail);
cq.select(cb.count(root.get(Person_.id))).where(p);
if (em.createQuery(cq).getSingleResult() > 0) {
return true;
} else {
return false;
}
}
}
package com.x.organization.assemble.personal.jaxrs.regist;
import com.x.base.core.project.exception.PromptException;
import java.util.Objects;
class ExceptionInvalidMail extends PromptException {
private static final long serialVersionUID = 4622760821556680073L;
ExceptionInvalidMail(String mail) {
super("邮件地址错误:不符合格式要求:" + Objects.toString(mail) + ".");
}
}
package com.x.organization.assemble.personal.jaxrs.regist;
import com.x.base.core.project.exception.PromptException;
import java.util.Objects;
class ExceptionMailExist extends PromptException {
private static final long serialVersionUID = -2489020682959861835L;
ExceptionMailExist(String mail) {
super("邮件:" + Objects.toString(mail) + "已注册.");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册