|
|
@@ -4,9 +4,9 @@ import java.util.Calendar;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import javax.validation.Valid;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.log4j.Logger;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
@@ -23,35 +23,39 @@ import com.goafanti.common.utils.VerifyCodeUtils;
|
|
|
import com.goafanti.core.shiro.token.TokenManager;
|
|
|
import com.goafanti.user.service.UserService;
|
|
|
|
|
|
-
|
|
|
@Controller
|
|
|
-public class UserRegisterController extends BaseController{
|
|
|
+public class UserRegisterController extends BaseController {
|
|
|
@Resource
|
|
|
- private UserService userService;
|
|
|
+ private UserService userService;
|
|
|
@Resource(name = "passwordUtil")
|
|
|
- private PasswordUtil passwordUtil;
|
|
|
+ private PasswordUtil passwordUtil;
|
|
|
+
|
|
|
+ Logger logger = Logger.getLogger(UserRegisterController.class);
|
|
|
+
|
|
|
/**
|
|
|
* 用户注册
|
|
|
+ *
|
|
|
* @param user
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/register", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
- public Result register(User user,
|
|
|
- String companyName,String verificationCode,String contacts,
|
|
|
- String mobileCode,BindingResult bindingResult){
|
|
|
+ public Result register(User user, String companyName, String verificationCode, String contacts, String mobileCode,
|
|
|
+ BindingResult bindingResult) {
|
|
|
Result res = new Result();
|
|
|
- if(!TokenManager.getSession().getAttribute(VerifyCodeUtils.V_CODE).equals(verificationCode)){
|
|
|
- res.getError().add(buildError(ErrorConstants.VCODE_ERROR,"验证码错误"));
|
|
|
+ String sessVCode = (String) TokenManager.getSession().getAttribute(VerifyCodeUtils.V_CODE);
|
|
|
+ if (sessVCode == null || !sessVCode.equals(verificationCode)) {
|
|
|
+ logger.info("input vcode:" + verificationCode + "| sess vcode:" + sessVCode);
|
|
|
+ res.getError().add(buildError(ErrorConstants.VCODE_ERROR, "验证码错误"));
|
|
|
return res;
|
|
|
}
|
|
|
- //验证码15分钟有效
|
|
|
- if(TimeUtils.checkOverTime("register")){
|
|
|
- res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR,"手机验证码超时失效"));
|
|
|
+ // 验证码15分钟有效
|
|
|
+ if (TimeUtils.checkOverTime("register")) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR, "手机验证码超时失效"));
|
|
|
return res;
|
|
|
}
|
|
|
- if(!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode)){
|
|
|
- res.getError().add(buildError(ErrorConstants.MCODE_ERROR,"手机验证码错误"));
|
|
|
+ if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode)) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "手机验证码错误"));
|
|
|
return res;
|
|
|
}
|
|
|
if (bindingResult.hasErrors()) {
|
|
|
@@ -59,29 +63,28 @@ public class UserRegisterController extends BaseController{
|
|
|
bindingResult.getFieldError().getField()));
|
|
|
return res;
|
|
|
}
|
|
|
- if(StringUtils.isBlank(user.getMobile())){
|
|
|
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"必须指定","用户名"));
|
|
|
- }else if(StringUtils.isBlank(user.getPassword())){
|
|
|
+ if (StringUtils.isBlank(user.getMobile())) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须指定", "用户名"));
|
|
|
+ } else if (StringUtils.isBlank(user.getPassword())) {
|
|
|
res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须指定", "密码"));
|
|
|
- }else{
|
|
|
- User u = userService.selectByMobieAndType(user.getMobile(),user.getType());
|
|
|
- if(null != u){
|
|
|
- if(u.getMobile().equals(user.getMobile())&& u.getType() == user.getType()){
|
|
|
+ } else {
|
|
|
+ User u = userService.selectByMobieAndType(user.getMobile(), user.getType());
|
|
|
+ if (null != u) {
|
|
|
+ if (u.getMobile().equals(user.getMobile()) && u.getType() == user.getType()) {
|
|
|
res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "用户名已存在"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if(res.getError().isEmpty()){
|
|
|
+ if (res.getError().isEmpty()) {
|
|
|
user.setId(UUID.randomUUID().toString());
|
|
|
Calendar now = Calendar.getInstance();
|
|
|
now.set(Calendar.MILLISECOND, 0);
|
|
|
user.setCreateTime(now.getTime());
|
|
|
user.setPassword(passwordUtil.getEncryptPwd(user));
|
|
|
- userService.insertRegister(user,contacts,companyName,user.getId());
|
|
|
- }
|
|
|
-
|
|
|
+ userService.insertRegister(user, contacts, companyName, user.getId());
|
|
|
+ }
|
|
|
+
|
|
|
return res;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
}
|