From 4f6f15b818704079ff2e4e4719b798f48d68a335 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期五, 11 九月 2026 13:52:19 +0800
Subject: [PATCH] update

---
 backend/src/main/java/com/tourguide/modules/user/service/AuthService.java |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/backend/src/main/java/com/tourguide/modules/user/service/AuthService.java b/backend/src/main/java/com/tourguide/modules/user/service/AuthService.java
index 440aeec..2fdd59b 100644
--- a/backend/src/main/java/com/tourguide/modules/user/service/AuthService.java
+++ b/backend/src/main/java/com/tourguide/modules/user/service/AuthService.java
@@ -21,6 +21,7 @@
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
 
 import java.nio.charset.StandardCharsets;
 import java.util.List;
@@ -59,8 +60,13 @@
 
     public AuthResponse<UserResponse> loginAdmin(LoginRequest request) {
         AdminUser user = adminUserService.findByUsername(request.getUsername());
-        if (user == null || user.getStatus() == null || user.getStatus() != 1
-                || !passwordEncoder.matches(request.getPassword(), user.getPassword())) {
+        if (user == null) {
+            throw new BusinessException(401, "用户名或密码错误");
+        }
+        if (user.getStatus() == null || user.getStatus() != 1) {
+            throw new BusinessException(403, "账号已被禁用,请联系管理员");
+        }
+        if (!passwordEncoder.matches(request.getPassword(), user.getPassword())) {
             throw new BusinessException(401, "用户名或密码错误");
         }
         List<String> menuCodes = adminPermissionService.getMenuCodes(user.getRoleCode());
@@ -129,12 +135,20 @@
     private GuideUser findLoginableGuideByPhone(String phone) {
         GuideUser user = guideUserService.findByPhone(phone);
         validateGuideLoginStatus(user, "手机号未注册");
+        validateGuideLoginPhone(user, phone);
         guideAutoDisableService.disableGuideIfEligible(user.getId());
         GuideUser currentUser = guideUserService.findByPhone(phone);
         validateGuideLoginStatus(currentUser, "手机号未注册");
+        validateGuideLoginPhone(currentUser, phone);
         return currentUser;
     }
 
+    private void validateGuideLoginPhone(GuideUser user, String phone) {
+        if (StringUtils.hasText(user.getMobile()) && !phone.equals(user.getMobile())) {
+            throw new BusinessException(401, "手机号未注册");
+        }
+    }
+
     private void validateGuideLoginStatus(GuideUser user, String notFoundMessage) {
         if (user == null) {
             throw new BusinessException(401, notFoundMessage);

--
Gitblit v1.7.1