if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
UserLogUtils.log(
username,
"loginError",
"username is empty");
throw new UserNotExistsException();
}
//密码如果不在指定范围内 肯定错误
if (password.length() < User.PASSWORD_MIN_LENGTH || password.length() > User.PASSWORD_MAX_LENGTH) {
UserLogUtils.log(
username,
"loginError",
"password length error! password is between {} and {}",
User.PASSWORD_MIN_LENGTH, User.PASSWORD_MAX_LENGTH);
throw new UserPasswordNotMatchException();
}
User user = null;
//此处需要走代理对象,目的是能走缓存切面
UserService proxyUserService = (UserService) AopContext.currentProxy();
if (maybeUsername(username)) {
user = proxyUserService.findByUsername(username);
}
if (user == null && maybeEmail(username)) {
user = proxyUserService.findByEmail(username);
}
if (user == null && maybeMobilePhoneNumber(username)) {
user = proxyUserService.findByMobilePhoneNumber(username);
}
if (user == null || Boolean.TRUE.equals(user.getDeleted())) {
UserLogUtils.log(
username,
"loginError",
"user is not exists!");
throw new UserNotExistsException();
}
passwordService.validate(user, password);
if (user.getStatus() == UserStatus.blocked) {