/open works :-)
This commit is contained in:
parent
87496bde56
commit
659b0daf5e
@ -8,7 +8,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|||||||
public class App {
|
public class App {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(App.class, args);
|
SpringApplication.run(App.class, args);
|
||||||
System.out.println(new BCryptPasswordEncoder().encode("password000"));
|
//System.out.println(new BCryptPasswordEncoder().encode("password000"));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,14 +4,13 @@ import com.example.nto.entity.Code;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
public interface CodeRepository extends JpaRepository<Code, Long> {
|
public interface CodeRepository extends JpaRepository<Code, Long> {
|
||||||
|
boolean existsByValue(long value);
|
||||||
|
|
||||||
|
|
||||||
// Метод для поиска кодов по логину
|
|
||||||
@Query("SELECT c.value FROM Code c WHERE c.employee.login = :login")
|
|
||||||
static List<Long> findCodesByLogin(@Param("login") String login) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -15,9 +15,12 @@ public class EmployeeServiceImpl implements EmployeeService {
|
|||||||
|
|
||||||
private final EmployeeRepository employeeRepository;
|
private final EmployeeRepository employeeRepository;
|
||||||
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||||
|
private final CodeRepository codeRepository;
|
||||||
|
|
||||||
public EmployeeServiceImpl(EmployeeRepository employeeRepository) {
|
|
||||||
|
public EmployeeServiceImpl(EmployeeRepository employeeRepository, CodeRepository codeRepository) {
|
||||||
this.employeeRepository = employeeRepository;
|
this.employeeRepository = employeeRepository;
|
||||||
|
this.codeRepository = codeRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -31,20 +34,19 @@ public class EmployeeServiceImpl implements EmployeeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean validateCode(String login, long code) { //не робит((((
|
public boolean validateCode(String login, long code) {
|
||||||
|
|
||||||
List<Long> validCodes = CodeRepository.findCodesByLogin(login); // Теперь вызывается из объекта
|
|
||||||
|
|
||||||
// Проверяем, если переданный код присутствует в списке()
|
boolean exists = codeRepository.existsByValue(code);
|
||||||
boolean isValid = validCodes.contains(code);
|
|
||||||
|
|
||||||
// Вывод отладочной информации(удалить)
|
// (можно удалить в продакшене)
|
||||||
System.out.println("Valid codes: " + validCodes);
|
System.out.println("Checking code: " + code + " | Exists: " + exists);
|
||||||
System.out.println("Input code: " + code);
|
|
||||||
|
|
||||||
return isValid;
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public boolean authenticate(String login, String rawPassword) {
|
public boolean authenticate(String login, String rawPassword) {
|
||||||
Optional<Employee> employee = findByLogin(login);
|
Optional<Employee> employee = findByLogin(login);
|
||||||
if (employee.isPresent() && !employee.get().isBlocked()) {
|
if (employee.isPresent() && !employee.get().isBlocked()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user