Antiloveg 8 years ago
parent
commit
7ca8d9b7e2

+ 71 - 7
src/main/java/com/goafanti/common/controller/PublicController.java

@@ -23,9 +23,13 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import com.goafanti.admin.service.AftFileService;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
+import com.goafanti.common.enums.MobileCodeCheckOverTimeSign;
+import com.goafanti.common.enums.UserType;
+import com.goafanti.common.model.User;
 import com.goafanti.common.service.IndustryCategoryService;
 import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.common.utils.MobileMessageUtils;
+import com.goafanti.common.utils.PasswordUtil;
 import com.goafanti.common.utils.PictureUtils;
 import com.goafanti.common.utils.TimeUtils;
 import com.goafanti.common.utils.VerifyCodeUtils;
@@ -70,6 +74,9 @@ public class PublicController extends BaseController {
 	@Value(value = "${patentTemplate}")
 	private String					patentTemplate		= null;
 
+	@Resource(name = "passwordUtil")
+	private PasswordUtil			passwordUtil;
+
 	/**
 	 * 获取验证码
 	 * 
@@ -123,7 +130,6 @@ public class PublicController extends BaseController {
 			}
 			if (!VerifyCodeUtils.verifyCode(verificationCode)) {
 				res.getError().add(buildError(ErrorConstants.VCODE_ERROR, "", "图形验证码输入错误!"));
-
 				return res;
 			}
 		}
@@ -132,8 +138,8 @@ public class PublicController extends BaseController {
 				|| TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == "") {
 			sendMessage(mobile, res);
 		} else if (TimeUtils.checkOverTime("getMCode")) {
-			TokenManager.getSession().removeAttribute(VerifyCodeUtils.M_CODE);
-			TokenManager.getSession().removeAttribute(VerifyCodeUtils.M_CODE_TIME);
+			VerifyCodeUtils.clearMobileCode();
+			VerifyCodeUtils.clearMobileCodeTime();
 			sendMessage(mobile, res);
 		} else {
 			res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
@@ -289,7 +295,7 @@ public class PublicController extends BaseController {
 		if (!StringUtils.isBlank(path)) {
 			return handleDownloadFile(response, fileName, path, res);
 		} else {
-			res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "下载文件不存在!"));
+			res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "下载文件不存在!"));
 			return res;
 		}
 	}
@@ -378,10 +384,10 @@ public class PublicController extends BaseController {
 			return res;
 		}
 
-		if (TimeUtils.checkOverTime("register")) {
+		if (TimeUtils.checkOverTime(MobileCodeCheckOverTimeSign.REGISTER.getCode())) {
 			res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR, "", "手机验证码超时失效!"));
-			TokenManager.getSession().removeAttribute(VerifyCodeUtils.M_CODE);
-			TokenManager.getSession().removeAttribute(VerifyCodeUtils.M_CODE_TIME);
+			VerifyCodeUtils.clearMobileCode();
+			VerifyCodeUtils.clearMobileCodeTime();
 			return res;
 		}
 		if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode)) {
@@ -392,4 +398,62 @@ public class PublicController extends BaseController {
 
 	}
 
+	/**
+	 * 重置密码
+	 * 
+	 * @param resetCode
+	 * @param mobile
+	 * @param type
+	 * @param newPwd
+	 * @return
+	 */
+	@RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
+	public Result resetPwd(String resetCode, String mobile, Integer type, String newPwd) {
+		Result res = new Result();
+		if (TimeUtils.checkOverTime(MobileCodeCheckOverTimeSign.RESETCODE.getCode())) {
+			res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
+			cleanCodeSession();
+			return res;
+		}
+		if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE).equals(resetCode)) {
+			res.getError().add(buildError(ErrorConstants.RESET_CODE_ERROR, "", "页面失效,请重新获取验证码!"));
+			cleanCodeSession();
+			return res;
+		}
+
+		if (StringUtils.isBlank(newPwd)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
+			return res;
+		}
+
+		if (StringUtils.isBlank(mobile)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "mobile"));
+			return res;
+		}
+
+		if (!UserType.ORGANIZATION.getCode().equals(type) || !UserType.PERSONAL.getCode().equals(type)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "type"));
+			return res;
+		}
+
+		User user = userService.selectByMobieAndType(mobile, type);
+		if (null == user) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "mobile"));
+			return res;
+		}
+		user.setPassword(newPwd);
+		user.setPassword(passwordUtil.getEncryptPwd(user));
+		userService.updateByPrimaryKey(user);
+		VerifyCodeUtils.clearResetCode();
+		VerifyCodeUtils.clearResetCodeTime();
+		return res;
+	}
+
+	private void cleanCodeSession() {
+		VerifyCodeUtils.clearResetCode();
+		VerifyCodeUtils.clearResetCodeTime();
+		VerifyCodeUtils.clearMobileCode();
+		VerifyCodeUtils.clearMobileCodeTime();
+	}
+
 }

+ 50 - 0
src/main/java/com/goafanti/common/enums/MobileCodeCheckOverTimeSign.java

@@ -0,0 +1,50 @@
+package com.goafanti.common.enums;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public enum MobileCodeCheckOverTimeSign {
+	
+	REGISTER("register", "注册手机验证码"),
+	RESETCODE("resetCode", "重置密码手机验证码"),
+	OTHER("", "未知参数");
+	
+	private String	code;
+	private String	desc;
+	
+	private static Map<String, MobileCodeCheckOverTimeSign> status = new HashMap<String, MobileCodeCheckOverTimeSign>();
+	
+	private MobileCodeCheckOverTimeSign(String code, String desc) {
+		this.code = code;
+		this.desc = desc;
+	}
+	
+	static {
+		for (MobileCodeCheckOverTimeSign value : MobileCodeCheckOverTimeSign.values()) {
+			status.put(value.getCode(), value);
+		}
+	}
+	
+	public static MobileCodeCheckOverTimeSign getField(String code) {
+		if (containsType(code)) {
+			return status.get(code);
+		}
+		return OTHER;
+	}
+	
+	public static String getFieldDesc(String code) {
+		return getField(code).getDesc();
+	}
+
+	public static boolean containsType(String code) {
+		return status.containsKey(code);
+	}
+	
+	public String getCode() {
+		return code;
+	}
+
+	public String getDesc() {
+		return desc;
+	}
+}

+ 38 - 18
src/main/java/com/goafanti/common/utils/VerifyCodeUtils.java

@@ -21,22 +21,22 @@ import com.goafanti.core.shiro.token.TokenManager;
 public class VerifyCodeUtils {
 
 	// 使用到Algerian字体,系统里没有的话需要安装字体,字体只显示大写,去掉了1,0,i,o几个容易混淆的字符
-	public static final String VERIFY_CODES = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
+	public static final String	VERIFY_CODES	= "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
 	// 验证码的Key
-	public static final String V_CODE = "_CODE";
-	
-	//手机验证码
-	public static final String M_VERIFY_CODES = "23456789";
-	//手机验证码Key
-	public static final String 	M_CODE = "M_CODE";
-	//手机验证码生成时间
-	public static final String M_CODE_TIME = "M_CODE_TIME";
-	
-	public static final String RESET_CODE = "RESET_CODE";
-	
-	public static final String RESET_CODE_TIME = "RESET_CODE_TIME";
-	
-	private static Random random = new Random();
+	public static final String	V_CODE			= "_CODE";
+
+	// 手机验证码
+	public static final String	M_VERIFY_CODES	= "23456789";
+	// 手机验证码Key
+	public static final String	M_CODE			= "M_CODE";
+	// 手机验证码生成时间
+	public static final String	M_CODE_TIME		= "M_CODE_TIME";
+
+	public static final String	RESET_CODE		= "RESET_CODE";
+
+	public static final String	RESET_CODE_TIME	= "RESET_CODE_TIME";
+
+	private static Random		random			= new Random();
 
 	/**
 	 * 验证码对象
@@ -44,9 +44,9 @@ public class VerifyCodeUtils {
 	 */
 	public static class Verify {
 
-		private String code;// 如 1 + 2
+		private String	code;	// 如 1 + 2
 
-		private Integer value;// 如 3
+		private Integer	value;	// 如 3
 
 		public String getCode() {
 			return code;
@@ -91,9 +91,10 @@ public class VerifyCodeUtils {
 	public static String generateVerifyCode(int verifySize) {
 		return generateVerifyCode(verifySize, VERIFY_CODES);
 	}
-	
+
 	/**
 	 * 手机验证码
+	 * 
 	 * @param verifySize
 	 * @return
 	 */
@@ -120,6 +121,25 @@ public class VerifyCodeUtils {
 	public static void clearVerifyCode() {
 		TokenManager.getSession().removeAttribute(V_CODE);
 	}
+	
+	/**
+	 * 清除手机验证码
+	 */
+	public static void clearMobileCode(){
+		TokenManager.getSession().removeAttribute(M_CODE);
+	}
+	
+	public static void clearMobileCodeTime(){
+		TokenManager.getSession().removeAttribute(VerifyCodeUtils.M_CODE_TIME);
+	}
+	
+	public static void clearResetCode(){
+		TokenManager.getSession().removeAttribute(VerifyCodeUtils.RESET_CODE);
+	}
+	
+	public static void clearResetCodeTime(){
+		TokenManager.getSession().removeAttribute(VerifyCodeUtils.RESET_CODE_TIME);
+	}
 
 	/**
 	 * 对比验证码

+ 2 - 56
src/main/java/com/goafanti/user/controller/UserApiController.java

@@ -143,56 +143,7 @@ public class UserApiController extends BaseApiController {
 		return res;
 	}
 
-	/**
-	 * 重置密码
-	 * 
-	 * @param resetCode
-	 * @param mobile
-	 * @param type
-	 * @param newPwd
-	 * @return
-	 */
-	@RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
-	public Result resetPwd(String resetCode, String mobile, Integer type, String newPwd) {
-		Result res = new Result();
-		if (TimeUtils.checkOverTime("resetCode")) {
-			res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "页面超时失效,请重新获取验证码!"));
-			this.cleanCodeSession();
-			return res;
-		}
-		if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE).equals(resetCode)) {
-			res.getError().add(buildError(ErrorConstants.RESET_CODE_ERROR, "页面失效,请重新获取验证码!"));
-			this.cleanCodeSession();
-			return res;
-		}
-
-		if (StringUtils.isBlank(newPwd)) {
-			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
-			return res;
-		}
-
-		if (StringUtils.isBlank(mobile)) {
-			res.getError().add(buildError(ErrorConstants.MOBILE_EMPTY_ERROR, "", "mobile"));
-			return res;
-		}
-
-		if (1 != type || 0 != type) {
-			res.getError().add(buildError(ErrorConstants.PARAM_PATTERN_ERROR, "", "type"));
-			return res;
-		}
-
-		User user = userService.selectByMobieAndType(mobile, type);
-		if (null == user) {
-			res.getError().add(buildError(ErrorConstants.MOBILE_EMPTY_ERROR, "", "mobile"));
-			return res;
-		}
-		user.setPassword(newPwd);
-		user.setPassword(passwordUtil.getEncryptPwd(user));
-		userService.updateByPrimaryKey(user);
-		TokenManager.getSession().removeAttribute(VerifyCodeUtils.RESET_CODE);
-		TokenManager.getSession().removeAttribute(VerifyCodeUtils.RESET_CODE_TIME);
-		return res;
-	}
+	
 
 	
 
@@ -903,12 +854,7 @@ public class UserApiController extends BaseApiController {
 		return res;
 	}
 
-	private void cleanCodeSession() {
-		TokenManager.getSession().removeAttribute(VerifyCodeUtils.RESET_CODE);
-		TokenManager.getSession().removeAttribute(VerifyCodeUtils.RESET_CODE_TIME);
-		TokenManager.getSession().removeAttribute(VerifyCodeUtils.M_CODE);
-		TokenManager.getSession().removeAttribute(VerifyCodeUtils.M_CODE_TIME);
-	}
+	
 
 	private UidAndTypeBo basicInfo(UserService userService) {
 		User u = userService.selectByPrimaryKey(TokenManager.getUserId());

+ 4 - 0
src/main/resources/props/error.properties

@@ -76,3 +76,7 @@ NON_REGISTER=\u8be5\u7528\u6237\u672a\u6ce8\u518c\uff01
 MCODE_EMPTY_ERROR=\u624b\u673a\u9a8c\u8bc1\u7801\u4e0d\u80fd\u4e3a\u7a7a\uff01
 
 MCODE_OVERTIME_ERROR=\u624b\u673a\u9a8c\u8bc1\u7801\u8d85\u65f6\u5931\u6548\uff01
+
+RESET_CODE_ERROR=\u9875\u9762\u5931\u6548,\u8bf7\u91cd\u65b0\u83b7\u53d6\u9a8c\u8bc1\u7801\uff01
+
+RESET_CODE_OVERTIME=\u9875\u9762\u8d85\u65f6\u5931\u6548,\u8bf7\u91cd\u65b0\u83b7\u53d6\u9a8c\u8bc1\u7801\uff01