@RequestMapping(value = "/register.jspx", method = RequestMethod.POST)
public String submit(String username, String email, String password,
CmsUserExt userExt, String captcha, String nextUrl,
HttpServletRequest request, HttpServletResponse response,
ModelMap model) throws IOException {
CmsSite site = CmsUtils.getSite(request);
CmsConfig config=site.getConfig();
WebErrors errors = validateSubmit(username, email, password, captcha,
site, request, response);
if (errors.hasErrors()) {
return FrontUtils.showError(request, response, model, errors);
}
String ip = RequestUtils.getIpAddr(request);
if(config.getEmailValidate()){
EmailSender sender = configMng.getEmailSender();
MessageTemplate msgTpl = configMng.getRegisterMessageTemplate();
if (sender == null) {
// 邮件服务器没有设置好
model.addAttribute("status", 4);
} else if (msgTpl == null) {
// 邮件模板没有设置好
model.addAttribute("status", 5);
} else {
try {
cmsUserMng.registerMember(username, email, password, ip, null, userExt,
false, sender, msgTpl);
model.addAttribute("status", 0);
} catch (UnsupportedEncodingException e) {
// 发送邮件异常
model.addAttribute("status", 100);
model.addAttribute("message", e.getMessage());
log.error("send email exception.", e);
}catch (MessagingException e) {
// 发送邮件异常
model.addAttribute("status", 101);
model.addAttribute("message", e.getMessage());
log.error("send email exception.", e);
}
}
log.info("member register success. username={}", username);
FrontUtils.frontData(request, model, site);
if (!StringUtils.isBlank(nextUrl)) {
response.sendRedirect(nextUrl);
return null;
} else {
return FrontUtils.getTplPath(request, site.getSolutionPath(),
TPLDIR_MEMBER, REGISTER_RESULT);
}
}else{
cmsUserMng.registerMember(username, email, password, ip, null, userExt);
log.info("member register success. username={}", username);
FrontUtils.frontData(request, model, site);
FrontUtils.frontPageData(request, model);
model.addAttribute("success",true);
return FrontUtils.getTplPath(request, site.getSolutionPath(),
TPLDIR_MEMBER, LOGIN_INPUT);
}
}