/open works :-)

This commit is contained in:
truettwo 2025-02-20 12:09:57 +03:00
parent 87496bde56
commit 659b0daf5e
3 changed files with 16 additions and 15 deletions

View File

@ -8,7 +8,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
System.out.println(new BCryptPasswordEncoder().encode("password000"));
//System.out.println(new BCryptPasswordEncoder().encode("password000"));
}

View File

@ -4,14 +4,13 @@ import com.example.nto.entity.Code;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
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;
}
}

View File

@ -15,9 +15,12 @@ public class EmployeeServiceImpl implements EmployeeService {
private final EmployeeRepository employeeRepository;
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
private final CodeRepository codeRepository;
public EmployeeServiceImpl(EmployeeRepository employeeRepository) {
public EmployeeServiceImpl(EmployeeRepository employeeRepository, CodeRepository codeRepository) {
this.employeeRepository = employeeRepository;
this.codeRepository = codeRepository;
}
@Override
@ -31,20 +34,19 @@ public class EmployeeServiceImpl implements EmployeeService {
}
@Override
public boolean validateCode(String login, long code) { //не робит((((
public boolean validateCode(String login, long code) {
List<Long> validCodes = CodeRepository.findCodesByLogin(login); // Теперь вызывается из объекта
// Проверяем, если переданный код присутствует в списке()
boolean isValid = validCodes.contains(code);
boolean exists = codeRepository.existsByValue(code);
// Вывод отладочной информации(удалить)
System.out.println("Valid codes: " + validCodes);
System.out.println("Input code: " + code);
// (можно удалить в продакшене)
System.out.println("Checking code: " + code + " | Exists: " + exists);
return isValid;
return exists;
}
public boolean authenticate(String login, String rawPassword) {
Optional<Employee> employee = findByLogin(login);
if (employee.isPresent() && !employee.get().isBlocked()) {