mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-22 19:31:20 +08:00
Allow login via email
This commit is contained in:
@@ -69,6 +69,9 @@ public class AuthController {
|
||||
return ResponseEntity.badRequest().body(Map.of("error", "Invalid captcha"));
|
||||
}
|
||||
Optional<User> userOpt = userService.findByUsername(req.getUsernameOrEmail());
|
||||
if (userOpt.isEmpty()) {
|
||||
userOpt = userService.findByEmail(req.getUsernameOrEmail());
|
||||
}
|
||||
if (userOpt.isEmpty() || !userService.matchesPassword(userOpt.get(), req.getPassword())) {
|
||||
return ResponseEntity.badRequest().body(Map.of(
|
||||
"error", "Invalid credentials",
|
||||
|
||||
@@ -102,6 +102,10 @@ public class UserService {
|
||||
return userRepository.findByUsername(username);
|
||||
}
|
||||
|
||||
public Optional<User> findByEmail(String email) {
|
||||
return userRepository.findByEmail(email);
|
||||
}
|
||||
|
||||
public Optional<User> findById(Long id) {
|
||||
return userRepository.findById(id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user