| | |
| | | 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; |
| | |
| | | |
| | | 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()); |
| | |
| | | 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); |