mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-08 11:07:34 +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"));
|
return ResponseEntity.badRequest().body(Map.of("error", "Invalid captcha"));
|
||||||
}
|
}
|
||||||
Optional<User> userOpt = userService.findByUsername(req.getUsernameOrEmail());
|
Optional<User> userOpt = userService.findByUsername(req.getUsernameOrEmail());
|
||||||
|
if (userOpt.isEmpty()) {
|
||||||
|
userOpt = userService.findByEmail(req.getUsernameOrEmail());
|
||||||
|
}
|
||||||
if (userOpt.isEmpty() || !userService.matchesPassword(userOpt.get(), req.getPassword())) {
|
if (userOpt.isEmpty() || !userService.matchesPassword(userOpt.get(), req.getPassword())) {
|
||||||
return ResponseEntity.badRequest().body(Map.of(
|
return ResponseEntity.badRequest().body(Map.of(
|
||||||
"error", "Invalid credentials",
|
"error", "Invalid credentials",
|
||||||
|
|||||||
@@ -102,6 +102,10 @@ public class UserService {
|
|||||||
return userRepository.findByUsername(username);
|
return userRepository.findByUsername(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<User> findByEmail(String email) {
|
||||||
|
return userRepository.findByEmail(email);
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<User> findById(Long id) {
|
public Optional<User> findById(Long id) {
|
||||||
return userRepository.findById(id);
|
return userRepository.findById(id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user