Compare commits

..

No commits in common. "32feaa4a93fbd72ad75760c842edc8e24a68a2f4" and "4932aee57ac0f7f636ec33751a822abd8a5c59bb" have entirely different histories.

19 changed files with 27 additions and 428 deletions

View File

@ -7,14 +7,12 @@ 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
@ -25,14 +23,13 @@ public class MockController {
public final UserRepository userRepo;
public final TokenRepository tokenRepo;
public final TokenService tokenService;
ArrayList<User> mockUsers;
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService){
public MockController(UserRepository userRepo, TokenRepository tokenRepo){
this.tokenRepo = tokenRepo;
this.userRepo = userRepo;
this.tokenService = tokenService;
}
/** Saves an example of each user type by :
@ -44,10 +41,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), 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"));
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"));
mockUsers = new ArrayList<User>(Arrays.asList(herobrine,joe,meh,joke));

View File

@ -1,32 +0,0 @@
package ovh.herisson.Clyde.EndPoints;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import ovh.herisson.Clyde.Services.StorageService;
import org.springframework.core.io.Resource;
import ovh.herisson.Clyde.Tables.FileType;
@RestController
@CrossOrigin(origins = "http://localhost:5173")
public class StorageController {
private final StorageService storageServ;
public StorageController(StorageService storageServ){
this.storageServ= storageServ;
}
@PostMapping("/upload/{fileType}")
public ResponseEntity<String> handleFileUpload(@RequestParam("file") MultipartFile file, @PathVariable FileType fileType) {
String path = storageServ.store(file,fileType);
if (path == null) return new ResponseEntity<>("issue with the file storage", HttpStatus.BAD_REQUEST);
return new ResponseEntity<>(path, HttpStatus.OK);
}
}

View File

@ -31,7 +31,7 @@ public class UserController {
return new ResponseEntity<>(user, HttpStatus.OK);
}
@PostMapping("/user") //todo check role
@PostMapping("/user")
public ResponseEntity<String> postUser(@RequestBody User user){
userService.save(user);
return new ResponseEntity<>(String.format("Account created with ID:%s",user.getRegNo()),HttpStatus.CREATED);

View File

@ -6,10 +6,8 @@ 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

View File

@ -1,9 +0,0 @@
package ovh.herisson.Clyde.Repositories;
import org.springframework.data.repository.CrudRepository;
import ovh.herisson.Clyde.Tables.StorageFile;
public interface FileRepository extends CrudRepository<StorageFile,Long> {
}

View File

@ -4,13 +4,10 @@ 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,Long> {
Token getByToken(String token);
Iterable<Token> getByUser(User user);
ArrayList <Token> getByUserOrderByExpirationDate(User user);
}

View File

@ -1,7 +1,6 @@
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;
@ -27,7 +26,7 @@ public class AuthenticatorService {
if (user == null){return null;}
if (!userService.checkPassword(user,password)){return null;}
String token = tokenService.generateNewToken();
tokenService.saveToken(new Token(user, token,expirationDate));
tokenService.saveToken(token,user,expirationDate);
return token;
}
}

View File

@ -1,56 +0,0 @@
package ovh.herisson.Clyde.Services;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import ovh.herisson.Clyde.Repositories.FileRepository;
import ovh.herisson.Clyde.Tables.FileType;
import ovh.herisson.Clyde.Tables.StorageFile;
import java.io.IOException;
import org.springframework.core.io.Resource;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Objects;
import java.util.UUID;
@Service
public class StorageService {
private final Path rootLocation = Paths.get("cdn/");
private final FileRepository fileRepo;
public StorageService(FileRepository filerepo){
this.fileRepo = filerepo;
}
public String store(MultipartFile file, FileType fileType) {
if (file.getOriginalFilename().isEmpty()){return null;}
UUID uuid = UUID.randomUUID();
String stringUuid = uuid + "." + file.getOriginalFilename().split("\\.",2)[1];
try {
if (file.isEmpty()) {
return null;
}
Path destinationFile = this.rootLocation.resolve(Paths.get(stringUuid));
Files.copy(file.getInputStream(), destinationFile,StandardCopyOption.REPLACE_EXISTING);
}
catch (IOException e) {
return null;
}
String url = this.rootLocation.resolve(Paths.get(Objects.requireNonNull(stringUuid)))
.normalize().toString();
fileRepo.save(new StorageFile(file.getName(),url, fileType));
return url;
}
}

View File

@ -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,28 +48,7 @@ public class TokenService {
return tokenRep.getUser();
}
public void saveToken(Token token){
//Si l'utilisateur a déja 5 token delete celui qui devait expirer le plus vite
ArrayList<Token> tokenList = tokenRepo.getByUserOrderByExpirationDate(token.getUser());
while(tokenList.size() >= 5){
tokenRepo.delete(tokenList.get(0));
tokenList.remove(tokenList.get(0));
}
tokenRepo.save(token);
public void saveToken(String token, User user, Date expirationDate){// todo faire qlq chose de l'expDate
tokenRepo.save(new Token(user,token));
}
//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);
}
}
};
}
}

View File

@ -1,8 +0,0 @@
package ovh.herisson.Clyde.Tables;
public enum FileType {
ProfilePicture,
EducationCertificate
}

View File

@ -1,108 +0,0 @@
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;
}
}

View File

@ -1,69 +0,0 @@
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;
}
}

View File

@ -1,7 +0,0 @@
package ovh.herisson.Clyde.Tables;
public enum RequestState {
Accepted,
Refused,
Pending;
}

View File

@ -1,63 +0,0 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
@Entity
public class StorageFile {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String url;
private FileType fileType;
public StorageFile(String name, String url, FileType fileType){
this.name = name;
this.url = url;
this.fileType = fileType;
}
public StorageFile(){}
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public FileType getFileType() {
return fileType;
}
public void setFileType(FileType fileType) {
this.fileType = fileType;
}
}

View File

@ -1,10 +1,6 @@
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 {
@ -16,16 +12,13 @@ public class Token {
@JoinColumn(name ="Users")
private User user;
private String token;
private Date expirationDate;
public Token(User user, String token, Date expirationDate){
public Token(User user, String token){
this.user = user;
this.token = token;
this.expirationDate = expirationDate;
}
public Token(){}
public int getId() {
return id;
}
@ -44,12 +37,4 @@ public class Token {
public void setToken(String data) {
this.token = data;
}
public void setExpirationDate(Date date){
this.expirationDate = date;
}
public Date getExpirationDate(){
return expirationDate;
}
}

View File

@ -16,7 +16,6 @@ public class User {
private int regNo;
private String lastName;
private String firstName;
@Column(unique = true)
private String email;
private String address;
private String country;
@ -24,9 +23,7 @@ public class User {
private String profilePictureUrl;
private ovh.herisson.Clyde.Tables.Role role;
private String password;
public User(String lastName, String firstName, String email, String address,
String country, Date birthDate, String profilePictureUrl, Role role, String password)
{
public User(String lastName, String firstName, String email, String address, String country, Date birthDate, String profilePictureUrl, Role role, String password){
this.lastName = lastName;
this.firstName = firstName;
this.email = email;

View File

@ -56,7 +56,7 @@
<li @click="active=!active" class="option"style="float: right;" title=settings>
<a class="icon" >
<div class="fa-solid fa-gear" style="margin-top: 7px; margin-bottom: 3px;"></div>
<div v-if="active" class="dropdown">
<div v-if="active"class="dropdown">
<div class="dropdown-content">Langage</div>
<ul style="list-style-type:none;">
<li style=" margin-bottom:10px;margin-right:20px;float:left; font-size:10px; color:black;">

View File

@ -1,6 +1,6 @@
<script setup>
import {reactive, ref} from 'vue'
import {getUser} from '../rest/Users.js'
import {getUser,register} from '../rest/Users.js'
/*
const user = getUser();
*/
@ -11,15 +11,14 @@
role:"student",
address: "Radiator Springs",
email:"ClydeGhost@gmail.com",
cursus:[
{
"id": 12,
cursus:{
cours1:{ "id": 12,
"name": "Math pour l'info",
"credits": 11,
"faculty": "science",
"teacher": 42,
"Assistants": []},
{
cours2:{
"id": 42,
"name": "Fonctionnement des ordinateurs",
"credits": 11,
@ -27,7 +26,7 @@
"teacher": 42,
"Assistants": []},
],
},
option:"IT",
degree:"BAC1",
password:"CeciEstUnMotDePasse123",
@ -42,14 +41,14 @@
role:"teacher",
address: "Radiator Springs",
email:"ClydeGhost@gmail.com",
coursesOwned:[
{
coursesOwned:{
cours1:{
"id": 12,
"name": "Math pour l'info",
"faculty": "science",
"teacher": 42,
"Assistants": []},
{
cours2:{
"id": 42,
"name": "Fonctionnement des ordinateurs",
"credits": 11,
@ -57,7 +56,7 @@
"teacher": 42,
"Assistants": []},
],
},
faculty:"Science",
})*/

View File

@ -32,7 +32,7 @@
.container{
color:white;
height:100px;
font-size:20px;
font-size:20px;
display:grid;
grid-template-columns:[firstCol-start]100px[firstCol-end secondCol-start]150px[secondCol-end thirdCol-start]200px[thirdCol-end fourthCol-start]150px[fourthCol-end]150px[fifthCol-end]150px[sixthCol-end]150px[endCol];
grid-template-areas: