diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java index 6594a39..aa7d4f8 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java @@ -40,6 +40,16 @@ public class UserController { return new ResponseEntity<>(ProtectionService.userWithoutPassword(user), HttpStatus.OK); } + + @GetMapping("/user/{id}") + public ResponseEntity> getUserById(@RequestHeader("Authorization") String token, @PathVariable Long id){ + + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + return new UnauthorizedResponse<>(null); + + return new ResponseEntity<>(ProtectionService.userWithoutPassword(userService.getUserById(id)), HttpStatus.OK); + } + @PostMapping("/user") public ResponseEntity> postUser(@RequestBody User user,@RequestHeader("Authorization") String token){ diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java index 8b91b79..cdbb4a2 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java @@ -122,4 +122,9 @@ public class UserService { public Iterable getAllTeachers (){return userRepo.findAllTeachers();} public Iterable getAllStudents(){return userRepo.findAllStudents();} + + + public User getUserById(long id) { + return userRepo.findById(id); + } } diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 35f7f04..9049478 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -12,11 +12,7 @@ window.onhashchange = function() { prevURL = currentURL; currentURL = window.location.hash; } - console.log(location) window.addEventListener('hashchange', () => { - console.log(prevURL) - console.log(location.hash) - console.log(isLogged()) if(location.hash === "#/home" && prevURL === "#/login"){ window.location.reload(); } diff --git a/frontend/src/Apps/ManageCourses.vue b/frontend/src/Apps/ManageCourses.vue index c2be26f..3beb1d9 100644 --- a/frontend/src/Apps/ManageCourses.vue +++ b/frontend/src/Apps/ManageCourses.vue @@ -2,7 +2,7 @@ import i18n from "@/i18n.js" import {ref} from 'vue' import { getCourses,deleteCourse,alterCourse,createCourse } from "@/rest/courses.js" - import {getSelf, getTeachers } from "@/rest/Users.js" + import {getUser, getSelf, getTeachers } from "@/rest/Users.js" const self = await getSelf(); @@ -108,7 +108,7 @@
{{i18n("Teacher")}} :
diff --git a/frontend/src/rest/Users.js b/frontend/src/rest/Users.js index 0636ccd..7f28cba 100644 --- a/frontend/src/rest/Users.js +++ b/frontend/src/rest/Users.js @@ -72,7 +72,7 @@ export async function createUser(firstname, lastname, birthDate, email, address, * if the user is not authenticated. then an empty array should be returned */ export async function getUser(id){ - const endpoint = "/user" + id != null ? "/" + id : ""; + const endpoint = "/user/" + id; return restGet(endpoint); }