From 160cfb0bbf1a07f68a7113b87063287c33a7bb2b Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sat, 9 Mar 2024 18:41:20 +0100 Subject: [PATCH 01/28] Page api stub --- frontend/src/rest/apps.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 frontend/src/rest/apps.js diff --git a/frontend/src/rest/apps.js b/frontend/src/rest/apps.js new file mode 100644 index 0000000..61fb716 --- /dev/null +++ b/frontend/src/rest/apps.js @@ -0,0 +1,9 @@ +import { restGet } from './restConsumer.js' + +export async function appList(){ + return restGet("/apps") +} + +export async function checkPage(page){ + return restGet("/apps/" + page) +} From 4241f1573103b77d432edfcc6f456363377d4570 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Wed, 13 Mar 2024 19:12:46 +0100 Subject: [PATCH 02/28] j'ai envie de me pendre --- .../Clyde/EndPoints/LoginController.java | 23 ++++++++++ .../Repositories/InscriptionRepository.java | 7 ++++ .../Clyde/Services/AuthenticatorService.java | 7 ++++ .../Clyde/Services/InscriptionService.java | 23 ++++++++++ .../ovh/herisson/Clyde/Tables/Cursus.java | 6 +++ .../ovh/herisson/Clyde/Tables/CursusType.java | 8 ++++ .../Clyde/Tables/InscriptionRequest.java | 18 ++++---- .../ovh/herisson/Clyde/Tables/Secretary.java | 42 ------------------- .../ovh/herisson/Clyde/Tables/UserCursus.java | 4 +- 9 files changed, 87 insertions(+), 51 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/InscriptionRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java delete mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Secretary.java diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java index e43f0a1..5c04ebe 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java @@ -1,10 +1,15 @@ package ovh.herisson.Clyde.EndPoints; import com.fasterxml.jackson.annotation.JsonFormat; +import jakarta.persistence.Column; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.AuthenticatorService; +import ovh.herisson.Clyde.Tables.Cursus; +import ovh.herisson.Clyde.Tables.CursusType; +import ovh.herisson.Clyde.Tables.InscriptionRequest; +import ovh.herisson.Clyde.Tables.User; import java.util.Date; @@ -40,6 +45,24 @@ public class LoginController { responseHeaders.set("Set-Cookie",String.format("session_token=%s",sessionToken)); return ResponseEntity.ok().headers(responseHeaders).build(); } + + @PostMapping("/register") + public ResponseEntity register(@RequestBody InscriptionRequest inscriptionRequest){ + + + authServ.register(inscriptionRequest); + + + + String sessionToken = authServ.login(); + if (sessionToken == null){ + return new UnauthorizedResponse<>("Identifier or Password incorrect"); + } + + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.set("Set-Cookie",String.format("session_token=%s",sessionToken)); + return ResponseEntity.ok().headers(responseHeaders).build(); + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/InscriptionRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/InscriptionRepository.java new file mode 100644 index 0000000..9f09b4b --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/InscriptionRepository.java @@ -0,0 +1,7 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.InscriptionRequest; + +public interface InscriptionRepository extends CrudRepository { +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java index 4cd1939..13d0fce 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java @@ -1,6 +1,8 @@ package ovh.herisson.Clyde.Services; import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.EndPoints.LoginController; +import ovh.herisson.Clyde.Tables.InscriptionRequest; import ovh.herisson.Clyde.Tables.Token; import ovh.herisson.Clyde.Tables.User; @@ -30,4 +32,9 @@ public class AuthenticatorService { tokenService.saveToken(new Token(user, token,expirationDate)); return token; } + + public void register(InscriptionRequest inscriptionRequest) { + + + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java new file mode 100644 index 0000000..b0739d1 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java @@ -0,0 +1,23 @@ +package ovh.herisson.Clyde.Services; + +import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.InscriptionRepository; +import ovh.herisson.Clyde.Tables.InscriptionRequest; + +@Service +public class InscriptionService { + + InscriptionRepository incriptionRepo; + public void save(InscriptionRequest inscriptionRequest){ + incriptionRepo.save(inscriptionRequest); + } + + public InscriptionService(InscriptionRepository inscriptionRepo){ + this.incriptionRepo = inscriptionRepo; + } + + //todo return sans le mdp + public InscriptionRequest getById(int id){ + return null; + } +} \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java index 5167197..172ec7d 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java @@ -13,6 +13,12 @@ public class Cursus { private int year; private String option; + public static Cursus infoBab1 = new Cursus(1,"info"); + + public static Cursus chemistryBab1 = new Cursus(1,"chemistry"); + + public static Cursus psychologyBab1 = new Cursus(1,"psychology"); + public Cursus(int year, String option){ this.year = year; this.option = option; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java new file mode 100644 index 0000000..5e9c50f --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java @@ -0,0 +1,8 @@ +package ovh.herisson.Clyde.Tables; + +public enum CursusType { + + infoBab1, + chemistryBab1, + psychologyBab1; +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java index 2e5bf0d..9b6ef95 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java @@ -9,7 +9,7 @@ public class InscriptionRequest { private int id; private String firstName; private String lastName; - private String adress; + private String address; private String email; private String country; private Date birthDate; @@ -19,15 +19,19 @@ public class InscriptionRequest { private Cursus cursus; private RequestState state; private String profilePicture; + + private String password; public InscriptionRequest(){} - public InscriptionRequest(String lastName, String firstName, String adress, String email, String country, Date birthDate, RequestState state, String profilePicture){ + public InscriptionRequest(String lastName, String firstName, String address, String email, String country, Date birthDate, RequestState state, String profilePicture, String password){ this.lastName = lastName; this.firstName = firstName; - this.adress = adress; + this.address = address; this.email = email; this.country = country; this.birthDate = birthDate; this.state = state; + this.profilePicture = profilePicture; + this.password = password; } public int getId() { @@ -50,12 +54,12 @@ public class InscriptionRequest { this.lastName = lastName; } - public String getAdress() { - return adress; + public String getAddress() { + return address; } - public void setAdress(String adress) { - this.adress = adress; + public void setAddress(String address) { + this.address = address; } public String getEmail() { diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Secretary.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Secretary.java deleted file mode 100644 index cc34841..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Secretary.java +++ /dev/null @@ -1,42 +0,0 @@ -package ovh.herisson.Clyde.Tables; - -import jakarta.persistence.*; - -@Entity -public class Secretary { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private int id; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "Users") - private User user; - private String faculty; - - public Secretary(User user, String faculty){ - this.user = user; - this.faculty = faculty; - } - - public Secretary() {} - - public int getId() { - return id; - } - - public User getUser() { - return user; - } - - public void setUser(User user) { - this.user = user; - } - - public String getFaculty() { - return faculty; - } - - public void setFaculty(String faculty) { - this.faculty = faculty; - } -} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java index a5c5153..6590b2d 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java @@ -9,11 +9,11 @@ public class UserCursus { private int id; //Un étudiant peut avoir plusieurs cursus - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "Users") private User user; - @OneToOne(fetch = FetchType.LAZY) + @OneToOne(fetch = FetchType.EAGER) @JoinColumn(name = "Cursus") private Cursus cursus; From 157e5951fca216d0d9a128c9cfcb889a4d7c7b3a Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Wed, 13 Mar 2024 19:14:22 +0100 Subject: [PATCH 03/28] =?UTF-8?q?ups=20je=20change=20un=20copi=C3=A9=20col?= =?UTF-8?q?l=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../herisson/Clyde/EndPoints/LoginController.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java index 5c04ebe..0b96535 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java @@ -2,6 +2,7 @@ package ovh.herisson.Clyde.EndPoints; import com.fasterxml.jackson.annotation.JsonFormat; import jakarta.persistence.Column; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import ovh.herisson.Clyde.Responses.UnauthorizedResponse; @@ -49,19 +50,9 @@ public class LoginController { @PostMapping("/register") public ResponseEntity register(@RequestBody InscriptionRequest inscriptionRequest){ - authServ.register(inscriptionRequest); - - - String sessionToken = authServ.login(); - if (sessionToken == null){ - return new UnauthorizedResponse<>("Identifier or Password incorrect"); - } - - HttpHeaders responseHeaders = new HttpHeaders(); - responseHeaders.set("Set-Cookie",String.format("session_token=%s",sessionToken)); - return ResponseEntity.ok().headers(responseHeaders).build(); + return new ResponseEntity<>("Is OK", HttpStatus.OK); } } From f0a411c03173a2470413a53db000ced81e610c9e Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Thu, 14 Mar 2024 16:36:09 +0100 Subject: [PATCH 04/28] added InscriptionController --- .../EndPoints/InscriptionController.java | 84 +++++++++++++++++++ .../Clyde/EndPoints/LoginController.java | 2 +- .../Repositories/InscriptionRepository.java | 3 + .../Clyde/Services/AuthenticatorService.java | 8 +- .../Clyde/Services/InscriptionService.java | 17 +++- 5 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java new file mode 100644 index 0000000..a997c54 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java @@ -0,0 +1,84 @@ +package ovh.herisson.Clyde.EndPoints; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import ovh.herisson.Clyde.Responses.UnauthorizedResponse; +import ovh.herisson.Clyde.Services.AuthenticatorService; +import ovh.herisson.Clyde.Services.InscriptionService; +import ovh.herisson.Clyde.Tables.InscriptionRequest; +import ovh.herisson.Clyde.Tables.Role; +import ovh.herisson.Clyde.Tables.User; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +@RestController +@CrossOrigin(originPatterns = "*", allowCredentials = "true") + +public class InscriptionController { + + + private final InscriptionService inscriptionServ; + private final AuthenticatorService authServ; + + public InscriptionController(InscriptionService inscriptionServ, AuthenticatorService authServ){ + this.inscriptionServ = inscriptionServ; + this.authServ = authServ; + } + + + @GetMapping("/inscriptionRequests") + public ResponseEntity>> getAllRequests(@RequestHeader("Authorization") String token){ + + if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);} + + Iterable inscriptionRequests = inscriptionServ.getAll(); + ArrayList> toReturn = new ArrayList<>(); + + for (InscriptionRequest i:inscriptionRequests){ + toReturn.add(requestWithoutPassword(i)); + } + + return new ResponseEntity<>(toReturn, HttpStatus.OK); + } + + + @GetMapping("/inscriptionRequest/{id}") + public ResponseEntity> getById(@PathVariable long id){ + + + + InscriptionRequest inscriptionRequest = inscriptionServ.getById(id); + if (inscriptionRequest == null) {return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);} + + return new ResponseEntity<>(requestWithoutPassword(inscriptionRequest), HttpStatus.OK); + } + + + private Map requestWithoutPassword(InscriptionRequest inscriptionRequest) { + Map toReturn = new HashMap<>(); + + toReturn.put("id", inscriptionRequest.getId()); + toReturn.put("firstName", inscriptionRequest.getFirstName()); + toReturn.put("lastName", inscriptionRequest.getLastName()); + toReturn.put("address", inscriptionRequest.getAddress()); + toReturn.put("birthDate", inscriptionRequest.getBirthDate()); + toReturn.put("country", inscriptionRequest.getCountry()); + toReturn.put("cursus", inscriptionRequest.getCursus()); + toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture()); + toReturn.put("state", inscriptionRequest.getState()); + return toReturn; + } + + + private boolean isSecretaryOrAdmin(String authorization){ + if (authorization ==null) + return false; + + User poster = authServ.getUserFromToken(authorization); + if (poster == null) return false; + + return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java index 0b96535..20542b5 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java @@ -13,6 +13,7 @@ import ovh.herisson.Clyde.Tables.InscriptionRequest; import ovh.herisson.Clyde.Tables.User; import java.util.Date; +import java.util.HashMap; @RestController @CrossOrigin(originPatterns = "*", allowCredentials = "true") @@ -51,7 +52,6 @@ public class LoginController { public ResponseEntity register(@RequestBody InscriptionRequest inscriptionRequest){ authServ.register(inscriptionRequest); - return new ResponseEntity<>("Is OK", HttpStatus.OK); } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/InscriptionRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/InscriptionRepository.java index 9f09b4b..0d83e6b 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/InscriptionRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/InscriptionRepository.java @@ -3,5 +3,8 @@ package ovh.herisson.Clyde.Repositories; import org.springframework.data.repository.CrudRepository; import ovh.herisson.Clyde.Tables.InscriptionRequest; + public interface InscriptionRepository extends CrudRepository { + + InscriptionRequest findById(long aLong); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java index 13d0fce..60dc6bc 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java @@ -2,6 +2,7 @@ package ovh.herisson.Clyde.Services; import org.springframework.stereotype.Service; import ovh.herisson.Clyde.EndPoints.LoginController; +import ovh.herisson.Clyde.Repositories.InscriptionRepository; import ovh.herisson.Clyde.Tables.InscriptionRequest; import ovh.herisson.Clyde.Tables.Token; import ovh.herisson.Clyde.Tables.User; @@ -13,10 +14,12 @@ public class AuthenticatorService { private final TokenService tokenService; private final UserService userService; + private final InscriptionService inscriptionService; - public AuthenticatorService(TokenService tokenService, UserService userService){ + public AuthenticatorService(TokenService tokenService, UserService userService, InscriptionService inscriptionService){ this.tokenService = tokenService; this.userService = userService; + this.inscriptionService = inscriptionService; } public User getUserFromToken(String token){ @@ -34,7 +37,6 @@ public class AuthenticatorService { } public void register(InscriptionRequest inscriptionRequest) { - - + inscriptionService.save(inscriptionRequest); } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java index b0739d1..45495b7 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java @@ -4,6 +4,9 @@ import org.springframework.stereotype.Service; import ovh.herisson.Clyde.Repositories.InscriptionRepository; import ovh.herisson.Clyde.Tables.InscriptionRequest; +import java.util.HashMap; +import java.util.Map; + @Service public class InscriptionService { @@ -16,8 +19,16 @@ public class InscriptionService { this.incriptionRepo = inscriptionRepo; } - //todo return sans le mdp - public InscriptionRequest getById(int id){ - return null; + public InscriptionRequest getById(long id){ + InscriptionRequest inscriptionRequest = incriptionRepo.findById(id); + + if (inscriptionRequest == null){ + return null; + } + return inscriptionRequest; + } + + public Iterable getAll(){ + return incriptionRepo.findAll(); } } \ No newline at end of file From 9aa425d1c3be9dfcd04bcf0d87173482c82999ef Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Thu, 14 Mar 2024 20:04:27 +0100 Subject: [PATCH 05/28] changed details --- .../Clyde/Services/InscriptionService.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java index 45495b7..4b2f6f4 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java @@ -4,31 +4,24 @@ import org.springframework.stereotype.Service; import ovh.herisson.Clyde.Repositories.InscriptionRepository; import ovh.herisson.Clyde.Tables.InscriptionRequest; -import java.util.HashMap; -import java.util.Map; - @Service public class InscriptionService { - InscriptionRepository incriptionRepo; - public void save(InscriptionRequest inscriptionRequest){ - incriptionRepo.save(inscriptionRequest); - } + InscriptionRepository inscriptionRepo; public InscriptionService(InscriptionRepository inscriptionRepo){ - this.incriptionRepo = inscriptionRepo; + this.inscriptionRepo = inscriptionRepo; + } + + public void save(InscriptionRequest inscriptionRequest){ + inscriptionRepo.save(inscriptionRequest); } public InscriptionRequest getById(long id){ - InscriptionRequest inscriptionRequest = incriptionRepo.findById(id); - - if (inscriptionRequest == null){ - return null; - } - return inscriptionRequest; + return inscriptionRepo.findById(id); } public Iterable getAll(){ - return incriptionRepo.findAll(); + return inscriptionRepo.findAll(); } } \ No newline at end of file From 12846ed83d4538284e06254d5d5da41d0a2baff0 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Thu, 14 Mar 2024 21:53:43 +0100 Subject: [PATCH 06/28] added cursus/course interactions --- .../Clyde/EndPoints/CursusController.java | 71 +++++++++++++++++++ .../Clyde/EndPoints/LoginController.java | 7 +- .../Clyde/EndPoints/MockController.java | 56 +++++++++++++-- .../Clyde/EndPoints/UserController.java | 2 - .../Clyde/Repositories/CourseRepository.java | 8 +++ .../Repositories/CursusCourseRepository.java | 20 ++++++ .../Clyde/Repositories/CursusRepository.java | 8 +++ .../Clyde/Services/CourseService.java | 23 ++++++ .../Clyde/Services/CursusCourseService.java | 68 ++++++++++++++++++ .../Clyde/Services/CursusService.java | 36 ++++++++++ .../ovh/herisson/Clyde/Tables/Cursus.java | 7 -- .../herisson/Clyde/Tables/CursusCourse.java | 4 +- .../ovh/herisson/Clyde/Tables/CursusType.java | 8 --- .../Clyde/Tables/InscriptionRequest.java | 3 + .../Clyde/Tables/ReinscriptionRequest.java | 9 ++- 15 files changed, 295 insertions(+), 35 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/CursusController.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/CourseRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusCourseRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/CourseService.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/CursusCourseService.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/CursusService.java delete mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CursusController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CursusController.java new file mode 100644 index 0000000..670865f --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CursusController.java @@ -0,0 +1,71 @@ +package ovh.herisson.Clyde.EndPoints; + + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import ovh.herisson.Clyde.Responses.UnauthorizedResponse; +import ovh.herisson.Clyde.Services.AuthenticatorService; +import ovh.herisson.Clyde.Services.CursusCourseService; +import ovh.herisson.Clyde.Services.CursusService; +import ovh.herisson.Clyde.Tables.Cursus; +import ovh.herisson.Clyde.Tables.CursusCourse; +import ovh.herisson.Clyde.Tables.Role; +import ovh.herisson.Clyde.Tables.User; + +import java.util.Map; + +@RestController +public class CursusController { + + + private final CursusService cursusServ; + private final AuthenticatorService authServ; + + private final CursusCourseService cursusCourseServ; + + public CursusController(CursusService cursusServ, AuthenticatorService authServ, CursusCourseService cursusCourseServ){ + this.cursusServ = cursusServ; + this.authServ = authServ; + this.cursusCourseServ = cursusCourseServ; + } + + @GetMapping("/cursus/{id}") + public ResponseEntity findById(@PathVariable long id){ + return new ResponseEntity<>(cursusServ.findById(id), HttpStatus.OK); + } + + @GetMapping("/curriculums") + public ResponseEntity>> findAllindDepth(){ + return new ResponseEntity<>(cursusCourseServ.getAllDepthCursus(),HttpStatus.OK); + } + + @GetMapping("/curriculum") + public ResponseEntity> findAll(){ + return new ResponseEntity<>(cursusCourseServ.findAll(),HttpStatus.OK); + } + + /**@PostMapping("/cursus") + public ResponseEntity postCursus(@RequestHeader("Authorization") String token,@RequestBody Cursus cursus){ + + if (!isSecretaryOrAdmin(token)){ + return new UnauthorizedResponse<>("you're not allowed to post a cursus"); + } + + cursusServ.save(cursus); + + return new ResponseEntity<>("created !",HttpStatus.CREATED); + }**/ + + + + private boolean isSecretaryOrAdmin(String authorization){ + if (authorization ==null) + return false; + + User poster = authServ.getUserFromToken(authorization); + if (poster == null) return false; + + return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java index 20542b5..bc6222e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java @@ -1,19 +1,14 @@ package ovh.herisson.Clyde.EndPoints; import com.fasterxml.jackson.annotation.JsonFormat; -import jakarta.persistence.Column; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.AuthenticatorService; -import ovh.herisson.Clyde.Tables.Cursus; -import ovh.herisson.Clyde.Tables.CursusType; import ovh.herisson.Clyde.Tables.InscriptionRequest; -import ovh.herisson.Clyde.Tables.User; import java.util.Date; -import java.util.HashMap; @RestController @CrossOrigin(originPatterns = "*", allowCredentials = "true") @@ -35,6 +30,7 @@ public class LoginController { public LoginController(AuthenticatorService authServ){ this.authServ = authServ; } + @PostMapping(value = "/login") public ResponseEntity login(@RequestBody RequestLogin requestLogin){ @@ -50,7 +46,6 @@ public class LoginController { @PostMapping("/register") public ResponseEntity register(@RequestBody InscriptionRequest inscriptionRequest){ - authServ.register(inscriptionRequest); return new ResponseEntity<>("Is OK", HttpStatus.OK); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index b140057..5b1306c 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -7,10 +7,8 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; import ovh.herisson.Clyde.Repositories.TokenRepository; import ovh.herisson.Clyde.Repositories.UserRepository; -import ovh.herisson.Clyde.Services.TokenService; -import ovh.herisson.Clyde.Tables.Role; -import ovh.herisson.Clyde.Tables.Token; -import ovh.herisson.Clyde.Tables.User; +import ovh.herisson.Clyde.Services.*; +import ovh.herisson.Clyde.Tables.*; import java.util.ArrayList; import java.util.Arrays; @@ -26,13 +24,22 @@ public class MockController { public final UserRepository userRepo; public final TokenRepository tokenRepo; public final TokenService tokenService; + + public final CursusCourseService cursusCourseService; + + public final CursusService cursusService; + + public final CourseService courseService; ArrayList mockUsers; - public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService){ + public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CursusCourseService cursusCourseService, CursusService cursusService, CourseService courseService){ this.tokenRepo = tokenRepo; this.userRepo = userRepo; this.tokenService = tokenService; + this.cursusCourseService = cursusCourseService; + this.cursusService = cursusService; + this.courseService = courseService; } /** Saves an example of each user type by : @@ -44,6 +51,9 @@ public class MockController { @PostMapping("/mock") public void postMock(){ + // user part + + User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), null,Role.Admin,passwordEncoder.encode("admin")); User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), null,Role.Student,passwordEncoder.encode("student")); User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Teacher,passwordEncoder.encode("secretary")); @@ -52,6 +62,42 @@ public class MockController { mockUsers = new ArrayList(Arrays.asList(herobrine,joe,meh,joke)); userRepo.saveAll(mockUsers); + + + // Course / Curriculum part + + Cursus infoBab1 = new Cursus(1,"info"); + Cursus chemistryBab1 = new Cursus(1,"chemistry"); + Cursus psychologyBab1 = new Cursus(1,"psychology"); + + cursusService.save(infoBab1); + cursusService.save(chemistryBab1); + cursusService.save(psychologyBab1); + + + Course progra1 = new Course(5,"Programmation et algorithimque 1","TODO DELETE"); + Course chemistry1 = new Course(12, "Thermochimie","TODO DELETE"); + Course psycho1 = new Course(21, "rien faire t'as cru c'est psycho", "TODO DELETE"); + Course commun = new Course(2, "cours commun","TODO DELETE"); + + courseService.save(progra1); + courseService.save(chemistry1); + courseService.save(psycho1); + courseService.save(commun); + + + cursusCourseService.save(new CursusCourse(infoBab1,progra1)); + cursusCourseService.save(new CursusCourse(infoBab1,commun)); + + cursusCourseService.save(new CursusCourse(psychologyBab1,psycho1)); + cursusCourseService.save(new CursusCourse(psychologyBab1,commun)); + + + cursusCourseService.save(new CursusCourse(chemistryBab1,commun)); + cursusCourseService.save(new CursusCourse(chemistryBab1,chemistry1)); + + + } @DeleteMapping("/mock") 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 43bcd0c..996905a 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java @@ -41,7 +41,5 @@ public class UserController { public Iterable getAllUsers(){ return userService.getAll(); } - - } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CourseRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CourseRepository.java new file mode 100644 index 0000000..671a995 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CourseRepository.java @@ -0,0 +1,8 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Course; + +public interface CourseRepository extends CrudRepository { + Course findById(long id); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusCourseRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusCourseRepository.java new file mode 100644 index 0000000..b0cba44 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusCourseRepository.java @@ -0,0 +1,20 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Course; +import ovh.herisson.Clyde.Tables.Cursus; +import ovh.herisson.Clyde.Tables.CursusCourse; + +public interface CursusCourseRepository extends CrudRepository { + + + //todo faire custom query pour trouver tous les cours d'un cursus par un cursusId + + @Query("select distinct cc.course from CursusCourse cc where cc.cursus = ?1") + Iterable findCoursesByCursus(Cursus cursus); + + + @Query("select distinct cc.cursus from CursusCourse cc") + Iterable findDistinctCursuses(); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusRepository.java new file mode 100644 index 0000000..0e84688 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusRepository.java @@ -0,0 +1,8 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Cursus; + +public interface CursusRepository extends CrudRepository { + Cursus findById(long id); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/CourseService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/CourseService.java new file mode 100644 index 0000000..368dbb2 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/CourseService.java @@ -0,0 +1,23 @@ +package ovh.herisson.Clyde.Services; + +import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.CourseRepository; +import ovh.herisson.Clyde.Tables.Course; + +@Service +public class CourseService { + + private final CourseRepository courseRepo; + + public CourseService(CourseRepository courseRepo) { + this.courseRepo = courseRepo; + } + + public void save(Course course){ + courseRepo.save(course); + } + + public Course findById(long id){ + return courseRepo.findById(id); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/CursusCourseService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/CursusCourseService.java new file mode 100644 index 0000000..95b31de --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/CursusCourseService.java @@ -0,0 +1,68 @@ +package ovh.herisson.Clyde.Services; + +import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.CourseRepository; +import ovh.herisson.Clyde.Repositories.CursusCourseRepository; +import ovh.herisson.Clyde.Repositories.CursusRepository; +import ovh.herisson.Clyde.Tables.Course; +import ovh.herisson.Clyde.Tables.Cursus; +import ovh.herisson.Clyde.Tables.CursusCourse; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +@Service +public class CursusCourseService { + + private final CursusCourseRepository cursusCourseRepo; + + private final CourseRepository courseRepo; + + private final CursusRepository cursusRepo; + + public CursusCourseService(CursusCourseRepository cursusCourseRepo, CourseRepository courseRepo, CursusRepository cursusRepo) { + this.cursusCourseRepo = cursusCourseRepo; + this.courseRepo = courseRepo; + this.cursusRepo = cursusRepo; + } + + public void save(CursusCourse cursusCourse){ + cursusCourseRepo.save(cursusCourse); + } + + public Iterable findAll(){ + return cursusCourseRepo.findAll(); + } + + + public Map getDepthCursus(Cursus cursus){ + + HashMap toReturn = new HashMap<>(); + ArrayList courses = new ArrayList<>(); + for (Course c: cursusCourseRepo.findCoursesByCursus(cursus)){ + courses.add(c); + } + toReturn.put("courses",courses); + toReturn.put("cursusId",cursus.getCursusId()); + toReturn.put("year",cursus.getYear()); + toReturn.put("option",cursus.getOption()); + + + return toReturn; + } + + public Iterable> getAllDepthCursus(){ + + ArrayList> toReturn = new ArrayList<>(); + + for (Cursus cursus : cursusCourseRepo.findDistinctCursuses()){ + toReturn.add(getDepthCursus(cursus)); + } + return toReturn; + } + + + + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/CursusService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/CursusService.java new file mode 100644 index 0000000..0258ec8 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/CursusService.java @@ -0,0 +1,36 @@ +package ovh.herisson.Clyde.Services; + +import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.CourseRepository; +import ovh.herisson.Clyde.Repositories.CursusRepository; +import ovh.herisson.Clyde.Tables.Cursus; + +import java.util.HashMap; +import java.util.Map; + +@Service +public class CursusService { + + + private final CursusRepository cursusRepo; + + private final CourseRepository courseRepo; + + public CursusService(CursusRepository cursusRepo, CourseRepository courseRepo){ + this.cursusRepo = cursusRepo; + this.courseRepo = courseRepo; + } + + + public void save(Cursus cursus){ + cursusRepo.save(cursus); + } + + public Cursus findById(long id){ + return cursusRepo.findById(id); + } + + public Iterable findAll(){ + return cursusRepo.findAll(); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java index 172ec7d..d124179 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java @@ -12,13 +12,6 @@ public class Cursus { private int cursusId; private int year; private String option; - - public static Cursus infoBab1 = new Cursus(1,"info"); - - public static Cursus chemistryBab1 = new Cursus(1,"chemistry"); - - public static Cursus psychologyBab1 = new Cursus(1,"psychology"); - public Cursus(int year, String option){ this.year = year; this.option = option; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java index ecdd857..111cb78 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java @@ -8,11 +8,11 @@ public class CursusCourse { @GeneratedValue(strategy = GenerationType.AUTO) private int id; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "Cursus") private Cursus cursus; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "Course") private Course course; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java deleted file mode 100644 index 5e9c50f..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java +++ /dev/null @@ -1,8 +0,0 @@ -package ovh.herisson.Clyde.Tables; - -public enum CursusType { - - infoBab1, - chemistryBab1, - psychologyBab1; -} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java index 9b6ef95..aecebe2 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java @@ -4,7 +4,10 @@ import jakarta.persistence.*; import java.util.Date; + +@Entity public class InscriptionRequest { + @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; private String firstName; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java index 8a56f88..9369c80 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java @@ -1,16 +1,15 @@ package ovh.herisson.Clyde.Tables; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; +import jakarta.persistence.*; +@Entity public class ReinscriptionRequest { + @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; @ManyToOne - @JoinColumn(name = "User") + @JoinColumn(name = "Users") private User user; @ManyToOne From 08c662a65f082c0f719c2d4ec5838789616acb3c Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sun, 10 Mar 2024 20:32:23 +0100 Subject: [PATCH 07/28] Fetch inscription on backend This commit is waiting for the backend implementation to be merged. The list of field expected is writen in comment --- frontend/src/Apps/Inscription.vue | 30 ++++--------------------- frontend/src/rest/ServiceInscription.js | 26 ++++++++++++--------- 2 files changed, 20 insertions(+), 36 deletions(-) diff --git a/frontend/src/Apps/Inscription.vue b/frontend/src/Apps/Inscription.vue index 0ba7fce..511a403 100644 --- a/frontend/src/Apps/Inscription.vue +++ b/frontend/src/Apps/Inscription.vue @@ -1,32 +1,10 @@ diff --git a/frontend/src/rest/ServiceInscription.js b/frontend/src/rest/ServiceInscription.js index ee75c3b..7048093 100644 --- a/frontend/src/rest/ServiceInscription.js +++ b/frontend/src/rest/ServiceInscription.js @@ -3,28 +3,34 @@ * * TODO: On time of writing, the backend doesn't support these endpoints so it could be modified in the future. */ -import { restGet } from './restConsumer.js' +import { restGet, restPost } from './restConsumer.js' /** * create a new register requests that can be recovered by the registering service * TODO: add info in the Object (I don't know what will be needed) */ export async function createRegister(){ - return restPost("/requests/register"}); + return restPost("/requests/register"); } /** * list all register request in a list of Objects - */ -export async function getRegisters(){ - return restGet("/requests/register") -} - -/** - * Get info on a particular registering request + * Shall return a list of + * - id + * - type + * - lastName + * - firstName + * - address + * - country + * - birthdate + * - email + * - cursus + * - degree */ export async function getRegisters(id){ - return restGet("/requests/register/" + id); + if(id != null) + return restGet("/requests/register/" + id); + return restGet("/requests/register") } /** From 198ee8a4ce03e46ea878acc16ea972184b22ef0a Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Fri, 15 Mar 2024 14:46:39 +0100 Subject: [PATCH 08/28] Register API and form optimization [depend: backend /register] (#93) Made the register api following the backend refactored the register form for more ergonomy **PS: Waiting for the backend to catch up** Reviewed-on: https://git.herisson.ovh/PGL/Clyde/pulls/93 Reviewed-by: Maxime <231026@umons.ac.be> Reviewed-by: Wal Reviewed-by: LeoMoulin Co-authored-by: Anthony Debucquoy Co-committed-by: Anthony Debucquoy --- frontend/src/Apps/Login.vue | 24 +++++++---------- frontend/src/rest/Users.js | 53 +++++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 17 deletions(-) diff --git a/frontend/src/Apps/Login.vue b/frontend/src/Apps/Login.vue index b7b3242..a5043e8 100644 --- a/frontend/src/Apps/Login.vue +++ b/frontend/src/Apps/Login.vue @@ -7,23 +7,16 @@ const loginPage= ref(true) const page = ref(0) - const emailID=ref("") - const passwordIN=ref("") - - const submitValue= ref(i18n("login.guest.submit")) const surname=ref("") const firstname=ref("") - const passwordOUT=ref("") + const password=ref("") const passwordConfirm=ref("") const birthday=ref("") - const emailOUT=ref("") + const email=ref("") const address=ref("") const country=ref("") const cursus=ref("") - const loginInfos = [{_emailID:emailID},{_passwordIN:passwordIN}] - const registerInfos= [{_surname:surname},{_firstname:firstname},{_birthday:birthday},{_passwordOUT:passwordOUT}, - {_passwordConfirm:passwordConfirm},{_emailOUT:emailOUT},{_address:address},{_country:country},{_cursus:cursus}] const imageSaved = ref(false) const ppData = ref(false) @@ -34,17 +27,17 @@
-
+

{{i18n("login.guest.signin")}}

ID / {{i18n("login.guest.email")}}

- +

{{i18n("login.guest.password")}}

- +
- +

{{i18n("login.guest.welcome")}}

@@ -75,11 +68,12 @@

{{i18n("login.guest.password")}}

- +

{{i18n("login.guest.confirm")}} {{i18n("login.guest.password")}}

+
@@ -93,7 +87,7 @@

{{i18n("login.guest.email")}}

- +

{{i18n("login.guest.address")}}

diff --git a/frontend/src/rest/Users.js b/frontend/src/rest/Users.js index f15dac5..b786f0d 100644 --- a/frontend/src/rest/Users.js +++ b/frontend/src/rest/Users.js @@ -4,8 +4,57 @@ export async function login(user, pass, exp){ return restPost("/login", {identifier: user, password: pass, expirationDate: exp}); } -export async function register(user, pass, mail){ - return restPost("/user", {name: user, password: pass, mail: mail}); +/** + * Register a user (tokenless) + * + * @param firstname + * @param lastname + * @param birthdate + * @param password + * @param mail + * @param address + * @param country + * @param cursus + * @param imageId id of the image in database returned when uploaded + */ +export async function register(firstname, lastname, birthDate, password, email, address, country, cursus, imageId){ + return restPost("/register", { + firstname: firstname, + lastname: lastname, + birthDate: birthDate, + password: password, + email: email, + address: address, + country: country, + cursus: cursus + }); +} + +/** + * Register a user (by secretary) + * + * @param firstname + * @param lastname + * @param birthdate + * @param password + * @param mail + * @param address + * @param country + * @param imageId id of the image in database returned when uploaded + * + * PS: the password is not is not required as it is generated by the backend and sent to the user + * by mail. it's up to the user to change it if he cares about security + */ +export async function createUser(firstname, lastname, birthDate, email, address, country, role, imageId){ + return restPost("/user", { + firstname: firstname, + lastname: lastname, + birthDate: birthDate, + password: password, + email: email, + address: address, + country: country, + }); } /** From 1bff48a4b99c769b6f6a38c974640f3d952b8608 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Fri, 15 Mar 2024 17:09:18 +0100 Subject: [PATCH 09/28] changed the frontend API calls to better suit the backend and logic (register => list and register => single item) --- frontend/src/rest/ServiceInscription.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/rest/ServiceInscription.js b/frontend/src/rest/ServiceInscription.js index ee75c3b..aa90768 100644 --- a/frontend/src/rest/ServiceInscription.js +++ b/frontend/src/rest/ServiceInscription.js @@ -3,14 +3,14 @@ * * TODO: On time of writing, the backend doesn't support these endpoints so it could be modified in the future. */ -import { restGet } from './restConsumer.js' +import {restGet, restPatch} from './restConsumer.js' /** * create a new register requests that can be recovered by the registering service * TODO: add info in the Object (I don't know what will be needed) */ export async function createRegister(){ - return restPost("/requests/register"}); + return restPost("/request/register"}); } /** @@ -24,12 +24,12 @@ export async function getRegisters(){ * Get info on a particular registering request */ export async function getRegisters(id){ - return restGet("/requests/register/" + id); + return restGet("/request/register/" + id); } /** * Change the state of a requests. */ export async function validateRegister(id, state){ - return restPost("/requests/register/" + id, {state: state}); + return restPatch("/request/register/" + id, {state: state}); } From 017235cccfc5164f9d98a5754d97b0e3f5b9a7f3 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Fri, 15 Mar 2024 17:29:45 +0100 Subject: [PATCH 10/28] fixed inscription in the backend --- .../EndPoints/InscriptionController.java | 25 ++++++++++++++----- .../Clyde/EndPoints/LoginController.java | 6 ++--- .../Clyde/Services/InscriptionService.java | 7 ++++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java index a997c54..7757242 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java @@ -7,6 +7,7 @@ import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.AuthenticatorService; import ovh.herisson.Clyde.Services.InscriptionService; import ovh.herisson.Clyde.Tables.InscriptionRequest; +import ovh.herisson.Clyde.Tables.RequestState; import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.User; import java.util.ArrayList; @@ -28,7 +29,7 @@ public class InscriptionController { } - @GetMapping("/inscriptionRequests") + @GetMapping("/requests/register") public ResponseEntity>> getAllRequests(@RequestHeader("Authorization") String token){ if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);} @@ -44,17 +45,29 @@ public class InscriptionController { } - @GetMapping("/inscriptionRequest/{id}") + @GetMapping("/request/register/{id}") public ResponseEntity> getById(@PathVariable long id){ - - - InscriptionRequest inscriptionRequest = inscriptionServ.getById(id); if (inscriptionRequest == null) {return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);} return new ResponseEntity<>(requestWithoutPassword(inscriptionRequest), HttpStatus.OK); } + @GetMapping("request/user/{id}") + public ResponseEntity getUserInscriptionRequest(@PathVariable long id, @RequestHeader("Authorize") String token){ + //todo return l'inscriptionRequest ACTUELLE du user (check si le poster est bien le même que id target ou secretariat) + return null; + } + + @PatchMapping("/request/register/{id}") + public ResponseEntity changeRequestState(@PathVariable long id, + @RequestHeader("Authorize") String token, + @RequestBody RequestState requestState) + { + if (!isSecretaryOrAdmin(token)) return new UnauthorizedResponse<>(null); + inscriptionServ.modifyState(id, requestState); + return null; + } private Map requestWithoutPassword(InscriptionRequest inscriptionRequest) { Map toReturn = new HashMap<>(); @@ -81,4 +94,4 @@ public class InscriptionController { return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin; } -} +} \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java index bc6222e..a47603b 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java @@ -44,11 +44,9 @@ public class LoginController { return ResponseEntity.ok().headers(responseHeaders).build(); } - @PostMapping("/register") + @PostMapping("/request/register") public ResponseEntity register(@RequestBody InscriptionRequest inscriptionRequest){ authServ.register(inscriptionRequest); return new ResponseEntity<>("Is OK", HttpStatus.OK); } -} - - +} \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java index 4b2f6f4..f1bd092 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java @@ -3,6 +3,7 @@ package ovh.herisson.Clyde.Services; import org.springframework.stereotype.Service; import ovh.herisson.Clyde.Repositories.InscriptionRepository; import ovh.herisson.Clyde.Tables.InscriptionRequest; +import ovh.herisson.Clyde.Tables.RequestState; @Service public class InscriptionService { @@ -24,4 +25,10 @@ public class InscriptionService { public Iterable getAll(){ return inscriptionRepo.findAll(); } + + public void modifyState(long id, RequestState requestState) { + InscriptionRequest inscriptionRequest = getById(id); + inscriptionRequest.setState(requestState); + save(inscriptionRequest); + } } \ No newline at end of file From 2ea6ed16bb64b8be0d66ee1a932272739100c13e Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Fri, 15 Mar 2024 18:53:58 +0100 Subject: [PATCH 11/28] removed missclick --- frontend/src/rest/ServiceInscription.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/rest/ServiceInscription.js b/frontend/src/rest/ServiceInscription.js index 8cdd276..5068217 100644 --- a/frontend/src/rest/ServiceInscription.js +++ b/frontend/src/rest/ServiceInscription.js @@ -10,7 +10,7 @@ import {restGet, restPatch} from './restConsumer.js' * TODO: add info in the Object (I don't know what will be needed) */ export async function createRegister(){ - return restPost("/request/register"}); + return restPost("/request/register"); } /** From 1f14890d435bc8bd3d0350616708dab09f777e4f Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Fri, 15 Mar 2024 18:54:53 +0100 Subject: [PATCH 12/28] added ApplicationController and Application enum --- .../EndPoints/ApplicationsController.java | 62 +++++++++++++++++++ .../herisson/Clyde/Tables/Applications.java | 24 +++++++ 2 files changed, 86 insertions(+) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java new file mode 100644 index 0000000..d044bf7 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java @@ -0,0 +1,62 @@ +package ovh.herisson.Clyde.EndPoints; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RestController; +import ovh.herisson.Clyde.Services.AuthenticatorService; +import ovh.herisson.Clyde.Tables.Applications; +import ovh.herisson.Clyde.Tables.Role; + +import java.util.ArrayList; + +@RestController +public class ApplicationsController { + + AuthenticatorService authServ; + + public ApplicationsController(AuthenticatorService authServ){ + this.authServ = authServ; + } + + + /** return a list of authorized applications. + * depends on the token + */ + @GetMapping("/apps") + public ResponseEntity> getAuthorizedApps(@RequestHeader("Authorization") String token){ + + return new ResponseEntity<>(getAuthorizedApplications(token), HttpStatus.OK); + } + + @GetMapping("/apps/{identifier}") + public ResponseEntity getAppAuthorization(@PathVariable Applications identifier, @RequestHeader("Authorization") String token){ + + if (getAuthorizedApplications(token).contains(identifier)){ + return new ResponseEntity<>(true, HttpStatus.OK); + } + return new ResponseEntity<>(false, HttpStatus.OK); + } + + public ArrayList getAuthorizedApplications(String token){ + Role posterRole = authServ.getUserFromToken(token).getRole(); + ArrayList authorizedApps = new ArrayList<>(); + + authorizedApps.add(Applications.LOGIN); + authorizedApps.add(Applications.PROFILE); + authorizedApps.add(Applications.MSG); + authorizedApps.add(Applications.FORUM); + authorizedApps.add(Applications.RDV); + + if (posterRole == Role.Student || posterRole == Role.Admin) return authorizedApps; + + if (posterRole == Role.Teacher || posterRole == Role.Secretary || posterRole == Role.Admin) authorizedApps.add(Applications.MANAGECOURSES); + + if (posterRole == Role.InscriptionService || posterRole == Role.Admin) authorizedApps.add(Applications.INSCRIPTION); + + return authorizedApps; + } + +} \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java new file mode 100644 index 0000000..445a928 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java @@ -0,0 +1,24 @@ +package ovh.herisson.Clyde.Tables; + +public enum Applications { + // without any token + LOGIN, + + // with any token + PROFILE, + + + // Students and higher authorization + MSG, + FORUM, + RDV, + + // teachers and Secretary authorization + MANAGECOURSES, + + // InscriptionService authorization + INSCRIPTION; + + + +} From e2da7271af3554fe090464dadea730d633833f1e Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Fri, 15 Mar 2024 23:53:15 +0100 Subject: [PATCH 13/28] rename Cursus -> Curriculum --- .../Clyde/EndPoints/CurriculumController.java | 70 ++++++++++++++++++ .../Clyde/EndPoints/CursusController.java | 71 ------------------- .../EndPoints/InscriptionController.java | 4 +- .../Clyde/EndPoints/MockController.java | 36 +++++----- .../CurriculumCourseRepository.java | 17 +++++ .../Repositories/CurriculumRepository.java | 8 +++ .../Repositories/CursusCourseRepository.java | 20 ------ .../Clyde/Repositories/CursusRepository.java | 8 --- .../Services/CurriculumCourseService.java | 68 ++++++++++++++++++ .../Clyde/Services/CurriculumService.java | 32 +++++++++ .../Clyde/Services/CursusCourseService.java | 68 ------------------ .../Clyde/Services/CursusService.java | 36 ---------- .../Tables/{Cursus.java => Curriculum.java} | 12 ++-- ...ursusCourse.java => CurriculumCourse.java} | 20 +++--- .../Clyde/Tables/InscriptionRequest.java | 12 ++-- .../Clyde/Tables/ReinscriptionRequest.java | 22 +++--- .../{UserCursus.java => UserCurriculum.java} | 22 +++--- 17 files changed, 259 insertions(+), 267 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/CurriculumController.java delete mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/CursusController.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumCourseRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumRepository.java delete mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusCourseRepository.java delete mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumCourseService.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumService.java delete mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/CursusCourseService.java delete mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/CursusService.java rename backend/src/main/java/ovh/herisson/Clyde/Tables/{Cursus.java => Curriculum.java} (76%) rename backend/src/main/java/ovh/herisson/Clyde/Tables/{CursusCourse.java => CurriculumCourse.java} (57%) rename backend/src/main/java/ovh/herisson/Clyde/Tables/{UserCursus.java => UserCurriculum.java} (53%) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CurriculumController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CurriculumController.java new file mode 100644 index 0000000..bc83924 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CurriculumController.java @@ -0,0 +1,70 @@ +package ovh.herisson.Clyde.EndPoints; + + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import ovh.herisson.Clyde.Services.AuthenticatorService; +import ovh.herisson.Clyde.Services.CurriculumCourseService; +import ovh.herisson.Clyde.Services.CurriculumService; +import ovh.herisson.Clyde.Tables.Curriculum; +import ovh.herisson.Clyde.Tables.CurriculumCourse; +import ovh.herisson.Clyde.Tables.Role; +import ovh.herisson.Clyde.Tables.User; + +import java.util.Map; + +@RestController +public class CurriculumController { + + + private final CurriculumService curriculumServ; + private final AuthenticatorService authServ; + + private final CurriculumCourseService curriculumCourseServ; + + public CurriculumController(CurriculumService curriculumServ, AuthenticatorService authServ, CurriculumCourseService curriculumCourseServ){ + this.curriculumServ = curriculumServ; + this.authServ = authServ; + this.curriculumCourseServ = curriculumCourseServ; + } + + @GetMapping("/curriculum/{id}") + public ResponseEntity findById(@PathVariable long id){ + return new ResponseEntity<>(curriculumServ.findById(id), HttpStatus.OK); + } + + @GetMapping("/curriculums") + public ResponseEntity>> findAllindDepth(){ + return new ResponseEntity<>(curriculumCourseServ.getAllDepthCurriculum(),HttpStatus.OK); + } + + @GetMapping("/curriculum") + public ResponseEntity> findAll(){ + return new ResponseEntity<>(curriculumCourseServ.findAll(),HttpStatus.OK); + } + + /**@PostMapping("/curriculum") + public ResponseEntity postCurriculum(@RequestHeader("Authorization") String token,@RequestBody Curriculum curriculum){ + + if (!isSecretaryOrAdmin(token)){ + return new UnauthorizedResponse<>("you're not allowed to post a Curriculum"); + } + + CurriculumServ.save(Curriculum); + + return new ResponseEntity<>("created !",HttpStatus.CREATED); + }**/ + + + + private boolean isSecretaryOrAdmin(String authorization){ + if (authorization ==null) + return false; + + User poster = authServ.getUserFromToken(authorization); + if (poster == null) return false; + + return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CursusController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CursusController.java deleted file mode 100644 index 670865f..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CursusController.java +++ /dev/null @@ -1,71 +0,0 @@ -package ovh.herisson.Clyde.EndPoints; - - -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -import ovh.herisson.Clyde.Responses.UnauthorizedResponse; -import ovh.herisson.Clyde.Services.AuthenticatorService; -import ovh.herisson.Clyde.Services.CursusCourseService; -import ovh.herisson.Clyde.Services.CursusService; -import ovh.herisson.Clyde.Tables.Cursus; -import ovh.herisson.Clyde.Tables.CursusCourse; -import ovh.herisson.Clyde.Tables.Role; -import ovh.herisson.Clyde.Tables.User; - -import java.util.Map; - -@RestController -public class CursusController { - - - private final CursusService cursusServ; - private final AuthenticatorService authServ; - - private final CursusCourseService cursusCourseServ; - - public CursusController(CursusService cursusServ, AuthenticatorService authServ, CursusCourseService cursusCourseServ){ - this.cursusServ = cursusServ; - this.authServ = authServ; - this.cursusCourseServ = cursusCourseServ; - } - - @GetMapping("/cursus/{id}") - public ResponseEntity findById(@PathVariable long id){ - return new ResponseEntity<>(cursusServ.findById(id), HttpStatus.OK); - } - - @GetMapping("/curriculums") - public ResponseEntity>> findAllindDepth(){ - return new ResponseEntity<>(cursusCourseServ.getAllDepthCursus(),HttpStatus.OK); - } - - @GetMapping("/curriculum") - public ResponseEntity> findAll(){ - return new ResponseEntity<>(cursusCourseServ.findAll(),HttpStatus.OK); - } - - /**@PostMapping("/cursus") - public ResponseEntity postCursus(@RequestHeader("Authorization") String token,@RequestBody Cursus cursus){ - - if (!isSecretaryOrAdmin(token)){ - return new UnauthorizedResponse<>("you're not allowed to post a cursus"); - } - - cursusServ.save(cursus); - - return new ResponseEntity<>("created !",HttpStatus.CREATED); - }**/ - - - - private boolean isSecretaryOrAdmin(String authorization){ - if (authorization ==null) - return false; - - User poster = authServ.getUserFromToken(authorization); - if (poster == null) return false; - - return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin; - } -} diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java index 7757242..3347c8e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java @@ -69,7 +69,7 @@ public class InscriptionController { return null; } - private Map requestWithoutPassword(InscriptionRequest inscriptionRequest) { + private Map requestWithoutPassword(InscriptionRequest inscriptionRequest) { Map toReturn = new HashMap<>(); toReturn.put("id", inscriptionRequest.getId()); @@ -78,7 +78,7 @@ public class InscriptionController { toReturn.put("address", inscriptionRequest.getAddress()); toReturn.put("birthDate", inscriptionRequest.getBirthDate()); toReturn.put("country", inscriptionRequest.getCountry()); - toReturn.put("cursus", inscriptionRequest.getCursus()); + toReturn.put("curriculum", inscriptionRequest.getCurriculum()); toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture()); toReturn.put("state", inscriptionRequest.getState()); return toReturn; diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index e254b8c..af837bf 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -20,18 +20,18 @@ public class MockController { public final UserRepository userRepo; public final TokenRepository tokenRepo; public final TokenService tokenService; - public final CursusCourseService cursusCourseService; - public final CursusService cursusService; + public final CurriculumCourseService CurriculumCourseService; + public final CurriculumService curriculumService; public final CourseService courseService; ArrayList mockUsers; - public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CursusCourseService cursusCourseService, CursusService cursusService, CourseService courseService){ + public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService){ this.tokenRepo = tokenRepo; this.userRepo = userRepo; this.tokenService = tokenService; - this.cursusCourseService = cursusCourseService; - this.cursusService = cursusService; + this.CurriculumCourseService = CurriculumCourseService; + this.curriculumService = curriculumService; this.courseService = courseService; } @@ -51,20 +51,20 @@ public class MockController { User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), null,Role.Student,passwordEncoder.encode("student")); User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Teacher,passwordEncoder.encode("secretary")); User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), null,Role.Teacher,passwordEncoder.encode("teacher")); - mockUsers = new ArrayList(Arrays.asList(herobrine,joe,meh,joke)); + mockUsers = new ArrayList<>(Arrays.asList(herobrine,joe,meh,joke)); userRepo.saveAll(mockUsers); // Course / Curriculum part - Cursus infoBab1 = new Cursus(1,"info"); - Cursus chemistryBab1 = new Cursus(1,"chemistry"); - Cursus psychologyBab1 = new Cursus(1,"psychology"); + Curriculum infoBab1 = new Curriculum(1,"info"); + Curriculum chemistryBab1 = new Curriculum(1,"chemistry"); + Curriculum psychologyBab1 = new Curriculum(1,"psychology"); - cursusService.save(infoBab1); - cursusService.save(chemistryBab1); - cursusService.save(psychologyBab1); + curriculumService.save(infoBab1); + curriculumService.save(chemistryBab1); + curriculumService.save(psychologyBab1); Course progra1 = new Course(5,"Programmation et algorithimque 1","TODO DELETE"); @@ -78,15 +78,15 @@ public class MockController { courseService.save(commun); - cursusCourseService.save(new CursusCourse(infoBab1,progra1)); - cursusCourseService.save(new CursusCourse(infoBab1,commun)); + CurriculumCourseService.save(new CurriculumCourse(infoBab1,progra1)); + CurriculumCourseService.save(new CurriculumCourse(infoBab1,commun)); - cursusCourseService.save(new CursusCourse(psychologyBab1,psycho1)); - cursusCourseService.save(new CursusCourse(psychologyBab1,commun)); + CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,psycho1)); + CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,commun)); - cursusCourseService.save(new CursusCourse(chemistryBab1,commun)); - cursusCourseService.save(new CursusCourse(chemistryBab1,chemistry1)); + CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,commun)); + CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,chemistry1)); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumCourseRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumCourseRepository.java new file mode 100644 index 0000000..c99f50b --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumCourseRepository.java @@ -0,0 +1,17 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Course; +import ovh.herisson.Clyde.Tables.Curriculum; +import ovh.herisson.Clyde.Tables.CurriculumCourse; + +public interface CurriculumCourseRepository extends CrudRepository { + + @Query("select distinct cc.course from CurriculumCourse cc where cc.curriculum = ?1") + Iterable findCoursesByCurriculum(Curriculum curriculum); + + + @Query("select distinct cc.curriculum from CurriculumCourse cc") + Iterable findDistinctCurriculums(); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumRepository.java new file mode 100644 index 0000000..441422f --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CurriculumRepository.java @@ -0,0 +1,8 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Curriculum; + +public interface CurriculumRepository extends CrudRepository { + Curriculum findById(long id); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusCourseRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusCourseRepository.java deleted file mode 100644 index b0cba44..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusCourseRepository.java +++ /dev/null @@ -1,20 +0,0 @@ -package ovh.herisson.Clyde.Repositories; - -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; -import ovh.herisson.Clyde.Tables.Course; -import ovh.herisson.Clyde.Tables.Cursus; -import ovh.herisson.Clyde.Tables.CursusCourse; - -public interface CursusCourseRepository extends CrudRepository { - - - //todo faire custom query pour trouver tous les cours d'un cursus par un cursusId - - @Query("select distinct cc.course from CursusCourse cc where cc.cursus = ?1") - Iterable findCoursesByCursus(Cursus cursus); - - - @Query("select distinct cc.cursus from CursusCourse cc") - Iterable findDistinctCursuses(); -} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusRepository.java deleted file mode 100644 index 0e84688..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/CursusRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package ovh.herisson.Clyde.Repositories; - -import org.springframework.data.repository.CrudRepository; -import ovh.herisson.Clyde.Tables.Cursus; - -public interface CursusRepository extends CrudRepository { - Cursus findById(long id); -} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumCourseService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumCourseService.java new file mode 100644 index 0000000..ccf1226 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumCourseService.java @@ -0,0 +1,68 @@ +package ovh.herisson.Clyde.Services; + +import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.CourseRepository; +import ovh.herisson.Clyde.Repositories.CurriculumCourseRepository; +import ovh.herisson.Clyde.Repositories.CurriculumRepository; +import ovh.herisson.Clyde.Tables.Course; +import ovh.herisson.Clyde.Tables.Curriculum; +import ovh.herisson.Clyde.Tables.CurriculumCourse; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +@Service +public class CurriculumCourseService { + + private final CurriculumCourseRepository curriculumCourseRepo; + + private final CourseRepository courseRepo; + + private final CurriculumRepository curriculumRepo; + + public CurriculumCourseService(CurriculumCourseRepository curriculumCourseRepository, CourseRepository courseRepo, CurriculumRepository curriculumRepo) { + this.curriculumCourseRepo = curriculumCourseRepository; + this.courseRepo = courseRepo; + this.curriculumRepo = curriculumRepo; + } + + public void save(CurriculumCourse curriculumCourse){ + curriculumCourseRepo.save(curriculumCourse); + } + + public Iterable findAll(){ + return curriculumCourseRepo.findAll(); + } + + + public Map getDepthCurriculum(Curriculum curriculum){ + + HashMap toReturn = new HashMap<>(); + ArrayList courses = new ArrayList<>(); + for (Course c: curriculumCourseRepo.findCoursesByCurriculum(curriculum)){ + courses.add(c); + } + toReturn.put("courses",courses); + toReturn.put("curriculumId", curriculum.getCurriculumId()); + toReturn.put("year", curriculum.getYear()); + toReturn.put("option", curriculum.getOption()); + + + return toReturn; + } + + public Iterable> getAllDepthCurriculum(){ + + ArrayList> toReturn = new ArrayList<>(); + + for (Curriculum curriculum : curriculumCourseRepo.findDistinctCurriculums()){ + toReturn.add(getDepthCurriculum(curriculum)); + } + return toReturn; + } + + + + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumService.java new file mode 100644 index 0000000..6f6d89b --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/CurriculumService.java @@ -0,0 +1,32 @@ +package ovh.herisson.Clyde.Services; + +import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Repositories.CourseRepository; +import ovh.herisson.Clyde.Repositories.CurriculumRepository; +import ovh.herisson.Clyde.Tables.Curriculum; + +@Service +public class CurriculumService { + + private final CurriculumRepository curriculumRepo; + + private final CourseRepository courseRepo; + + public CurriculumService(CurriculumRepository curriculumRepo, CourseRepository courseRepo){ + this.curriculumRepo = curriculumRepo; + this.courseRepo = courseRepo; + } + + + public void save(Curriculum curriculum){ + curriculumRepo.save(curriculum); + } + + public Curriculum findById(long id){ + return curriculumRepo.findById(id); + } + + public Iterable findAll(){ + return curriculumRepo.findAll(); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/CursusCourseService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/CursusCourseService.java deleted file mode 100644 index 95b31de..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/CursusCourseService.java +++ /dev/null @@ -1,68 +0,0 @@ -package ovh.herisson.Clyde.Services; - -import org.springframework.stereotype.Service; -import ovh.herisson.Clyde.Repositories.CourseRepository; -import ovh.herisson.Clyde.Repositories.CursusCourseRepository; -import ovh.herisson.Clyde.Repositories.CursusRepository; -import ovh.herisson.Clyde.Tables.Course; -import ovh.herisson.Clyde.Tables.Cursus; -import ovh.herisson.Clyde.Tables.CursusCourse; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -@Service -public class CursusCourseService { - - private final CursusCourseRepository cursusCourseRepo; - - private final CourseRepository courseRepo; - - private final CursusRepository cursusRepo; - - public CursusCourseService(CursusCourseRepository cursusCourseRepo, CourseRepository courseRepo, CursusRepository cursusRepo) { - this.cursusCourseRepo = cursusCourseRepo; - this.courseRepo = courseRepo; - this.cursusRepo = cursusRepo; - } - - public void save(CursusCourse cursusCourse){ - cursusCourseRepo.save(cursusCourse); - } - - public Iterable findAll(){ - return cursusCourseRepo.findAll(); - } - - - public Map getDepthCursus(Cursus cursus){ - - HashMap toReturn = new HashMap<>(); - ArrayList courses = new ArrayList<>(); - for (Course c: cursusCourseRepo.findCoursesByCursus(cursus)){ - courses.add(c); - } - toReturn.put("courses",courses); - toReturn.put("cursusId",cursus.getCursusId()); - toReturn.put("year",cursus.getYear()); - toReturn.put("option",cursus.getOption()); - - - return toReturn; - } - - public Iterable> getAllDepthCursus(){ - - ArrayList> toReturn = new ArrayList<>(); - - for (Cursus cursus : cursusCourseRepo.findDistinctCursuses()){ - toReturn.add(getDepthCursus(cursus)); - } - return toReturn; - } - - - - -} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/CursusService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/CursusService.java deleted file mode 100644 index 0258ec8..0000000 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/CursusService.java +++ /dev/null @@ -1,36 +0,0 @@ -package ovh.herisson.Clyde.Services; - -import org.springframework.stereotype.Service; -import ovh.herisson.Clyde.Repositories.CourseRepository; -import ovh.herisson.Clyde.Repositories.CursusRepository; -import ovh.herisson.Clyde.Tables.Cursus; - -import java.util.HashMap; -import java.util.Map; - -@Service -public class CursusService { - - - private final CursusRepository cursusRepo; - - private final CourseRepository courseRepo; - - public CursusService(CursusRepository cursusRepo, CourseRepository courseRepo){ - this.cursusRepo = cursusRepo; - this.courseRepo = courseRepo; - } - - - public void save(Cursus cursus){ - cursusRepo.save(cursus); - } - - public Cursus findById(long id){ - return cursusRepo.findById(id); - } - - public Iterable findAll(){ - return cursusRepo.findAll(); - } -} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Curriculum.java similarity index 76% rename from backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java rename to backend/src/main/java/ovh/herisson/Clyde/Tables/Curriculum.java index d124179..67075d1 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Curriculum.java @@ -6,21 +6,21 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @Entity -public class Cursus { +public class Curriculum { @Id @GeneratedValue(strategy = GenerationType.AUTO) - private int cursusId; + private int curriculumId; private int year; private String option; - public Cursus(int year, String option){ + public Curriculum(int year, String option){ this.year = year; this.option = option; } - public Cursus() {} + public Curriculum() {} - public int getCursusId(){ - return this.cursusId; + public int getCurriculumId(){ + return this.curriculumId; } public int getYear(){ diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/CurriculumCourse.java similarity index 57% rename from backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java rename to backend/src/main/java/ovh/herisson/Clyde/Tables/CurriculumCourse.java index 111cb78..8202e8d 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/CurriculumCourse.java @@ -3,25 +3,25 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; @Entity -public class CursusCourse { +public class CurriculumCourse { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "Cursus") - private Cursus cursus; + @JoinColumn(name = "Curriculum") + private Curriculum curriculum; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "Course") private Course course; - public CursusCourse(Cursus cursus, Course course){ - this.cursus = cursus; + public CurriculumCourse(Curriculum curriculum, Course course){ + this.curriculum = curriculum; this.course = course; } - public CursusCourse() {} + public CurriculumCourse() {} public int getId() { return id; @@ -35,11 +35,11 @@ public class CursusCourse { this.course = course; } - public Cursus getCursus() { - return cursus; + public Curriculum getCurriculum() { + return curriculum; } - public void setCursus(Cursus cursus) { - this.cursus = cursus; + public void setCurriculum(Curriculum curriculum) { + this.curriculum = curriculum; } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java index aecebe2..dfbf7ed 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java @@ -18,8 +18,8 @@ public class InscriptionRequest { private Date birthDate; @ManyToOne - @JoinColumn(name="Cursus") - private Cursus cursus; + @JoinColumn(name="Curriculum") + private Curriculum curriculum; private RequestState state; private String profilePicture; @@ -89,12 +89,12 @@ public class InscriptionRequest { this.birthDate = birthDate; } - public Cursus getCursus() { - return cursus; + public Curriculum getCurriculum() { + return curriculum; } - public void setCursus(Cursus cursus) { - this.cursus = cursus; + public void setCurriculum(Curriculum curriculum) { + this.curriculum = curriculum; } public RequestState getState() { diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java index 69c80e6..57ad53c 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java @@ -13,26 +13,26 @@ public class ReinscriptionRequest { private User user; @ManyToOne - @JoinColumn(name = "Cursus") - private Cursus newCursus; + @JoinColumn(name = "Curriculum") + private Curriculum newCurriculum; private RequestState state; - //Permet de différencier les demandes de changement et une réinscription dans le même cursus + //Permet de différencier les demandes de changement et une réinscription dans le même Curriculum //Pour la réinscription on va le mettre a 0 private boolean type = false; public ReinscriptionRequest(){} - public ReinscriptionRequest(User user, Cursus newCursus, RequestState state, boolean type){ + public ReinscriptionRequest(User user, Curriculum newCurriculum, RequestState state, boolean type){ this.user = user; - this.newCursus = newCursus; + this.newCurriculum = newCurriculum; this.state = state; this.type = type; } - public ReinscriptionRequest(User user, Cursus newCursus, RequestState state){ + public ReinscriptionRequest(User user, Curriculum newCurriculum, RequestState state){ this.user = user; - this.newCursus = newCursus; + this.newCurriculum = newCurriculum; this.state = state; } @@ -48,12 +48,12 @@ public class ReinscriptionRequest { this.user = user; } - public Cursus getNewCursus() { - return newCursus; + public Curriculum getNewCurriculum() { + return newCurriculum; } - public void setNewCursus(Cursus newCursus) { - this.newCursus = newCursus; + public void setNewCurriculum(Curriculum newCurriculum) { + this.newCurriculum = newCurriculum; } public RequestState getState() { diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java similarity index 53% rename from backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java rename to backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java index 6590b2d..2202763 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java @@ -3,26 +3,26 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; @Entity -public class UserCursus { +public class UserCurriculum { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; - //Un étudiant peut avoir plusieurs cursus + //Un étudiant peut avoir plusieurs curriculums @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "Users") private User user; @OneToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "Cursus") - private Cursus cursus; + @JoinColumn(name = "Curriculum") + private Curriculum curriculum; - public UserCursus(User user, Cursus cursus){ + public UserCurriculum(User user, Curriculum curriculum){ this.user = user; - this.cursus = cursus; + this.curriculum = curriculum; } - public UserCursus() {} + public UserCurriculum() {} public int getId() { return id; @@ -36,11 +36,11 @@ public class UserCursus { this.user = user; } - public Cursus getCursus() { - return cursus; + public Curriculum getCurriculum() { + return curriculum; } - public void setCursus(Cursus cursus) { - this.cursus = cursus; + public void setCurriculum(Curriculum curriculum) { + this.curriculum = curriculum; } } From 208c6c63e841daf5d2ff49f09dc1dbaa24c25163 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Sat, 16 Mar 2024 00:31:03 +0100 Subject: [PATCH 14/28] moved the isSecretaryOrAdmin method --- .../Clyde/EndPoints/InscriptionController.java | 15 ++------------- .../herisson/Clyde/EndPoints/UserController.java | 16 ++-------------- .../Clyde/Services/AuthenticatorService.java | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java index a997c54..67ca1ee 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java @@ -31,7 +31,7 @@ public class InscriptionController { @GetMapping("/inscriptionRequests") public ResponseEntity>> getAllRequests(@RequestHeader("Authorization") String token){ - if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);} + if (authServ.isNotSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);} Iterable inscriptionRequests = inscriptionServ.getAll(); ArrayList> toReturn = new ArrayList<>(); @@ -70,15 +70,4 @@ public class InscriptionController { toReturn.put("state", inscriptionRequest.getState()); return toReturn; } - - - private boolean isSecretaryOrAdmin(String authorization){ - if (authorization ==null) - return false; - - User poster = authServ.getUserFromToken(authorization); - if (poster == null) return false; - - return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin; - } -} +} \ No newline at end of file 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 844e82e..d797284 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java @@ -43,7 +43,7 @@ public class UserController { @PostMapping("/user") public ResponseEntity postUser(@RequestBody User user,@RequestHeader("Authorization") String authorization){ - if (!isSecretaryOrAdmin(authorization)) + if (authServ.isNotSecretaryOrAdmin(authorization)) return new UnauthorizedResponse<>(null); userService.save(user); @@ -53,7 +53,7 @@ public class UserController { @GetMapping("/users") public ResponseEntity>> getAllUsers(@RequestHeader("Authorization") String authorization){ - if (!isSecretaryOrAdmin(authorization)) + if (authServ.isNotSecretaryOrAdmin(authorization)) return new UnauthorizedResponse<>(null); Iterable users = userService.getAll(); @@ -85,7 +85,6 @@ public class UserController { */ private HashMap userWithoutPassword(User user){ HashMap toReturn = new HashMap<>(); - toReturn.put("regNo",user.getRegNo()); toReturn.put("firstName",user.getFirstName()); toReturn.put("lastName",user.getLastName()); @@ -93,18 +92,7 @@ public class UserController { toReturn.put("country",user.getCountry()); toReturn.put("address",user.getAddress()); toReturn.put("role",user.getRole()); - return toReturn; } - - private boolean isSecretaryOrAdmin(String authorization){ - if (authorization ==null) - return false; - - User poster = authServ.getUserFromToken(authorization); - if (poster == null) return false; - - return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin; - } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java index 60dc6bc..1cc18e1 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java @@ -4,6 +4,7 @@ import org.springframework.stereotype.Service; import ovh.herisson.Clyde.EndPoints.LoginController; import ovh.herisson.Clyde.Repositories.InscriptionRepository; import ovh.herisson.Clyde.Tables.InscriptionRequest; +import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.Token; import ovh.herisson.Clyde.Tables.User; @@ -39,4 +40,17 @@ public class AuthenticatorService { public void register(InscriptionRequest inscriptionRequest) { inscriptionService.save(inscriptionRequest); } + + + public boolean isNotSecretaryOrAdmin(String authorization){ + if (authorization ==null) + return true; + + User poster = getUserFromToken(authorization); + if (poster == null) return true; + + return poster.getRole() != Role.Secretary || poster.getRole() != Role.Admin; + } + } + From 25009ba149938c74594d53088e7c52ea5ad0fd16 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Sat, 16 Mar 2024 00:34:20 +0100 Subject: [PATCH 15/28] Enum in CamelCase --- .../Clyde/EndPoints/ApplicationsController.java | 14 +++++++------- .../ovh/herisson/Clyde/Tables/Applications.java | 17 +++++++---------- .../ovh/herisson/Clyde/Tables/CursusType.java | 6 +++--- .../ovh/herisson/Clyde/Tables/RequestState.java | 2 +- .../java/ovh/herisson/Clyde/Tables/Role.java | 4 ++-- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java index d044bf7..9bd32c1 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java @@ -44,17 +44,17 @@ public class ApplicationsController { Role posterRole = authServ.getUserFromToken(token).getRole(); ArrayList authorizedApps = new ArrayList<>(); - authorizedApps.add(Applications.LOGIN); - authorizedApps.add(Applications.PROFILE); - authorizedApps.add(Applications.MSG); - authorizedApps.add(Applications.FORUM); - authorizedApps.add(Applications.RDV); + authorizedApps.add(Applications.Login); + authorizedApps.add(Applications.Profile); + authorizedApps.add(Applications.Msg); + authorizedApps.add(Applications.Forum); + authorizedApps.add(Applications.Rdv); if (posterRole == Role.Student || posterRole == Role.Admin) return authorizedApps; - if (posterRole == Role.Teacher || posterRole == Role.Secretary || posterRole == Role.Admin) authorizedApps.add(Applications.MANAGECOURSES); + if (posterRole == Role.Teacher || posterRole == Role.Secretary || posterRole == Role.Admin) authorizedApps.add(Applications.ManageCourses); - if (posterRole == Role.InscriptionService || posterRole == Role.Admin) authorizedApps.add(Applications.INSCRIPTION); + if (posterRole == Role.InscriptionService || posterRole == Role.Admin) authorizedApps.add(Applications.Inscription); return authorizedApps; } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java index 445a928..6ad6567 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java @@ -2,23 +2,20 @@ package ovh.herisson.Clyde.Tables; public enum Applications { // without any token - LOGIN, + Login, // with any token - PROFILE, + Profile, // Students and higher authorization - MSG, - FORUM, - RDV, + Msg, + Forum, + Rdv, // teachers and Secretary authorization - MANAGECOURSES, + ManageCourses, // InscriptionService authorization - INSCRIPTION; - - - + Inscription } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java index 5e9c50f..d99d47e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusType.java @@ -2,7 +2,7 @@ package ovh.herisson.Clyde.Tables; public enum CursusType { - infoBab1, - chemistryBab1, - psychologyBab1; + InfoBab1, + ChemistryBab1, + PsychologyBab1 } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/RequestState.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/RequestState.java index f0345c1..d52f1c9 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/RequestState.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/RequestState.java @@ -3,5 +3,5 @@ package ovh.herisson.Clyde.Tables; public enum RequestState { Accepted, Refused, - Pending; + Pending } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java index 4e4469b..f6f8967 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java @@ -5,5 +5,5 @@ public enum Role { Student, Admin, InscriptionService, - Secretary; -} + Secretary +} \ No newline at end of file From 0860567e1b9d0ccbb85cb7c05bcad3359e0df04a Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Sat, 16 Mar 2024 00:42:46 +0100 Subject: [PATCH 16/28] fixed the GetAuthorizedApps method --- .../Clyde/EndPoints/ApplicationsController.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java index d044bf7..d5ad171 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java @@ -46,11 +46,12 @@ public class ApplicationsController { authorizedApps.add(Applications.LOGIN); authorizedApps.add(Applications.PROFILE); - authorizedApps.add(Applications.MSG); - authorizedApps.add(Applications.FORUM); - authorizedApps.add(Applications.RDV); - if (posterRole == Role.Student || posterRole == Role.Admin) return authorizedApps; + if (posterRole == Role.Teacher || posterRole == Role.Student || posterRole == Role.Admin){ + authorizedApps.add(Applications.MSG); + authorizedApps.add(Applications.FORUM); + authorizedApps.add(Applications.RDV); + } if (posterRole == Role.Teacher || posterRole == Role.Secretary || posterRole == Role.Admin) authorizedApps.add(Applications.MANAGECOURSES); @@ -58,5 +59,4 @@ public class ApplicationsController { return authorizedApps; } - } \ No newline at end of file From b7b2eafb933d9a1cac369dc24f68451459d91591 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Sat, 16 Mar 2024 00:44:11 +0100 Subject: [PATCH 17/28] removed the GET /Apps/{id} frontend just iterates on the /apps list --- .../Clyde/EndPoints/ApplicationsController.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java index d5ad171..c76d513 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java @@ -31,16 +31,7 @@ public class ApplicationsController { return new ResponseEntity<>(getAuthorizedApplications(token), HttpStatus.OK); } - @GetMapping("/apps/{identifier}") - public ResponseEntity getAppAuthorization(@PathVariable Applications identifier, @RequestHeader("Authorization") String token){ - - if (getAuthorizedApplications(token).contains(identifier)){ - return new ResponseEntity<>(true, HttpStatus.OK); - } - return new ResponseEntity<>(false, HttpStatus.OK); - } - - public ArrayList getAuthorizedApplications(String token){ + private ArrayList getAuthorizedApplications(String token){ Role posterRole = authServ.getUserFromToken(token).getRole(); ArrayList authorizedApps = new ArrayList<>(); From 13fd048cd28f2efc59a6b7a4112343761aed28b9 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Sat, 16 Mar 2024 09:01:36 +0100 Subject: [PATCH 18/28] added a inscriptionService mock user --- .../main/java/ovh/herisson/Clyde/EndPoints/MockController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index 136cecd..f3ea51d 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -43,7 +43,8 @@ public class MockController { User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), null,Role.Student,passwordEncoder.encode("student")); User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Teacher,passwordEncoder.encode("secretary")); User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), null,Role.Teacher,passwordEncoder.encode("teacher")); - mockUsers = new ArrayList(Arrays.asList(herobrine,joe,meh,joke)); + User lena = new User("Louille","Lena","inscriptionService@InscriptionService.com","no","yes",new Date(0), null,Role.Teacher,passwordEncoder.encode("inscriptionService")); + mockUsers = new ArrayList<>(Arrays.asList(herobrine,joe,meh,joke)); userRepo.saveAll(mockUsers); } From c6198b7220931156195ebeb7901cd3cda13dd926 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Sat, 16 Mar 2024 09:02:08 +0100 Subject: [PATCH 19/28] cleaned Services + added private final to all repos --- .../Clyde/Services/AuthenticatorService.java | 2 -- .../herisson/Clyde/Services/InscriptionService.java | 13 +++++-------- .../ovh/herisson/Clyde/Services/StorageService.java | 2 -- .../ovh/herisson/Clyde/Services/TokenService.java | 4 +--- .../main/java/ovh/herisson/Clyde/Tables/Course.java | 2 +- 5 files changed, 7 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java index 1cc18e1..a3301c1 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/AuthenticatorService.java @@ -1,8 +1,6 @@ package ovh.herisson.Clyde.Services; import org.springframework.stereotype.Service; -import ovh.herisson.Clyde.EndPoints.LoginController; -import ovh.herisson.Clyde.Repositories.InscriptionRepository; import ovh.herisson.Clyde.Tables.InscriptionRequest; import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.Token; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java index 45495b7..318dfc1 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java @@ -4,23 +4,20 @@ import org.springframework.stereotype.Service; import ovh.herisson.Clyde.Repositories.InscriptionRepository; import ovh.herisson.Clyde.Tables.InscriptionRequest; -import java.util.HashMap; -import java.util.Map; - @Service public class InscriptionService { - InscriptionRepository incriptionRepo; + private final InscriptionRepository inscriptionRepo; public void save(InscriptionRequest inscriptionRequest){ - incriptionRepo.save(inscriptionRequest); + inscriptionRepo.save(inscriptionRequest); } public InscriptionService(InscriptionRepository inscriptionRepo){ - this.incriptionRepo = inscriptionRepo; + this.inscriptionRepo = inscriptionRepo; } public InscriptionRequest getById(long id){ - InscriptionRequest inscriptionRequest = incriptionRepo.findById(id); + InscriptionRequest inscriptionRequest = inscriptionRepo.findById(id); if (inscriptionRequest == null){ return null; @@ -29,6 +26,6 @@ public class InscriptionService { } public Iterable getAll(){ - return incriptionRepo.findAll(); + return inscriptionRepo.findAll(); } } \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java index c7f8d1b..fb04f68 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java @@ -4,10 +4,8 @@ import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import ovh.herisson.Clyde.Repositories.FileRepository; import ovh.herisson.Clyde.Tables.*; - import java.io.File; import java.io.IOException; - import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java index 50ddcbf..ce0d109 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java @@ -5,16 +5,14 @@ import org.springframework.stereotype.Service; import ovh.herisson.Clyde.Repositories.TokenRepository; import ovh.herisson.Clyde.Tables.Token; import ovh.herisson.Clyde.Tables.User; - import java.io.UnsupportedEncodingException; import java.security.SecureRandom; import java.util.ArrayList; import java.util.Calendar; -import java.util.Date; @Service public class TokenService { - TokenRepository tokenRepo; + private final TokenRepository tokenRepo; public TokenService(TokenRepository tokenRepo){ this.tokenRepo = tokenRepo; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java index 54e167a..fb11604 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java @@ -1,6 +1,6 @@ package ovh.herisson.Clyde.Tables; -import jakarta.persistence.Entity; +import ja karta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; From 8f2fb041129f83e717d2b382b831f47b4eef1a7f Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Sat, 16 Mar 2024 09:03:03 +0100 Subject: [PATCH 20/28] I pressed tab by accident --- backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java index fb11604..54e167a 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java @@ -1,6 +1,6 @@ package ovh.herisson.Clyde.Tables; -import ja karta.persistence.Entity; +import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; From 17d0ae7ccc4d7f39ea301c0bec7b6c3b8ba34b49 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sat, 16 Mar 2024 10:17:04 +0100 Subject: [PATCH 21/28] Refactoring: cursus -> curriculum frontend I hope I didn't missed anything, this commit is following the previous one in this branch --- frontend/src/Apps/Login.vue | 6 ++-- frontend/src/Apps/ManageCourses.vue | 18 +++++------ frontend/src/Apps/Profil.vue | 4 +-- frontend/src/Apps/Request.vue | 2 +- frontend/src/rest/ServiceInscription.js | 2 +- frontend/src/rest/Users.js | 6 ++-- frontend/src/rest/curriculum.js | 41 +++++++++++++++++++++++++ frontend/src/rest/cursus.js | 41 ------------------------- 8 files changed, 60 insertions(+), 60 deletions(-) create mode 100644 frontend/src/rest/curriculum.js delete mode 100644 frontend/src/rest/cursus.js diff --git a/frontend/src/Apps/Login.vue b/frontend/src/Apps/Login.vue index a5043e8..73b4f81 100644 --- a/frontend/src/Apps/Login.vue +++ b/frontend/src/Apps/Login.vue @@ -16,7 +16,7 @@ const email=ref("") const address=ref("") const country=ref("") - const cursus=ref("") + const curriculum=ref("") const imageSaved = ref(false) const ppData = ref(false) @@ -49,7 +49,7 @@
- +

{{i18n("login.guest.welcome")}}

@@ -103,7 +103,7 @@

{{i18n("curriculum").toUpperCase()}}

- diff --git a/frontend/src/Apps/ManageCourses.vue b/frontend/src/Apps/ManageCourses.vue index 5827e52..0a3fe27 100644 --- a/frontend/src/Apps/ManageCourses.vue +++ b/frontend/src/Apps/ManageCourses.vue @@ -1,7 +1,7 @@ @@ -130,7 +130,7 @@ const cursus=[
{{i18n("courses.toDelete")}} :
@@ -147,7 +147,7 @@ const cursus=[
-
+
+ v-for="item in user.curriculum">
{{item.name}}
{{item.teacher}}
diff --git a/frontend/src/Apps/Request.vue b/frontend/src/Apps/Request.vue index 4d63464..3e0eec4 100644 --- a/frontend/src/Apps/Request.vue +++ b/frontend/src/Apps/Request.vue @@ -8,7 +8,7 @@ address: String, country: String, birthDate: String, - cursus:String, + curriculum:String, degree:String,}); diff --git a/frontend/src/rest/ServiceInscription.js b/frontend/src/rest/ServiceInscription.js index 5068217..1f75123 100644 --- a/frontend/src/rest/ServiceInscription.js +++ b/frontend/src/rest/ServiceInscription.js @@ -24,7 +24,7 @@ export async function createRegister(){ * - country * - birthdate * - email - * - cursus + * - curriculum * - degree */ export async function getRegisters(id){ diff --git a/frontend/src/rest/Users.js b/frontend/src/rest/Users.js index b786f0d..17420b5 100644 --- a/frontend/src/rest/Users.js +++ b/frontend/src/rest/Users.js @@ -14,10 +14,10 @@ export async function login(user, pass, exp){ * @param mail * @param address * @param country - * @param cursus + * @param curriculum * @param imageId id of the image in database returned when uploaded */ -export async function register(firstname, lastname, birthDate, password, email, address, country, cursus, imageId){ +export async function register(firstname, lastname, birthDate, password, email, address, country, curriculum, imageId){ return restPost("/register", { firstname: firstname, lastname: lastname, @@ -26,7 +26,7 @@ export async function register(firstname, lastname, birthDate, password, email, email: email, address: address, country: country, - cursus: cursus + curriculum: curriculum }); } diff --git a/frontend/src/rest/curriculum.js b/frontend/src/rest/curriculum.js new file mode 100644 index 0000000..4aa6d8f --- /dev/null +++ b/frontend/src/rest/curriculum.js @@ -0,0 +1,41 @@ +/** + * curriculum API + */ + +import { restGet, restPostn, restDelete, restPatch } from './restConsumer.js' + +/** + * Create a new curriculum (bundle of courses) + * @param courses list of courses + */ +export async function createcurriculum(courses){ + return restPost("/curriculum", {courses: courses} ); +} + +/** + * Delete the specified curriculum + */ +export async function deletecurriculum(id){ + return restDelete("/curriculum/" + id); +} + +/** + * Get informations on a particular curriculum + * + * @param id identification of the curriculum + * + * @return list of courses + */ +export async function getcurriculum(id){ + return restGet("/curriculum/" + id); +} + +/** + * Modify the courses of a curriculum + * + * @param id the id of the curriculum + * @param courses list of new courses + */ +export async function altercurriculum(id, courses){ + return restPatch("/curriculum/" + id, courses); +} diff --git a/frontend/src/rest/cursus.js b/frontend/src/rest/cursus.js deleted file mode 100644 index 5aad5be..0000000 --- a/frontend/src/rest/cursus.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * cursus API - */ - -import { restGet, restPostn, restDelete, restPatch } from './restConsumer.js' - -/** - * Create a new cursus (bundle of courses) - * @param courses list of courses - */ -export async function createCursus(courses){ - return restPost("/cursus", {courses: courses} ); -} - -/** - * Delete the specified cursus - */ -export async function deleteCursus(id){ - return restDelete("/cursus/" + id); -} - -/** - * Get informations on a particular cursus - * - * @param id identification of the cursus - * - * @return list of courses - */ -export async function getCursus(id){ - return restGet("/cursus/" + id); -} - -/** - * Modify the courses of a cursus - * - * @param id the id of the cursus - * @param courses list of new courses - */ -export async function alterCursus(id, courses){ - return restPatch("/cursus/" + id, courses); -} From 45fbef52edd3034c6036a8f7055ee6dbfede031f Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sat, 16 Mar 2024 12:29:51 +0100 Subject: [PATCH 22/28] fix tokens characters --- .../main/java/ovh/herisson/Clyde/Services/TokenService.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java index 50ddcbf..8c9e2d6 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java @@ -9,6 +9,7 @@ import ovh.herisson.Clyde.Tables.User; import java.io.UnsupportedEncodingException; import java.security.SecureRandom; import java.util.ArrayList; +import java.util.Base64; import java.util.Calendar; import java.util.Date; @@ -30,13 +31,10 @@ public class TokenService { new SecureRandom().nextBytes(bytes); for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) (((bytes[i]+256)%256 %95+ 32)); - while ((char)bytes[i] == ';'){ - bytes[i] = new SecureRandom().generateSeed(1)[0]; - } } // will never end up in the catch because of the way that SecureRandom.nextBytes is implemented try { - return new String(bytes,"ISO_8859_1"); + return new String(Base64.getEncoder().encode(bytes),"ISO_8859_1"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } From 847936b799082589ba6c50d13cda0cbca2d37557 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sat, 16 Mar 2024 12:29:51 +0100 Subject: [PATCH 23/28] fix tokens characters --- .../main/java/ovh/herisson/Clyde/Services/TokenService.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java index 50ddcbf..8c9e2d6 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java @@ -9,6 +9,7 @@ import ovh.herisson.Clyde.Tables.User; import java.io.UnsupportedEncodingException; import java.security.SecureRandom; import java.util.ArrayList; +import java.util.Base64; import java.util.Calendar; import java.util.Date; @@ -30,13 +31,10 @@ public class TokenService { new SecureRandom().nextBytes(bytes); for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) (((bytes[i]+256)%256 %95+ 32)); - while ((char)bytes[i] == ';'){ - bytes[i] = new SecureRandom().generateSeed(1)[0]; - } } // will never end up in the catch because of the way that SecureRandom.nextBytes is implemented try { - return new String(bytes,"ISO_8859_1"); + return new String(Base64.getEncoder().encode(bytes),"ISO_8859_1"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } From 04f64f505e23bddf710c69214d59890a0efc9595 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sat, 16 Mar 2024 13:56:29 +0100 Subject: [PATCH 24/28] Indicated that you are logged by coloring the icon in orange and disconnect if clicked on it --- frontend/src/App.vue | 10 +++++++--- frontend/src/Apps/Login.vue | 5 ++++- frontend/src/rest/Users.js | 9 +++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 7b944de..1163b03 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -2,6 +2,7 @@ import { toast } from 'vue3-toastify'; import { ref, computed } from 'vue' import i18n, { setLang } from './i18n.js' + import { isLogged } from '@/rest/Users.js' // Liste des apps @@ -19,6 +20,7 @@ const currentPath = ref(window.location.hash) window.addEventListener('hashchange', () => { + Logged.value = isLogged(); currentPath.value = window.location.hash }) @@ -31,7 +33,9 @@ const settings=ref(i18n("app.settings")) const login=ref(i18n("app.login")) const active=ref(false) - + + const Logged = ref(isLogged()); +