Fix: search by email on register
This commit is contained in:
@@ -38,7 +38,8 @@ public interface CredentialRepository extends JpaRepository<Credential, byte[]>
|
|||||||
@Query("SELECT c FROM Credential c WHERE c.userIdBin = :userIdBin")
|
@Query("SELECT c FROM Credential c WHERE c.userIdBin = :userIdBin")
|
||||||
List<Credential> findByUserId(@Param("userIdBin") byte[] userIdBin);
|
List<Credential> findByUserId(@Param("userIdBin") byte[] userIdBin);
|
||||||
|
|
||||||
List<Credential> findByEmail(String email);
|
@Query("SELECT c FROM Credential c WHERE c.email = :email")
|
||||||
|
List<Credential> findByEmail(@Param("email") String email);
|
||||||
|
|
||||||
boolean existsByUsernameAndServiceId(String username, Byte serviceId);
|
boolean existsByUsernameAndServiceId(String username, Byte serviceId);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.miarma.backend.core.service;
|
package net.miarma.backend.core.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -57,9 +58,10 @@ public class AuthService {
|
|||||||
userIdByUsername = credByUsername.get().getUserId();
|
userIdByUsername = credByUsername.get().getUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
List<Credential> accountsByEmail = credentialService.getByEmail(request.email());
|
||||||
userIdByEmail = credentialService.getByEmail(request.email()).get(0).getUserId();
|
if (!accountsByEmail.isEmpty()) {
|
||||||
} catch (NotFoundException e) { }
|
userIdByEmail = accountsByEmail.getFirst().getUserId();
|
||||||
|
}
|
||||||
|
|
||||||
User user;
|
User user;
|
||||||
if (userIdByUsername != null && userIdByEmail != null) {
|
if (userIdByUsername != null && userIdByEmail != null) {
|
||||||
|
|||||||
@@ -88,8 +88,7 @@ public class CredentialService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Credential> getByEmail(String email) {
|
public List<Credential> getByEmail(String email) {
|
||||||
return credentialRepository.findByEmail(email).stream()
|
return credentialRepository.findByEmail(email);
|
||||||
.toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Credential getByUserIdAndService(UUID userId, Byte serviceId) {
|
public Credential getByUserIdAndService(UUID userId, Byte serviceId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user