diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 4d6f6fe..ad299de 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,11 +4,12 @@
-
+
-
+
-
+
+
@@ -39,6 +40,7 @@
"keyToString": {
"Application.App.executor": "Run",
"Maven.NTO-2024 [org.apache.maven.plugins:maven-clean-plugin:3.1.0:clean].executor": "Run",
+ "Maven.NTO-2024 [org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile].executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
"git-widget-placeholder": "main",
@@ -191,7 +193,15 @@
1740049179417
-
+
+
+ 1740052413527
+
+
+
+ 1740052413527
+
+
@@ -207,7 +217,8 @@
-
+
+
@@ -219,17 +230,17 @@
file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AdminController.java
- 128
+ 124
file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java
- 95
+ 96
file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java
- 82
+ 83
diff --git a/src/main/java/com/example/nto/controller/AdminController.java b/src/main/java/com/example/nto/controller/AdminController.java
index 46b7c50..f1019b6 100644
--- a/src/main/java/com/example/nto/controller/AdminController.java
+++ b/src/main/java/com/example/nto/controller/AdminController.java
@@ -7,13 +7,12 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.security.RolesAllowed;
import java.util.List;
-@Controller
+@RestController
@RequestMapping("/api/admin/")
public class AdminController {
@@ -107,20 +106,17 @@ public class AdminController {
* Такой же метод, как и getEmployeeInfo, только для админов по логину
* @return
*/
- @RolesAllowed("ADMIN")
@GetMapping("/{value}/info")
public Employee getEmployeeInfoAdmin(@PathVariable String value) {
return employeeService.getEmployeeInfoById(Long.parseLong(value));
}
- @RolesAllowed("ADMIN")
@DeleteMapping("/employee/delete/")
public ResponseEntity deleteEmployee(@RequestBody DeleteEmployeeRequest deleteEmployeeRequest) {
employeeService.deleteEmployee(deleteEmployeeRequest.id);
return ResponseEntity.status(HttpStatus.OK).build();
}
- @RolesAllowed("ADMIN")
@PutMapping("/employee/update/login/")
public ResponseEntity updateEmployeeLogin(@RequestBody UpdateEmployeeRequest updateEmployeeRequest) {
@@ -130,27 +126,23 @@ public class AdminController {
return ResponseEntity.status(HttpStatus.OK).build();
}
- @RolesAllowed("ADMIN")
@PutMapping("/employee/update/avatar/")
public ResponseEntity updateEmployeeAvatar(@RequestBody UpdateEmployeeRequest updateEmployeeRequest) {
employeeService.updateEmployeeAvatar(updateEmployeeRequest.id, updateEmployeeRequest.field);
return ResponseEntity.status(HttpStatus.OK).build();
}
- @RolesAllowed("ADMIN")
@PutMapping("/employee/update/position/")
public ResponseEntity updatePosition(@RequestBody UpdateEmployeeRequest updateEmployeeRequest) {
employeeService.updateEmployeePosition(updateEmployeeRequest.id, updateEmployeeRequest.field);
return ResponseEntity.status(HttpStatus.OK).build();
}
- @RolesAllowed("ADMIN")
@GetMapping("/employee/info/{id}/")
public Employee getInfo(@PathVariable Long id) {
return employeeService.getEmployeeInfoById(id);
}
- @RolesAllowed("ADMIN")
@GetMapping("/employee/info/all/")
public List getEmployees() {
return employeeService.getEmployees();
diff --git a/src/main/java/com/example/nto/controller/AuthController.java b/src/main/java/com/example/nto/controller/AuthController.java
index 807c3cc..8f77183 100644
--- a/src/main/java/com/example/nto/controller/AuthController.java
+++ b/src/main/java/com/example/nto/controller/AuthController.java
@@ -3,7 +3,10 @@ package com.example.nto.controller;
import com.example.nto.entity.Employee;
import com.example.nto.repository.EmployeeRepository;
import lombok.AllArgsConstructor;
+import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
@@ -11,6 +14,7 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@@ -21,15 +25,18 @@ import java.util.List;
@RestController
public class AuthController {
- class RoleResponse {
- private String role;
+ @Autowired
+ private PasswordEncoder passwordEncoder;
- public String getRole() {
- return role;
+ class RoleResponse {
+ private boolean isAdmin;
+
+ public boolean isAdmin() {
+ return isAdmin;
}
- public void setRole(String role) {
- this.role = role;
+ public void setAdmin(boolean admin) {
+ isAdmin = admin;
}
}
@@ -39,6 +46,7 @@ public class AuthController {
@AllArgsConstructor
private static class LoginBody {
private String login;
+ private String password;
public String getLogin() {
return login;
@@ -47,6 +55,14 @@ public class AuthController {
public void setLogin(String login) {
this.login = login;
}
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
}
@@ -57,11 +73,11 @@ public class AuthController {
Эндпоинт авторизации, кинь сюда логин и пароль, и возможно я дам тебе возможность авторизоваться.
*/
@PostMapping("/api/login/")
- private RoleResponse login(HttpServletRequest request, @RequestBody LoginBody loginBody) { //, @RequestParam String login, @RequestParam String password) {
+ private ResponseEntity> login(HttpServletRequest request, @RequestBody LoginBody loginBody) { //, @RequestParam String login, @RequestParam String password) {
Employee employee = employeeRepository.getByLogin(loginBody.login).get();
RoleResponse response = new RoleResponse();
- response.setRole(employee.getRole());
- return response;
+ response.setAdmin(employee.getRole().equals("ADMIN"));
+ return new ResponseEntity<>(response, HttpStatus.OK);
}
}
diff --git a/src/main/java/com/example/nto/controller/EmployeeController.java b/src/main/java/com/example/nto/controller/EmployeeController.java
index d3c3f5d..6cffd09 100644
--- a/src/main/java/com/example/nto/controller/EmployeeController.java
+++ b/src/main/java/com/example/nto/controller/EmployeeController.java
@@ -31,25 +31,26 @@ public class EmployeeController {
this.entryRepository = entryRepository;
}
- /**
- * Эндпоинт для проверки присутствия логина в емплоеееее таблице
- *
- * @return статус код, смотри документацию к тз
- */
- @GetMapping("/api/{login}/auth")
- public ResponseEntity authAttempt(@PathVariable String login) {
- try {
- if (employeeService.checkEmployeeExists(login)) {
- return ResponseEntity.status(HttpStatus.ACCEPTED).build(); // Логин найден ДВЕСТИ
- }
- return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); // Логин не найден 401 неавторизован
-
- } catch (
- Exception e) // Я понял статус "что-то пошло не так", как то, что произошла какая-то ошибка. Вообще по идее должен быть статус 500, но допустим
- {
- return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
- }
- }
+// Был вырезан коллективным решением
+// /**
+// * Эндпоинт для проверки присутствия логина в емплоеееее таблице
+// *
+// * @return статус код, смотри документацию к тз
+// */
+// @GetMapping("/api/{login}/auth")
+// public ResponseEntity authAttempt(@PathVariable String login) {
+// try {
+// if (employeeService.checkEmployeeExists(login)) {
+// return ResponseEntity.status(HttpStatus.OK).build(); // Логин найден ДВЕСТИ
+// }
+// return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); // Логин не найден 401 неавторизован
+//
+// } catch (
+// Exception e) // Я понял статус "что-то пошло не так", как то, что произошла какая-то ошибка. Вообще по идее должен быть статус 500, но допустим
+// {
+// return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
+// }
+// }
/**
* Получить информацию по емплоеееее
@@ -90,7 +91,7 @@ public class EmployeeController {
entry.setTime(LocalDateTime.now());
entry.setPlace(codeRepository.findByValue(value));
entryRepository.save(entry);
- return ResponseEntity.status(HttpStatus.ACCEPTED).build();
+ return ResponseEntity.status(HttpStatus.OK).build();
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
diff --git a/src/main/java/com/example/nto/entity/Entry.java b/src/main/java/com/example/nto/entity/Entry.java
index 6782500..408c2a7 100644
--- a/src/main/java/com/example/nto/entity/Entry.java
+++ b/src/main/java/com/example/nto/entity/Entry.java
@@ -19,7 +19,7 @@ public class Entry {
@JsonIdentityReference(alwaysAsId = true)
private Employee employee;
- private LocalDateTime time;
+ private LocalDateTime time ;
@ManyToOne