Explorar o código

fix: 修改登陆查询用户bug

pangqijun hai 3 meses
pai
achega
dbd327659e

+ 4 - 8
src/main/java/org/springblade/modules/api/controller/LoginController.java

@@ -26,6 +26,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.AllArgsConstructor;
+import org.springblade.common.aspect.IPLimit;
 import org.springblade.common.cache.ParamCache;
 import org.springblade.common.constant.CommonConstant;
 import org.springblade.common.enums.AuditStatusEnum;
@@ -271,12 +272,6 @@ public class LoginController extends BladeController {
 			return R.fail("请输入手机验证码!");
 		}
 
-		User user = userService.getByAccount(username);
-
-		if (Objects.isNull(user)){
-			return R.fail("请先注册!");
-		}
-
 		String tenantId = WebUtil.getRequest().getHeader(TokenUtil.TENANT_HEADER_KEY);
 		String grantType = "phone";
 		String userType = Func.toStr(WebUtil.getRequest().getHeader(TokenUtil.USER_TYPE_HEADER_KEY), UserEnum.APP.getName());
@@ -290,12 +285,12 @@ public class LoginController extends BladeController {
 		ITokenGranter granter = TokenGranterBuilder.getGranter(grantType);
 		UserInfo userInfo = granter.grant(tokenParameter);
 		if (UserEnum.MERCHANT.getName().equals(userType)) {
-			UserMerchantVO vo = iUserMerchantService.getByUserId(user.getId());
+			UserMerchantVO vo = iUserMerchantService.getByUserId(userInfo.getUser().getId());
 			if (AuditStatusEnum.WAIT.getValue().equals(vo.getAuditStatus())) {
 				return R.fail("账号审核中");
 			}
 		}
-		if(ObjectUtil.isNotNull(user.getLogOut()) && user.getLogOut() == 1){
+		if(ObjectUtil.isNotNull(userInfo.getUser().getLogOut()) && userInfo.getUser().getLogOut() == 1){
 			return R.fail("用户已注销无法正常使用,如需使用请联系管理员");
 		}
 		return R.data(TokenUtil.createAuthInfo(userInfo));
@@ -353,6 +348,7 @@ public class LoginController extends BladeController {
 	@ApiOperationSupport(order = 6)
 	@ApiOperation(value = "商家注册", notes = "商家注册")
 	@Transactional
+	@IPLimit(count = 1, time = 1)
 	public R<Void> merchantRegister(@Valid @RequestBody MerchantRegisterRequest request) {
 		if (!PhoneUtil.isPhone(request.getPhone())){
 			return R.fail("请输入正确的手机号!");

+ 9 - 0
src/main/java/org/springblade/modules/auth/enums/UserEnum.java

@@ -52,4 +52,13 @@ public enum UserEnum {
 	final String name;
 	final int category;
 
+	public static int getValue(String name) {
+		for (UserEnum value : UserEnum.values()) {
+			if (value.getName().equals(name)) {
+				return value.getCategory();
+			}
+		}
+		return -1;
+	}
+
 }

+ 6 - 3
src/main/java/org/springblade/modules/auth/granter/PhoneTokenGranter.java

@@ -69,6 +69,8 @@ public class PhoneTokenGranter implements ITokenGranter {
 		String username = tokenParameter.getArgs().getStr("username");//手机号
 		String captchaCode = tokenParameter.getArgs().getStr("captchaCode");
 		String tenantId = tokenParameter.getArgs().getStr("tenantId");
+		// 获取用户类型
+		String userType = tokenParameter.getArgs().getStr("userType");
 		// 获取验证码
 		String cache = bladeRedis.get(this.cacheKey(username, captchaId));
 		// 判断验证码
@@ -81,7 +83,8 @@ public class PhoneTokenGranter implements ITokenGranter {
 		if (cnt >= failCount) {
 			throw new ServiceException(TokenUtil.USER_HAS_TOO_MANY_FAILS);
 		}
-		User user = userService.userByAccount(tenantId, username);
+//		User user = userService.userByAccount(tenantId, username);
+		User user = userService.getByAccountAndType(username, UserEnum.getValue(userType));
 		if (user == null){
 			throw new ServiceException("手机号不存在");
 		}
@@ -93,13 +96,13 @@ public class PhoneTokenGranter implements ITokenGranter {
 			if (TokenUtil.judgeTenant(tenant)) {
 				throw new ServiceException(TokenUtil.USER_HAS_NO_TENANT_PERMISSION);
 			}
-			// 获取用户类型
-			String userType = tokenParameter.getArgs().getStr("userType");
 			// 根据不同用户类型调用对应的接口返回数据,用户可自行拓展
 			if (userType.equals(UserEnum.WEB.getName())) {
 				userInfo = userService.userInfo(tenantId, username, password, UserEnum.WEB);
 			} else if (userType.equals(UserEnum.APP.getName())) {
 				userInfo = userService.userInfo(tenantId, username, password, UserEnum.APP);
+			} else if (userType.equals(UserEnum.MERCHANT.getName())) {
+				userInfo = userService.userInfo(tenantId, username, password, UserEnum.MERCHANT);
 			} else {
 				userInfo = userService.userInfo(tenantId, username, password, UserEnum.OTHER);
 			}

+ 10 - 0
src/main/java/org/springblade/modules/system/mapper/UserMapper.java

@@ -57,6 +57,16 @@ public interface UserMapper extends BaseMapper<User> {
 	 */
 	User getUser(String tenantId, String account, String password);
 
+	/**
+	 * 获取用户
+	 *
+	 * @param tenantId
+	 * @param account
+	 * @param password
+	 * @return
+	 */
+	User getUserAndType(String tenantId, String account, String password, Integer type);
+
 	/**
 	 * 获取导出用户数据
 	 *

+ 8 - 0
src/main/java/org/springblade/modules/system/mapper/UserMapper.xml

@@ -277,4 +277,12 @@
           and bu.id = #{userId}
         group by bu.id
     </select>
+    <select id="getUserAndType" resultType="org.springblade.modules.system.entity.User">
+        SELECT
+            *
+        FROM
+            blade_user
+        WHERE
+            tenant_id = #{param1} and account = #{param2} and password = #{param3} and user_type = #{param4} and is_deleted = 0
+    </select>
 </mapper>

+ 1 - 1
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java

@@ -215,7 +215,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
 
 	@Override
 	public UserInfo userInfo(String tenantId, String account, String password, UserEnum userEnum) {
-		User user = baseMapper.getUser(tenantId, account, password);
+		User user = baseMapper.getUserAndType(tenantId, account, password, userEnum.getCategory());
 		return buildUserInfo(user, userEnum);
 	}