boolean accountNonExpired = true;
boolean credentialsNonExpired = true;
boolean accountNonLocked = true;
try {
LOGGER.debug("Loading user by username: {}", email);
User user = userRepository.findByEmail(email);
// OCT 21
Calendar cal = Calendar.getInstance();
LOGGER.debug("Found user: {}", user);
if (user == null) {
return new org.springframework.security.core.userdetails.User(
" ", " ", enabled, true, true, true,
getAuthorities(new Integer(1)));
}
// OCT 21
if (!(user.getVerificationToken().isVerified())) {
enabled = false;
}
// OCT 21
if ((user.getVerificationToken().isVerified())
&& (user.getVerificationToken().getExpiryDate().getTime() - cal
.getTime().getTime()) <= 0) {
userRepository.delete(user);
// DEBUGGING
System.out.println("Deleted");
accountNonExpired = false;
}
return new org.springframework.security.core.userdetails.User(
user.getEmail(), user.getPassword().toLowerCase(), enabled,
accountNonExpired, credentialsNonExpired, accountNonLocked,
getAuthorities(user.getRole().getRole()));
} catch (Exception e) {
throw new RuntimeException(e);
}
}