auth
This commit is contained in:
parent
eefdf4a072
commit
a4e6862c3b
15
pom.xml
15
pom.xml
@ -56,6 +56,21 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-boot-starter</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-boot-starter</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-swagger-ui</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -22,7 +22,9 @@ public class EmployeeController {
|
|||||||
|
|
||||||
@GetMapping("/auth") // Проверка аутентификации
|
@GetMapping("/auth") // Проверка аутентификации
|
||||||
public ResponseEntity<?> authenticate() {
|
public ResponseEntity<?> authenticate() {
|
||||||
|
|
||||||
return ResponseEntity.ok("Authenticated successfully");
|
return ResponseEntity.ok("Authenticated successfully");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{login}/info") // Получение информации о сотруднике
|
@GetMapping("/{login}/info") // Получение информации о сотруднике
|
||||||
@ -39,19 +41,18 @@ public class EmployeeController {
|
|||||||
public ResponseEntity<?> openDoor(@PathVariable String login, @RequestBody Map<String, Long> payload) {
|
public ResponseEntity<?> openDoor(@PathVariable String login, @RequestBody Map<String, Long> payload) {
|
||||||
Long code = payload.get("value");
|
Long code = payload.get("value");
|
||||||
|
|
||||||
if (code == null) {
|
if (code != null) {
|
||||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid payload");
|
Optional<Employee> employee = employeeService.findByLogin(login);
|
||||||
}
|
if (!employee.isPresent()) {
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid login");
|
||||||
Optional<Employee> employee = employeeService.findByLogin(login);
|
}
|
||||||
if (employee.isEmpty()) {
|
if (employeeService.validateCode(login, code)) {
|
||||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid login");
|
return ResponseEntity.ok("Door opened");
|
||||||
}
|
} else {
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid code");
|
||||||
if (employeeService.validateCode(login, code)) {
|
}
|
||||||
return ResponseEntity.ok("Door opened");
|
|
||||||
} else {
|
} else {
|
||||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid code");
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid payload");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user