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 8ae4217..e3168ec 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -7,12 +7,14 @@ 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 java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; import java.util.Date; @RestController @@ -23,13 +25,14 @@ public class MockController { public final UserRepository userRepo; public final TokenRepository tokenRepo; - + public final TokenService tokenService; ArrayList mockUsers; - public MockController(UserRepository userRepo, TokenRepository tokenRepo){ + public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService){ this.tokenRepo = tokenRepo; this.userRepo = userRepo; + this.tokenService = tokenService; } /** Saves an example of each user type by : @@ -41,11 +44,10 @@ public class MockController { @PostMapping("/mock") public void postMock(){ - User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), "none",Role.Admin,passwordEncoder.encode("admin")); - User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), "None",Role.Student,passwordEncoder.encode("student")); - User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0),"none", Role.Teacher, passwordEncoder.encode("secretary")); - User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), "none",Role.Teacher, passwordEncoder.encode("teacher")); - + 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")); + 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)); userRepo.saveAll(mockUsers); diff --git a/backend/src/main/java/ovh/herisson/Clyde/JdbcConfig.java b/backend/src/main/java/ovh/herisson/Clyde/JdbcConfig.java index b6525dc..6df0b74 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/JdbcConfig.java +++ b/backend/src/main/java/ovh/herisson/Clyde/JdbcConfig.java @@ -6,8 +6,10 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.scheduling.annotation.EnableScheduling; @Configuration +@EnableScheduling public class JdbcConfig { @Bean diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/TokenRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/TokenRepository.java index 6a4e47a..d3b422a 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/TokenRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/TokenRepository.java @@ -4,10 +4,13 @@ import org.springframework.data.repository.CrudRepository; import ovh.herisson.Clyde.Tables.Token; import ovh.herisson.Clyde.Tables.User; +import java.util.ArrayList; + public interface TokenRepository extends CrudRepository { Token getByToken(String token); Iterable getByUser(User user); + ArrayList getByUserOrderByExpirationDate(User user); } 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 f3ae072..4cd1939 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,7 @@ package ovh.herisson.Clyde.Services; import org.springframework.stereotype.Service; +import ovh.herisson.Clyde.Tables.Token; import ovh.herisson.Clyde.Tables.User; import java.util.Date; @@ -26,7 +27,7 @@ public class AuthenticatorService { if (user == null){return null;} if (!userService.checkPassword(user,password)){return null;} String token = tokenService.generateNewToken(); - tokenService.saveToken(token,user,expirationDate); + tokenService.saveToken(new Token(user, token,expirationDate)); return token; } } 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 125dbde..50ddcbf 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java @@ -1,19 +1,19 @@ package ovh.herisson.Clyde.Services; - +import org.springframework.scheduling.annotation.Scheduled; 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.nio.charset.StandardCharsets; import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; @Service public class TokenService { - TokenRepository tokenRepo; public TokenService(TokenRepository tokenRepo){ @@ -48,7 +48,28 @@ public class TokenService { return tokenRep.getUser(); } - public void saveToken(String token, User user, Date expirationDate){// todo faire qlq chose de l'expDate - tokenRepo.save(new Token(user,token)); + public void saveToken(Token token){ + //Si l'utilisateur a déja 5 token delete celui qui devait expirer le plus vite + ArrayList tokenList = tokenRepo.getByUserOrderByExpirationDate(token.getUser()); + while(tokenList.size() >= 5){ + tokenRepo.delete(tokenList.get(0)); + tokenList.remove(tokenList.get(0)); + } + tokenRepo.save(token); } -} \ No newline at end of file + + //Tous les jours a minuit + @Scheduled(cron = "0 0 0 * * ?") + public void autoDeleteToken() { + for (Token t: tokenRepo.findAll()){ + Calendar cal = Calendar.getInstance(); + + Calendar cal2 = Calendar.getInstance(); + cal2.setTime(t.getExpirationDate()); + + if (cal.compareTo(cal2) >= 0){ + tokenRepo.delete(t); + } + } + }; +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java new file mode 100644 index 0000000..2e5bf0d --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/InscriptionRequest.java @@ -0,0 +1,108 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +import java.util.Date; + +public class InscriptionRequest { + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + private String firstName; + private String lastName; + private String adress; + private String email; + private String country; + private Date birthDate; + + @ManyToOne + @JoinColumn(name="Cursus") + private Cursus cursus; + private RequestState state; + private String profilePicture; + public InscriptionRequest(){} + public InscriptionRequest(String lastName, String firstName, String adress, String email, String country, Date birthDate, RequestState state, String profilePicture){ + this.lastName = lastName; + this.firstName = firstName; + this.adress = adress; + this.email = email; + this.country = country; + this.birthDate = birthDate; + this.state = state; + } + + public int getId() { + return id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getAdress() { + return adress; + } + + public void setAdress(String adress) { + this.adress = adress; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public Date getBirthDate() { + return birthDate; + } + + public void setBirthDate(Date birthDate) { + this.birthDate = birthDate; + } + + public Cursus getCursus() { + return cursus; + } + + public void setCursus(Cursus cursus) { + this.cursus = cursus; + } + + public RequestState getState() { + return state; + } + + public void setState(RequestState state) { + this.state = state; + } + + public String getProfilePicture() { + return profilePicture; + } + + public void setProfilePicture(String profilePicture) { + this.profilePicture = profilePicture; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java new file mode 100644 index 0000000..8a56f88 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/ReinscriptionRequest.java @@ -0,0 +1,69 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; + +public class ReinscriptionRequest { + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @ManyToOne + @JoinColumn(name = "User") + private User user; + + @ManyToOne + @JoinColumn(name = "Cursus") + private Cursus newCursus; + private RequestState state; + + //Permet de différencier les demandes de changement et une réinscription dans le même cursus + //Pour la réinscription on va le mettre a 0 + private boolean type; + + public ReinscriptionRequest(){} + + public ReinscriptionRequest(User user, Cursus newCursus, RequestState state, boolean type){ + this.user = user; + this.newCursus = newCursus; + this.state = state; + this.type = type; + } + + public int getId() { + return id; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public Cursus getNewCursus() { + return newCursus; + } + + public void setNewCursus(Cursus newCursus) { + this.newCursus = newCursus; + } + + public RequestState getState() { + return state; + } + + public void setState(RequestState state) { + this.state = state; + } + + public boolean isType() { + return type; + } + + public void setType(boolean type) { + this.type = type; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/RequestState.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/RequestState.java new file mode 100644 index 0000000..f0345c1 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/RequestState.java @@ -0,0 +1,7 @@ +package ovh.herisson.Clyde.Tables; + +public enum RequestState { + Accepted, + Refused, + Pending; +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java index 848f836..8aa4c0e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java @@ -1,6 +1,10 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; +import org.springframework.scheduling.annotation.Scheduled; +import ovh.herisson.Clyde.Repositories.TokenRepository; + +import java.util.Date; @Entity public class Token { @@ -12,13 +16,16 @@ public class Token { @JoinColumn(name ="Users") private User user; private String token; + private Date expirationDate; - public Token(User user, String token){ + public Token(User user, String token, Date expirationDate){ this.user = user; this.token = token; + this.expirationDate = expirationDate; } public Token(){} + public int getId() { return id; } @@ -37,4 +44,12 @@ public class Token { public void setToken(String data) { this.token = data; } + + public void setExpirationDate(Date date){ + this.expirationDate = date; + } + + public Date getExpirationDate(){ + return expirationDate; + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java index 7a2c51d..1f6aa3b 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java @@ -15,6 +15,7 @@ public class User { private Long regNo; private String lastName; private String firstName; + @Column(unique = true) private String email; private String address; private String country; diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 51f8882..ef68173 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -7,17 +7,19 @@ // Liste des apps import LoginPage from './Apps/Login.vue' import Inscription from "./Apps/Inscription.vue" + import Profil from "./Apps/Profil.vue" const apps = { '/login': LoginPage, - '/inscription': Inscription + '/inscription': Inscription, + '/profil': Profil } const currentPath = ref(window.location.hash) window.addEventListener('hashchange', () => { currentPath.value = window.location.hash }) - + const currentView = computed(() => { return apps[currentPath.value.slice(1) || '/'] }) @@ -26,9 +28,8 @@ const notifications=ref(i18n("app.notifications")) const settings=ref(i18n("app.settings")) const login=ref(i18n("app.login")) + const active=ref(false) - -