From a4e6862c3b966ce89f688d334b4ebe6557403873 Mon Sep 17 00:00:00 2001 From: truettwo Date: Wed, 19 Feb 2025 15:42:51 +0300 Subject: [PATCH] auth --- pom.xml | 15 +++++++++++ .../nto/controller/EmployeeController.java | 25 ++++++++++--------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 85d913d..32b099f 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,21 @@ org.springframework.boot spring-boot-starter-security + + io.springfox + springfox-boot-starter + 3.0.0 + + + io.springfox + springfox-boot-starter + 3.0.0 + + + io.springfox + springfox-swagger-ui + 3.0.0 + \ No newline at end of file diff --git a/src/main/java/com/example/nto/controller/EmployeeController.java b/src/main/java/com/example/nto/controller/EmployeeController.java index 44ebf87..93ac564 100644 --- a/src/main/java/com/example/nto/controller/EmployeeController.java +++ b/src/main/java/com/example/nto/controller/EmployeeController.java @@ -22,7 +22,9 @@ public class EmployeeController { @GetMapping("/auth") // Проверка аутентификации public ResponseEntity authenticate() { + return ResponseEntity.ok("Authenticated successfully"); + } @GetMapping("/{login}/info") // Получение информации о сотруднике @@ -39,19 +41,18 @@ public class EmployeeController { public ResponseEntity openDoor(@PathVariable String login, @RequestBody Map payload) { Long code = payload.get("value"); - if (code == null) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid payload"); - } - - Optional employee = employeeService.findByLogin(login); - if (employee.isEmpty()) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid login"); - } - - if (employeeService.validateCode(login, code)) { - return ResponseEntity.ok("Door opened"); + if (code != null) { + Optional employee = employeeService.findByLogin(login); + if (!employee.isPresent()) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid login"); + } + if (employeeService.validateCode(login, code)) { + return ResponseEntity.ok("Door opened"); + } else { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid code"); + } } else { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid code"); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid payload"); } }