瀏覽代碼

APP注册接口更改为2个接口,注册验证与注册

anderx 7 年之前
父節點
當前提交
697505e0d0

+ 112 - 1
src/main/java/com/goafanti/app/controller/OpenAppUserController.java

@@ -1,9 +1,16 @@
 package com.goafanti.app.controller;
 
+import java.util.Calendar;
+import java.util.UUID;
+
 import javax.annotation.Resource;
+import javax.validation.Valid;
+
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.goafanti.achievement.service.AchievementInterestService;
@@ -13,12 +20,22 @@ import com.goafanti.banners.service.BannersService;
 import com.goafanti.comment.bo.CommentResult;
 import com.goafanti.comment.service.CommentService;
 import com.goafanti.common.bo.Result;
+import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.common.enums.UserAuthentication;
+import com.goafanti.common.enums.UserFields;
+import com.goafanti.common.enums.UserLevel;
+import com.goafanti.common.model.User;
+import com.goafanti.common.utils.PasswordUtil;
+import com.goafanti.common.utils.TimeUtils;
+import com.goafanti.common.utils.VerifyCodeUtils;
+import com.goafanti.core.shiro.token.TokenManager;
 import com.goafanti.demand.service.DemandService;
 import com.goafanti.easemob.EasemobUtils;
 import com.goafanti.message.service.MessageService;
 import com.goafanti.news.service.NewsService;
+import com.goafanti.user.bo.InputUser;
 import com.goafanti.user.service.UserCareerService;
 import com.goafanti.user.service.UserIdentityService;
 import com.goafanti.user.service.UserInterestService;
@@ -50,7 +67,11 @@ public class OpenAppUserController extends BaseApiController {
 	@Resource
 	private UserIdentityService	userIdentityService;
 	@Resource
-	AchievementInterestService achievementInterestService;
+	private AchievementInterestService achievementInterestService;
+	@Resource
+	private UserService	userService;
+	@Resource(name = "passwordUtil")
+	private PasswordUtil	passwordUtil;
 	
 	/**
 	 * 成果详情
@@ -122,4 +143,94 @@ public class OpenAppUserController extends BaseApiController {
 		res.setData(messageService.selectMessageWithGroup());
 		return res;
 	}
+	
+	/**
+	 * APP用户注册检查
+	 * 
+	 * @param user
+	 * @return
+	 */
+	@RequestMapping(value = "/registerCheck", method = RequestMethod.GET)
+	@ResponseBody
+	public Result registerCheck(@Valid InputUser user, String mobileCode,String uuid,BindingResult bindingResult) {
+		Result res = new Result();
+		if (bindingResult.hasErrors()) {
+			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
+					UserFields.getFieldDesc(bindingResult.getFieldError().getField())));
+			return res;
+		}
+		
+		if (StringUtils.isBlank(user.getMobile())) {
+			res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "手机号码不能为空"));
+			return res;
+		}
+		User u = userService.selectByMobieAndType(user.getMobile().trim(),null);
+		if (null != u) {
+			res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "用户已存在"));
+		}
+		if (TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) ==null||!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode.toLowerCase())) {
+			res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "手机验证码错误"));
+			return res;
+		}
+		// 验证码15分钟有效
+		if (TimeUtils.checkOverTime("register")) {
+			res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR, "手机验证码超时失效"));
+			return res;
+		}
+		
+		return res.data(1);
+	}
+	/**
+	 * APP用户注册
+	 * 
+	 * @param user
+	 * @return
+	 */
+	@RequestMapping(value = "/appRegister", method = RequestMethod.POST)
+	@ResponseBody
+	public Result AppRegister(@Valid InputUser user, String mobileCode,String uuid,BindingResult bindingResult) {
+		Result res = new Result();
+		if (bindingResult.hasErrors()) {
+			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
+					UserFields.getFieldDesc(bindingResult.getFieldError().getField())));
+			return res;
+		}
+		if (StringUtils.isBlank(user.getUnitName())) {
+			res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "用户名不能为空"));
+			return res;
+		}
+		if (StringUtils.isBlank(user.getMobile())) {
+			res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "手机号码不能为空"));
+			return res;
+		}
+		if (user.getBeInviteCode()!=null&&!user.getBeInviteCode().equals("")&&userService.checkeToInviteCode(user.getBeInviteCode())) {
+			res.getError().add(buildError("邀请码不存在", "邀请码不存在"));
+			return res;
+		}
+		if (res.getError().isEmpty()) {
+			User us = new User();
+			us.setId(UUID.randomUUID().toString());
+			us.setMobile(user.getMobile().trim());
+			us.setPassword(user.getPassword());
+			Calendar now = Calendar.getInstance();
+			now.set(Calendar.MILLISECOND, 0);
+			us.setCreateTime(now.getTime());
+			us.setUpdateTime(now.getTime());
+			us.setPassword(passwordUtil.getEncryptPwd(us));
+			us.setNickname(user.getUnitName());
+			us.setType(user.getType());
+			us.setBeInviteCode(user.getBeInviteCode());
+			us.setSource(AFTConstants.USER_SOURCE_REGISTER);
+			us.setStatus(AFTConstants.USER_STATUS_NORMAL);
+			us.setShareType(AFTConstants.USER_SHARE_PUBLIC);
+			us.setIdentifyName(StringUtils.isBlank(user.getUnitName())?"":user.getUnitName());
+			us.setLvl(UserLevel.GENERAL.getCode());
+			us.setAuthentication(UserAuthentication.UN_AUTHENTICATION.getCode());
+			us.setTransferTime(now.getTime());
+			userService.insertRegister(us,user.getUnitName(),user.getUsername());
+			//获得抵用券
+			userService.saveVoucher(us);
+		}
+		return res;
+	}
 }

+ 5 - 1
src/main/java/com/goafanti/common/mapper/UserMapper.xml

@@ -709,7 +709,11 @@
     select
   <include refid="Base_Column_List" />
     from user
-    where mobile = #{0} and type=#{1} and source = 0
+    where mobile = #{0} 
+    <if test="#{1} !=null">
+    and type=#{1} 
+    </if>
+    and source = 0
   </select>
   
   <select id="selectByNameAndType" resultMap="BaseResultMap">