WIP: Page & /apps endpoints api stub #113

Manually merged
tonitch merged 4 commits from tonitch/front/pagesAPI into master 2024-03-16 14:45:06 +01:00
43 changed files with 1665 additions and 263 deletions
Showing only changes of commit 77a170be6d - Show all commits

View File

@ -41,3 +41,4 @@ tasks.register("run") {
tasks.withType<Test> {
useJUnitPlatform()
}

View File

@ -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<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);}
Iterable<InscriptionRequest> inscriptionRequests = inscriptionServ.getAll();
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
for (InscriptionRequest i:inscriptionRequests){
toReturn.add(requestWithoutPassword(i));
}
return new ResponseEntity<>(toReturn, HttpStatus.OK);
}
@GetMapping("/inscriptionRequest/{id}")
public ResponseEntity<Map<String,Object>> 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<String,Object> requestWithoutPassword(InscriptionRequest inscriptionRequest) {
Map<String, Object> 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;
}
}

View File

@ -1,15 +1,22 @@
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(origins = "http://localhost:5173")
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
public class LoginController {
private final AuthenticatorService authServ;
@ -40,6 +47,13 @@ public class LoginController {
responseHeaders.set("Set-Cookie",String.format("session_token=%s",sessionToken));
return ResponseEntity.ok().headers(responseHeaders).build();
}
@PostMapping("/register")
public ResponseEntity<String> register(@RequestBody InscriptionRequest inscriptionRequest){
authServ.register(inscriptionRequest);
return new ResponseEntity<>("Is OK", HttpStatus.OK);
}
}

View File

@ -1,35 +1,33 @@
package ovh.herisson.Clyde.EndPoints;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Repositories.TokenRepository;
import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.Token;
import ovh.herisson.Clyde.Tables.User;
import ovh.herisson.Clyde.Services.TokenService;
import ovh.herisson.Clyde.Tables.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@RestController
@CrossOrigin(origins = "http://localhost:5173")
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
public class MockController {
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
public final UserRepository userRepo;
public final TokenRepository tokenRepo;
public final TokenService tokenService;
ArrayList<User> 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,18 +39,13 @@ 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<User>(Arrays.asList(herobrine,joe,meh,joke));
userRepo.saveAll(mockUsers);
for (User user: mockUsers){
tokenRepo.save(new Token(user,user.getPassword()));
}
}
@DeleteMapping("/mock")
@ -63,3 +56,4 @@ public class MockController {
userRepo.deleteAll(mockUsers);
}
}

View File

@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.RestController;
import ovh.herisson.Clyde.Responses.PingResponse;
@RestController
@CrossOrigin(origins = "http://localhost:5173")
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
public class PingController {
@GetMapping("/ping")

View File

@ -0,0 +1,36 @@
package ovh.herisson.Clyde.EndPoints;
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 ovh.herisson.Clyde.Tables.FileType;
import ovh.herisson.Clyde.Tables.StorageFile;
@RestController
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
public class StorageController {
private final StorageService storageServ;
public StorageController(StorageService storageServ){
this.storageServ= storageServ;
}
@PostMapping("/upload/{fileType}")
public ResponseEntity<StorageFile> handleFileUpload(@RequestParam("file") MultipartFile file, @PathVariable FileType fileType) {
StorageFile fileEntry = null;
try {
fileEntry = storageServ.store(file,fileType);
} catch(Exception e){
e.printStackTrace();
}
return new ResponseEntity<>(fileEntry, HttpStatus.OK);
}
}

View File

@ -0,0 +1,26 @@
package ovh.herisson.Clyde.EndPoints;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import ovh.herisson.Clyde.Services.TokenService;
import ovh.herisson.Clyde.Tables.Token;
@RestController
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
public class TokenController {
private final TokenService tokenServ;
public TokenController(TokenService tokenServ){
this.tokenServ = tokenServ;
}
@GetMapping("/tokens")
public Iterable<Token> getTokens(){
return tokenServ.getAllTokens();
}
}

View File

@ -1,18 +1,26 @@
package ovh.herisson.Clyde.EndPoints;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
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.UserService;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@RestController
@CrossOrigin(origins = "http://localhost:5173")
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
public class UserController {
private final UserService userService;
@ -23,25 +31,80 @@ public class UserController {
}
@GetMapping("/user")
public ResponseEntity<User> getUser(@RequestHeader("Authorization") String token){
User user = authServ.getUserFromToken(token);
if (user == null) {
return new UnauthorizedResponse<>(null);
}
return new ResponseEntity<>(user, HttpStatus.OK);
public ResponseEntity<HashMap<String,Object>> getUser(@RequestHeader("Authorization") String authorization){
if (authorization == null) return new UnauthorizedResponse<>(null);
User user = authServ.getUserFromToken(authorization);
if (user == null) return new UnauthorizedResponse<>(null);
return new ResponseEntity<>(userWithoutPassword(user), HttpStatus.OK);
}
@PostMapping("/user")
public ResponseEntity<String> postUser(@RequestBody User user){
public ResponseEntity<String> postUser(@RequestBody User user,@RequestHeader("Authorization") String authorization){
if (!isSecretaryOrAdmin(authorization))
return new UnauthorizedResponse<>(null);
userService.save(user);
return new ResponseEntity<String>(String.format("Account created with ID:%s",user.getRegNo()),HttpStatus.CREATED);
return new ResponseEntity<>(String.format("Account created with ID:%s",user.getRegNo()),HttpStatus.CREATED);
}
@GetMapping("/users")
public Iterable<User> getAllUsers(){
return userService.getAll();
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllUsers(@RequestHeader("Authorization") String authorization){
if (!isSecretaryOrAdmin(authorization))
return new UnauthorizedResponse<>(null);
Iterable<User> users = userService.getAll();
ArrayList<HashMap<String, Object>> withoutPassword = new ArrayList<>();
for (User u :users){
withoutPassword.add(userWithoutPassword(u));
}
return new ResponseEntity<>(withoutPassword, HttpStatus.OK);
}
@PatchMapping("/user")
public ResponseEntity<String> patchUser(@RequestBody Map<String,Object> updates, @RequestHeader("Authorization") String authorization) {
if (authorization == null) return new UnauthorizedResponse<>(null);
User poster = authServ.getUserFromToken(authorization);
if (poster == null) {return new UnauthorizedResponse<>("bad authorization");}
if (!userService.modifyData(poster, updates, poster))
return new UnauthorizedResponse<>("there was an issue with the updates requested");
return new ResponseEntity<>("data modified", HttpStatus.OK);
}
/** return user's data except password
* @param user the user to return
* @return all the user data without the password
*/
private HashMap<String,Object> userWithoutPassword(User user){
HashMap<String,Object> toReturn = new HashMap<>();
toReturn.put("regNo",user.getRegNo());
toReturn.put("firstName",user.getFirstName());
toReturn.put("lastName",user.getLastName());
toReturn.put("birthDate",user.getBirthDate());
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;
}
}

View File

@ -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

View File

@ -0,0 +1,9 @@
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

@ -0,0 +1,10 @@
package ovh.herisson.Clyde.Repositories;
import org.springframework.data.repository.CrudRepository;
import ovh.herisson.Clyde.Tables.InscriptionRequest;
public interface InscriptionRepository extends CrudRepository<InscriptionRequest,Long> {
InscriptionRequest findById(long aLong);
}

View File

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

View File

@ -1,6 +1,10 @@
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;
import java.util.Date;
@ -10,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){
@ -26,7 +32,11 @@ 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;
}
public void register(InscriptionRequest inscriptionRequest) {
inscriptionService.save(inscriptionRequest);
}
}

View File

@ -0,0 +1,34 @@
package ovh.herisson.Clyde.Services;
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);
}
public InscriptionService(InscriptionRepository inscriptionRepo){
this.incriptionRepo = inscriptionRepo;
}
public InscriptionRequest getById(long id){
InscriptionRequest inscriptionRequest = incriptionRepo.findById(id);
if (inscriptionRequest == null){
return null;
}
return inscriptionRequest;
}
public Iterable<InscriptionRequest> getAll(){
return incriptionRepo.findAll();
}
}

View File

@ -0,0 +1,70 @@
package ovh.herisson.Clyde.Services;
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;
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;
if(!Files.exists(rootLocation)){
try {
Files.createDirectories(rootLocation);
} catch(IOException e){
e.printStackTrace();
}
}
}
public StorageFile 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();
return fileRepo.save(new StorageFile(file.getName(),url, fileType));
}
public void delete(StorageFile file) throws SecurityException {
File f = new File(file.getUrl());
f.delete();
//Delete l'entité
fileRepo.delete(file);
}
}

View File

@ -1,31 +1,38 @@
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){
this.tokenRepo = tokenRepo;
}
public Iterable<Token> getAllTokens() {
return tokenRepo.findAll();
}
public String generateNewToken(){
byte[] bytes = new byte[64];
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 {
@ -35,11 +42,34 @@ public class TokenService {
}
}
public User getUserFromToken(String token){
return tokenRepo.getByToken(token).getUser();
public User getUserFromToken(String token) {
Token tokenRep = tokenRepo.getByToken(token);
if (tokenRep == null) return null;
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<Token> tokenList = tokenRepo.getByUserOrderByExpirationDate(token.getUser());
while(tokenList.size() >= 5){
tokenRepo.delete(tokenList.get(0));
tokenList.remove(tokenList.get(0));
}
tokenRepo.save(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

@ -5,16 +5,10 @@ import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.*;
@Service
public class UserService {
private final UserRepository userRepo;
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
@ -34,17 +28,79 @@ public class UserService {
}
}
/** modify the target data
* verify the permission of modifying from the poster
*
* @param poster the user wanting to modify target's data
* @param updates the changes to be made
* @param target the user to update
* @return if the changes were done or not
*/
public boolean modifyData(User poster, Map<String ,Object> updates, User target){
if (poster.getRegNo().equals(target.getRegNo())){
for (Map.Entry<String, Object> entry : updates.entrySet()){
if ( entry.getKey().equals("regNo") || entry.getKey().equals("role")) {return false;}
switch (entry.getKey()){
case "firstName":
target.setFirstName((String) entry.getValue());
break;
case "lastName":
target.setLastName((String) entry.getValue());
break;
case "email":
target.setEmail((String) entry.getValue());
break;
case "address":
target.setAddress((String) entry.getValue());
break;
case "country":
target.setCountry((String) entry.getValue());
break;
case "birthDate":
target.setBirthDate((Date) entry.getValue());
break;
case "profilePictureUrl":
target.setProfilePictureUrl((String) entry.getValue());
break;
case "password":
target.setPassword(passwordEncoder.encode((String) entry.getValue()));
break;
}
}
userRepo.save(target);
return true;
}
// the secretary can change roles (for example if a student becomes a teacher)
else if (poster.getRole() == Role.Secretary)
{
for (Map.Entry<String, Object> entry : updates.entrySet()){
if ( !entry.getKey().equals("role")) {return false;}
if (entry.getValue() == Role.Admin){return false;}
target.setRole((Role) entry.getValue());
userRepo.save(target);
return true;
}
}
return false;
}
public boolean checkPassword(User user, String tryingPassword){
return passwordEncoder.matches(tryingPassword, user.getPassword());
}
public void save(User user){
user.setPassword(passwordEncoder.encode(user.getPassword()));
userRepo.save(user);
}
public Iterable<User> getAll(){
return userRepo.findAll();
}
}

View File

@ -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;

View File

@ -0,0 +1,8 @@
package ovh.herisson.Clyde.Tables;
public enum CursusType {
infoBab1,
chemistryBab1,
psychologyBab1;
}

View File

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

View File

@ -0,0 +1,115 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*;
import java.util.Date;
@Entity
public class InscriptionRequest {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String firstName;
private String lastName;
private String address;
private String email;
private String country;
private Date birthDate;
@ManyToOne
@JoinColumn(name="Cursus")
private Cursus cursus;
private RequestState state;
private String profilePicture;
private String password;
public InscriptionRequest(){}
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.address = address;
this.email = email;
this.country = country;
this.birthDate = birthDate;
this.state = state;
this.profilePicture = profilePicture;
this.password = password;
}
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 getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
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

@ -0,0 +1,75 @@
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 = false;
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 ReinscriptionRequest(User user, Cursus newCursus, RequestState state){
this.user = user;
this.newCursus = newCursus;
this.state = state;
}
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

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

View File

@ -4,5 +4,6 @@ public enum Role {
Teacher,
Student,
Admin,
InscriptionService,
Secretary;
}

View File

@ -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;
}
}

View File

@ -0,0 +1,60 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*;
@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,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 {
@ -8,17 +12,20 @@ public class Token {
@Id
private int id;
@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.EAGER)
@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;
}
}

View File

@ -8,14 +8,14 @@ import java.util.Date;
//et l'attribut tokenApi doit encore être ajouté vu qu'il faut en discuter
@Entity
//Je rajoute un s au nom de la table pour éviter les conflits avec les mots réservés
@Table(name = "Users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int regNo;
private Long regNo;
private String lastName;
private String firstName;
@Column(unique = true)
private String email;
private String address;
private String country;
@ -23,7 +23,9 @@ 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;
@ -35,9 +37,34 @@ public class User {
this.password = password;
}
/** Constructor for the first registration request from a student (can't specify a Role)
*
* @param lastName
* @param firstName
* @param email
* @param address
* @param country
* @param birthDate
* @param profilePictureUrl
* @param password
*/
public User(String lastName, String firstName, String email, String address,
String country, Date birthDate, String profilePictureUrl, String password)
{
this.lastName = lastName;
this.firstName = firstName;
this.email = email;
this.address = address;
this.country = country;
this.birthDate = birthDate;
this.profilePictureUrl = profilePictureUrl;
this.password = password;
this.role = Role.Student;
}
public User() {}
public int getRegNo(){
public Long getRegNo(){
return this.regNo;
}
public String getLastName() {

View File

@ -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;

View File

@ -18,8 +18,3 @@ var dev = tasks.register<NpmTask>("dev") {
tasks.register<NpmTask>("run") {
dependsOn(dev)
}
tasks.register<NpmTask>("test") {
dependsOn(tasks.npmInstall)
args.set(listOf("run", "test:unit"))
}

View File

@ -1,11 +1,9 @@
# English translations (some examples to remove)
login.guest.signin=Sign in
login.guest.register=Register
login.guest.alregister=Already Registered
login.guest.welcome=WELCOME TO THE UNIVERSITY
login.guest.email=E-MAIL
login.guest.firstname= FIRSTNAME
login.guest.firstname=FIRSTNAME
login.guest.surname=SURNAME
login.guest.country=COUNTRY
login.guest.address=ADDRESS
@ -15,6 +13,8 @@ login.guest.lastpage=Last Page
login.guest.submit=Submit
login.guest.birthday=BIRTHDAY
login.guest.confirm=CONFIRM
login.cPassword=Confirm Password
login.password=Password
app.home=Home
app.login=Login
app.notifications=Notifications
@ -23,8 +23,28 @@ app.messages=Messages
app.forum=Forum
app.schedules=Schedules
app.inscription.requests=Inscription Requests
app.manage.courses=Manage Courses
app.language=Language
app.manage.profile=Manage profile
request.moreInfos=More Infos
request.accept=Accept
request.refuse=Refuse
#=====================================================
courses.createCourse=Create course
courses.deleteCourse=Delete course
courses.modify=Modify
courses.toDelete=Course to Delete
courses.confirm=Confirm
courses.back=Back
profile.modify.data=Modify personnal data
profile.reRegister=Re-register
profile.unRegister=Unregister
profile.course.list=Courses list
profile.address=Address
profile.picture=Profile picture
name=Name
teacher=Teacher
student=Student
secretary=Secretary
curriculum=curriculum
credits=Credits
faculty=Faculty

View File

@ -1,20 +1,20 @@
# Traductions françaises (Quelques examples a enlever)
login.guest.signin=SE CONNECTER
login.guest.register=S'enregistrer
login.guest.alregister=Déjà Enregistré
login.guest.welcome=BIENVENUE A L'UNIVERSITE
login.guest.email=E-MAIL
login.guest.firstname= PRENOM
login.guest.surname= NOM
login.guest.country= PAYS
login.guest.firstname=PRENOM
login.guest.surname=NOM
login.guest.country=PAYS
login.guest.address=ADRESSE
login.guest.password= MOT DE PASSE
login.guest.password=MOT DE PASSE
login.guest.nextpage=Prochaine Page
login.guest.lastpage=Derniere Page
login.guest.submit=Envoyer
login.guest.birthday=DATE DE NAISSANCE
login.guest.confirm=CONFIRMER
login.cPassword=Confirmer mot de passe
login.password=Mot de passe
app.home=Home
app.login=Se connecter
app.notifications=Notifications
@ -23,7 +23,28 @@ app.messages=Messages
app.forum=Forum
app.schedules=Horaires
app.inscription.requests=Demandes d'Inscription
app.manage.courses=Gérer les cours
app.language=Langue
app.manage.profile=Gérer le profil
request.moreInfos=Plus d'Infos
request.accept=Accepter
request.refuse=Refuser
#=====================================================
courses.createCourse=Créer un cours
courses.deleteCourse=Supprimer un cours
courses.modify=Modifier
courses.toDelete=Cours à supprimer
courses.confirm=Confirmer
courses.back=Retour
profile.modify.data=Modifier données personnelles
profile.reRegister=Réinsciption
profile.unRegister=Désinscription
profile.course.list=Liste des cours
profile.address=Adresse
profile.picture=Photo de profil
name=Nom
teacher=Enseignant
student=Etudiant
secretary=Secrétaire
curriculum=Cursus
credits=Credits
faculty=Faculté

View File

@ -7,10 +7,14 @@
// Liste des apps
import LoginPage from './Apps/Login.vue'
import Inscription from "./Apps/Inscription.vue"
import Profil from "./Apps/Profil.vue"
import Courses from "./Apps/ManageCourses.vue"
const apps = {
'/login': LoginPage,
'/inscription': Inscription
'/inscription': Inscription,
'/profil': Profil,
'/manage-courses' : Courses,
}
const currentPath = ref(window.location.hash)
@ -26,8 +30,7 @@
const notifications=ref(i18n("app.notifications"))
const settings=ref(i18n("app.settings"))
const login=ref(i18n("app.login"))
const active=ref(false)
</script>
@ -37,29 +40,41 @@
<div class="topBar">
<ul class="horizontal">
<li title=home>
<a href="#home">
<img @click="draw" src="./assets/Clyde.png" style="width: 40px; height: auto; margin-top:4px">
<a class="icon" href="#home">
<img class="clyde" src="./assets/Clyde.png" style="width: 40px; height: auto; margin-top:4px">
</a></li>
<li title=home>
<a href="#home">
<a class="icon" href="#home">
<div class=" fa-solid fa-house" style="margin-top: 7px; margin-bottom: 3px;"></div>
</a></li>
<li style="float: right;" title=login>
<a href="#/login">
<a class="icon" href="#/login">
<div class="fa-solid fa-user" style="margin-top: 7px; margin-bottom: 3px;"></div>
</a></li>
<li style="float: right;" title=notifications>
<a href="#Notifications">
<a class="icon" href="#Notifications">
<div class="fa-solid fa-bell" style="margin-top: 7px; margin-bottom: 3px;"></div>
</a></li>
<li style="float: right;" title=settings>
<a href="#Options">
<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>
</a></li>
<div v-if="active" class="dropdown">
<div class="dropdown-content">{{i18n("app.language")}}</div>
<ul style="list-style-type:none;">
<li style=" margin-bottom:10px;margin-right:20px;float:left; font-size:10px; color:black;">
<button @:click="setLang('en');" href="#home">EN</button>
<li style="float:right; margin-top:7.5px;" title="Language">
<input type="checkbox" @:click="setLang( toggle? 'fr' : 'en' )" v-model="toggle" class="theme-checkbox">
</li>
<li style="float:left;font-size:10px; color:black;"><button @:click="setLang('fr');" href="#home">FR</button></li>
</ul>
<div style='align-items:center;'>
<a style="cursor:pointer;font-size:20px;" href="#/profil" class="dropdown-content">
{{i18n("app.manage.profile")}}
</a>
</div>
</div>
</a></li>
</ul>
</div>
@ -84,8 +99,12 @@
<div class="fa-solid fa-envelope" style="font-size: 40px;" ></div>
<div class="text">{{i18n("app.forum")}}</div></a></li>
<li><a href="#/inscription">
<div class="fa-solid fa-users" style="font-size: 40px;"></div>
<div class="text">{{i18n("app.inscription.requests")}}</div></a></li>
<div class="fa-solid fa-users" style="align-self:center;font-size: 40px;"></div>
<div class="text" style="top:0;">{{i18n("app.inscription.requests")}}</div></a></li>
<li><a href="#/manage-courses">
<div class="fa-solid fa-book" style="align-self:center;font-size: 40px;overflow:none;"></div>
<div class="text">{{i18n("app.manage.courses")}}</div></a></li>
</ul>
</div>
@ -122,8 +141,37 @@
.leftBar{
grid-area:leftBar;
}
.option {
position: relative;
display: block;
}
.dropdown {
margin-top:55px;
width:160px;
display: inline-block;
height:110px;
font-size: 13px;
position: absolute;
z-index: 1;
background-color:white;
}
.dropdown-content {
min-width: 160px;
text-align: center;
margin-bottom: 10px;
right:0;
color:rgb(50,50,50);
text-decoration: none;
font-size:24px
}
.dropdown-content div{
display:block;
}
ul.vertical{
list-style-type: none;
margin-top: 61px;
@ -176,7 +224,6 @@
position: fixed;
height:61px;
width: 100%;
overflow: hidden;
background-color: rgb(24, 24, 24);
}
@ -187,7 +234,7 @@
}
ul.horizontal li a:hover:not(.active){
ul.horizontal li a.icon:hover:not(.active){
background-color: black;
border-radius:6px;
color:white;
@ -205,7 +252,6 @@
}
.text {
position: absolute;
right: 0%;
width: 0%;
opacity: 0;
@ -217,55 +263,13 @@
ul.vertical:hover .text {
opacity: 1;
width: 70%;
width: 60%;
transition-duration: .3s;
padding-left: 5px;
}
.theme-checkbox {
--toggle-size: 16px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
width: 80px;
height: 40px;
background: -webkit-gradient(linear, left top, right top, color-stop(50%, #efefef), color-stop(50%, #2a2a2a)) no-repeat;
background: -o-linear-gradient(left, #efefef 50%, rgb(239, 60, 168) 50%) no-repeat;
background: linear-gradient(to right, #efefef 50%, rgb(239, 60, 168) 50%) no-repeat;
background-size: 205%;
background-position: 0;
-webkit-transition: 0.4s;
-o-transition: 0.4s;
transition: 0.4s;
border-radius: 99em;
position: relative;
cursor: pointer;
font-size: var(--toggle-size);
padding-left: 15px;
}
.theme-checkbox::before {
content: "";
width: 35px;
height: 35px;
position: absolute;
top: 2px;
left: 3px;
background: -webkit-gradient(linear, left top, right top, color-stop(50%, #efefef), color-stop(50%, #2rgb(239, 60, 168))) no-repeat;
background: -o-linear-gradient(left, #efefef 50%, rgb(239, 60, 168) 50%) no-repeat;
background: linear-gradient(to right, #efefef 50%, rgb(239, 60, 168) 50%) no-repeat;
background-size: 205%;
background-position: 100%;
border-radius: 50%;
-webkit-transition: 0.4s;
-o-transition: 0.4s;
transition: 0.4s;
.clyde:hover{
content: url("./assets/angry_clyde.png")
}
.theme-checkbox:checked::before {
left: calc(100% - 35px - 3px);
background-position: 0;
}
.theme-checkbox:checked {
background-position: 100%;
}
</style>

View File

@ -1,32 +1,10 @@
<script setup>
import Req from "./Request.vue"
const requests_example = [ {
id:0,
type:"Inscription",
lastName:"DoefenschmirtzLEMAGNIFIQUE",
firstName:"Jhon",
address: "Radiator Springs",
country: "USA",
birthdate:"2004-02-02",
email:"JohnDoe@gmail.com",
cursus:"IT",
degree:"BAC1",
},
{
id:1,
type:"ReInscription",
lastName:"Doe",
firstName:"Jane",
address: "Radiator Springs",
country: "USA",
birthdate:"2004-03-03",
email:"JaneDoe@gmail.com",
cursus:"Psychology",
degree:"BAC1",
}]
import { getRegisters } from '@/rest/ServiceInscription.js'
const requests_example = getRegisters();
</script>
<template>
<Req v-for="item of requests_example" v-bind="item">
</Req>
<Req v-for="item of requests_example"/>
</template>

View File

@ -1,47 +1,43 @@
<script setup>
import { login , register} from '@/rest/Users.js'
import { ref } from 'vue'
import i18n from '@/i18n.js'
import { login , register } from '@/rest/Users.js'
import { uploadProfilePicture } from '@/rest/uploads.js'
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)
</script>
<template>
<div class="logBoxCenterer">
<div class='loginBox'>
<div v-if="loginPage">
<form @submit.prevent="login(emailID, passwordIN)"class="form">
<form @submit.prevent="login(email, password)"class="form">
<h1 style="color:rgb(239,60,168); font-family: sans-serif;">
{{i18n("login.guest.signin")}}
</h1>
<div class="inputBox">
<p>ID / {{i18n("login.guest.email")}}</p>
<input type="text" v-model="emailID">
<input type="text" v-model="email">
</div>
<div class="inputBox">
<p>{{i18n("login.guest.password")}}</p>
<input type="password" v-model="passwordIN">
<input type="password" v-model="password">
</div>
<div class="register">
<a @click="loginPage=!loginPage">{{i18n("login.guest.register")}}</a>
@ -53,7 +49,7 @@
</div>
<div v-else>
<form @submit.prevent="register(surname,firstname,emailOUT)" class="form">
<form @submit.prevent="register(firstname, surname, birthday, password, mail, address, country, cursus)" class="form">
<h1 style="color:rgb(239,60,168); font-family: sans-serif; text-align:center;">
{{i18n("login.guest.welcome")}}
</h1>
@ -72,11 +68,12 @@
</div>
<div class="inputBox">
<p>{{i18n("login.guest.password")}}</p>
<input type="password" v-model="passwordOUT">
<input type="password" v-model="password">
</div>
<div class="inputBox">
<p>{{i18n("login.guest.confirm")}} {{i18n("login.guest.password")}}</p>
<input type="password" v-model="passwordConfirm">
<!-- TODO: Verify password is same as passwordConfirm -->
</div>
<div class="switchpage">
@ -90,7 +87,7 @@
<div v-else>
<div class="inputBox">
<p>{{i18n("login.guest.email")}}</p>
<input type="mail" v-model="emailOUT">
<input type="mail" v-model="email">
</div>
<div class="inputBox">
<p>{{i18n("login.guest.address")}}</p>
@ -100,8 +97,12 @@
<p>{{i18n("login.guest.country")}}</p>
<input type="text" v-model="country">
</div>
<form novalidate enctype="multipart/form-data" class="inputBox">
<p>ProfilePicture</p>
<input type="file" :disabled="imageSaved" @change="ppData = uploadProfilePicture($event.target.files); imageSaved = true;" accept="image/*">
</form>
<div class="inputBox">
<p>CURSUS</p>
<p>{{i18n("curriculum").toUpperCase()}}</p>
<select v-model="cursus">
<option value="Chemistry">Chemistry</option>
<option value="Psycho">Psychology</option>
@ -121,7 +122,6 @@
</form>
</div>
</div>
</div>
</template>
<style scoped>
@ -142,14 +142,6 @@
transform: translate(0px ,1px);
}
.logBoxCenterer {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.loginBox {
background-color: rgb(24,24,24);
@ -175,7 +167,6 @@
.inputBox input,button,select {
width:100%;
background:rgb(255, 0 255);
border: none;
margin-right: 50px;
padding-left: 10px;

View File

@ -0,0 +1,279 @@
<script setup>
import i18n from "@/i18n.js"
import {ref} from 'vue'
const cursus=[
{
"id": 12,
"name": "Math pour l'info",
"credits": 11,
"faculty": "science",
"teacher": 42,
"Assistants": []},
{
"id": 42,
"name": "Operating Systems",
"credits": 8,
"faculty": "science",
"teacher": 62,
"Assistants": []},
{
"id": 52,
"name": "Fonctionnement des ordinateurs",
"credits": 11,
"faculty": "science",
"teacher": 59,
"Assistants": []},
]
const profList=[42,45,62,84,59]
const createMod = ref(false)
const deleteMod = ref(false)
const editElementID = ref("");
function editItem(id){
editElementID = id;
}
//Juste pour montrer le Create Mode
const pattern = {
"id": 0,
"name": null,
"credits": null,
"faculty": null,
"teacher": null,
"Assistants": []}
let toAdd = Object.assign({}, pattern);
function addToCourse (){
if (cursus.length>0){
toAdd.id=(cursus[cursus.length-1].id)-1;}
else{
toAdd.id=0;
}
let isnull= false;
for(const [key, value] of Object.entries(toAdd)){
if(value === null){
isnull=true;
}
}
if (!isnull){
cursus.push(toAdd);
}
toAdd= Object.assign({},pattern);
}
//Juste pour montrer le Delete Mode
let toRemove;
function removeCourse() {
console.log("ok");
console.log(toRemove);
let rem=-1;
for(const [key, value] of Object.entries(cursus)){
console.log(key);
console.log(value)
if(value.name === toRemove){
rem = key;
break;
}
}
console.log(rem)
if (rem > -1){
cursus.splice(rem, 1);}
console.log(cursus);
}
</script>
<template>
<div class="body">
<div v-if="!deleteMod && !createMod" class="listTitle buttonGrid">
<button class="create" @click="createMod = true">
{{i18n("courses.createCourse")}}
</button>
<button class="delete" @click="deleteMod=true" >
{{i18n("courses.deleteCourse")}}
</button>
</div>
<div v-if="createMod">
<form class="listElement">
<div style="margin-bottom:20px;">
{{i18n("name")}} :
<input v-model="toAdd.name">
</div>
<div style="margin-bottom:20px;">
{{i18n("teacher")}} :
<select style="max-width:200px;" class="teacher" v-model="toAdd.teacher">
<option v-for="item in profList">{{item}}</option>
</select>
</div>
<div style="margin-bottom:20px;">
{{i18n("credits")}} :
<input v-model="toAdd.credits">
</div>
<div style="margin-bottom:20px;">
{{i18n("faculty")}} :
<input v-model="toAdd.faculty">
</div>
<button class="create" @click="createMod=!createMod; addToCourse();"> {{i18n("courses.confirm")}} </button>
<button style="float:right;" @click="createMod=!createMod">{{i18n("courses.back")}}</button>
</form>
</div>
<div v-if="deleteMod">
<form class="listElement">
<div style="margin-bottom:20px;">
{{i18n("courses.toDelete")}} :
<select style="max-width:200px;" class="teacher" v-model="toRemove">
<option v-for="item in cursus">{{item.name}}</option>
</select>
</div>
<div style="margin-bottom:20px;">
{{i18n("login.password")}}:
<input >
</div>
<div style="margin-bottom:20px;">
{{i18n("login.cPassword")}} :
<input>
</div>
<button class="delete" @click="deleteMod=!deleteMod;removeCourse();"> {{i18n("courses.deleteCourse")}} </button>
<button style="float:right;" @click="deleteMod=!deleteMod"> {{i18n("courses.back")}}</button>
</form>
</div>
<div v-if="!createMod && !deleteMod" v-for="item in cursus" :key="item.name">
<div style ="padding:15px 15px 15px 15px;">
<button v-if="editElementID !== item.name" @click="editElementID = item.name">
{{i18n("courses.modify")}}
</button>
<button v-else @click="editElementID= ''"> {{i18n("courses.confirm")}} </button>
</div>
<div class="listElement" >
<div class="containerElement" v-if="editElementID !== item.name" >
<div class="name"> {{item.name}} </div>
<div class="teacher">{{item.teacher}}</div>
<div class="credits">{{i18n("credits")}}:{{item.credits}}</div>
</div>
<div class="containerElement"v-else>
<input style="max-width:200px;" class="name" v-model="item.name">
<select style="max-width:200px;" class="teacher" v-model="item.teacher">
<option v-for="item in profList">{{item}}</option>
</select>
<input style="max-width:100px;"class="credits" v-model="item.credits">
</div>
</div>
</div>
</div>
</template>
<style scoped>
.body {
width:100%;
margin-bottom:10px;
}
.containerElement{
justify-content:center;
display:grid;
grid-template-columns:350px 350px 200px;
grid-template-areas:
"name teacher credits";
column-gap:10px;
}
.name {
grid-area:name;
align-self:center;
}
.teacher{
grid-area:teacher;
align-self:center;
}
.credits{
grid-area:credits;
align-self:center;
}
.listElement{
border:2px solid black;
font-size:25px;
color:white;
padding:20px;
background-color:rgb(50,50,50);
border-radius:20px;
margin-bottom:10px;
}
.modify{
font-size:25px;
padding:10px 10px 10px 10px;
background-color: rgb(239,60,168);
cursor: pointer;
border:none;
border-radius:15px;
}
input, select{
padding:10px 10px 10px 10px;
font-size:25px;
cursor: pointer;
border:none;
border-radius:15px;
}
button{
font-size:15px;
height:50px;
width:100px;
border:none;
border-radius:20px;
}
.buttonGrid{
display:grid;
grid-template-columns: auto auto;
column-gap:50px;
grid-template-areas:
"create delete";
}
.create{
grid-area:create;
background-color:rgb(0,200,0);
}
.delete{
grid-area:delete;
background-color:rgb(200,0,0);
}
.listTitle{
display: flex;
justify-content: center;
align-items: center;
width:400px;
margin-left:auto;
margin-right:auto;
border:2px solid black;
font-size:25px;
color:white;
padding:20px;
background-color:rgb(50,50,50);
border-radius:20px;margin-bottom:10px;
button:hover{
opacity:0.8;
}
}
</style>

View File

@ -0,0 +1,274 @@
<script setup>
import {reactive, ref} from 'vue'
import {getUser} from '../rest/Users.js'
import i18n from "@/i18n.js"
/*
const user = getUser();
*/
const user =reactive({
profilPicture:"../assets/clyde.png",
lastName:"Ghost",
firstName:"Clyde",
role:"student",
address: "Radiator Springs",
email:"ClydeGhost@gmail.com",
cursus:[
{
"id": 12,
"name": "Math pour l'info",
"credits": 11,
"faculty": "science",
"teacher": 42,
"Assistants": []},
{
"id": 42,
"name": "Fonctionnement des ordinateurs",
"credits": 11,
"faculty": "science",
"teacher": 42,
"Assistants": []},
],
option:"IT",
degree:"BAC1",
password:"CeciEstUnMotDePasse123",
})
/*
Teacher user
const user =reactive({
profilPicture:"../assets/clyde.png",
lastName:"Ghost",
firstName:"Clyde",
role:"teacher",
address: "Radiator Springs",
email:"ClydeGhost@gmail.com",
coursesOwned:[
{
"id": 12,
"name": "Math pour l'info",
"faculty": "science",
"teacher": 42,
"Assistants": []},
{
"id": 42,
"name": "Fonctionnement des ordinateurs",
"credits": 11,
"faculty": "science",
"teacher": 42,
"Assistants": []},
],
faculty:"Science",
})*/
const modif = ref(false);
const toModify = Object.assign({}, user);
</script>
<template>
<div class="body">
<div class="container">
<div class="profilPic">
<img class="subContainter" src="../assets/Clyde.png">
</div>
<div class="globalInfos">
<div v-if="modif==false" class="infosContainer" >
<div>
{{user.firstName}} {{user.lastName.toUpperCase()}}
</div>
<div>
E-mail: {{user.email}}
</div>
<div v-if="user.role==='student'">
{{user.option}} {{i18n(user.role).toUpperCase()}}
</div>
<div v-else>
{{i18n("faculty")}}: {{user.faculty}}
Role: {{i18n(user.role).toUpperCase()}}
</div>
<div>
<button @click="modif=!modif"> {{i18n("profile.modify.data")}} </button>
</div>
<div v-if="(user.role==='student')">
<button>{{i18n("profile.reRegister")}}</button>
<button style="float:right;background-color:rgb(150,0,0);">{{i18n("profile.unRegister")}}</button>
</div>
</div>
<div v-else class="infosContainer">
<div>
{{i18n("profile.picture")}}:
<input type="file">
</div>
<div>
E-mail:
<input type="mail" v-model="toModify.email" />
</div>
<div>
{{i18n("profile.address")}}:
<input type="text" v-model="toModify.address">
</div>
<div>
{{i18n("login.password")}}:
<input type="password" v-model="toModify.password">
</div>
<div>
{{i18n("login.cPassword")}}:
<input type="password" id="confirm">
</div>
<div>
<button @click=" modif=!modif">{{i18n("courses.confirm")}}</button>
</div>
</div>
</div>
<div v-if="modif==false"class="moreInfos">
<div v-if="(user.role==='student')">
<div class="listTitle">
{{i18n("profile.course.list")}}
</div>
<div class="listElement "
v-for="item in user.cursus">
<div class=" containerElement">
<div class="name"> {{item.name}} </div>
<div class="teacher">{{item.teacher}}</div>
<div class="credits">Credits:{{item.credits}}</div>
</div>
</div>
</div>
<div>
</div>
<div v-if="(user.role==='teacher')">
<div class="listTitle">
{{i18n("profile.course.list")}}
</div>
<div class="listElement " v-for="item in user.coursesOwned">
{{item.name}}
</div>
</div>
<div>
</div>
</div>
</div>
</div>
</template>
<style scoped>
.container{
display:grid;
grid-template-columns:200px 900px;
grid-template-rows:200px auto;
column-gap:30px;
row-gap:25px;
grid-template-areas:
"profilPic globalInfos"
"minfos minfos";
}
.profilPic{
grid-area:profilPic;
}
.globalInfos {
grid-area:globalInfos;
align-self :center;
}
.subContainter{
width:100%;
background-color:rgb(50,50,50);
border-radius:20px;
border:4px solid black;
}
.moreInfos {
grid-area:minfos;
}
.body {
width:100%;
margin-bottom:10px;
}
.containerElement{
justify-content:center;
display:grid;
grid-template-columns:350px 350px 200px;
grid-template-areas:
"name teacher credits";
column-gap:10px;
}
.name {
grid-area:name;
align-self:center;
}
.teacher{
grid-area:teacher;
align-self:center;
}
.credits{
grid-area:credits;
align-self:center;
}
.listTitle{
display: flex;
justify-content: center;
align-items: center;
width:200px;
margin-left:auto;
margin-right:auto;
border:2px solid black;
font-size:25px;
color:white;
padding:20px;
background-color:rgb(50,50,50);
border-radius:20px;margin-bottom:10px;
}
.listElement{
border:2px solid black;
font-size:25px;
color:white;
padding:20px;
background-color:rgb(50,50,50);
border-radius:20px;
margin-bottom:10px;
}
.infosContainer {
padding-bottom:50px;
border:2px solid black;
font-size:25px;
color:white;
padding:20px;
background-color:rgb(50,50,50);
border-radius:20px;
}
button{
border:none;
background-color:rgb(239, 60, 168);
border-radius:10px;
height:35px;
margin-top:10px;
}
button:hover{
opacity:0.8;
}
</style>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -10,9 +10,10 @@
*/
import { getCookie, setCookie } from './utils.js';
import { reactive } from 'vue';
const default_lang = "EN";
let langs;
const langs = reactive({});
/**
@ -27,8 +28,8 @@ let langs;
export default function i18n(key, options) {
let ret = langs[key];
if(options != null){
for (let key in options) {
ret = ret.replaceAll("$" + key, options[key]);
for (let option in options) {
ret = ret.replaceAll("$" + option, options[option]);
}
}
return ret;
@ -47,14 +48,12 @@ export async function loadLangs(lang){
const content = await (await fetch(filename)).text();
const lines = content.split("\n");
let filteredLines = {};
for (let line of lines) {
if(!line.trim().startsWith("#") && line.trim() != ""){
let split = line.indexOf("=")
filteredLines[line.substr(0, split)] = line.substr(split+1, line.length);
langs[line.substr(0, split)] = line.substr(split+1, line.length);
};
}
langs = filteredLines;
}
await loadLangs();

View File

@ -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){
if(id != null)
return restGet("/requests/register/" + id);
return restGet("/requests/register")
}
/**

View File

@ -1,11 +1,60 @@
import { restGet, restPost } from './restConsumer.js'
export async function login(user, pass, exp){
return restPost("/login", {login: user, password: pass, expiration: 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,
});
}
/**
@ -18,6 +67,25 @@ export async function getUser(id){
return restGet(endpoint);
}
/**
* Alterable datas of user.
* usage by secretary
*
* @param id regno of the user
* @param data data to change
*
* - lastName
* - firstName
* - birthDate
* - role
* - email
* - photo
* - Adress
*/
export async function alterUser(id, data){
return restPatch("/user/" + id, data);
}
/**
* Reserved for secretary roles. Allow to list all user on the plateform
*/
@ -25,3 +93,27 @@ export async function getAllUsers(){
return restGet("/users");
}
/**
* Get informations about yourself
* - RegNo
* - FirstName / LastName
* - email
* - adressId (?)
* - birthDate
* - role
*/
export async function getSelf(){
return restGet("/user");
}
/**
* Alterable datas are
* - email
* - photo
* - Adress
* - Password
*/
export async function alterSelf(data){
return restPatch("/user", data);
}

View File

@ -8,15 +8,20 @@ export async function restGet(endPoint) {
}
export async function restPost(endPoint, data) {
return await _rest(endPoint, {method: "POST", body: data});
return await _rest(endPoint, {method: "POST", credentials: 'include', body: JSON.stringify(data)});
}
export async function restPostFile(endPoint, file){
let headers = new Headers();
return await _rest(endPoint, {method: "POST", credentials: 'include', body: file, headers: headers });
}
export async function restDelete(endPoint, data) {
return await _rest(endPoint, {method: "DELETE", body: data});
return await _rest(endPoint, {method: "DELETE", credentials: 'include', body: JSON.stringify(data)});
}
export async function restPatch(endPoint, data) {
return await _rest(endPoint, {method: "PATCH", body: data});
return await _rest(endPoint, {method: "PATCH", credentials: 'include', body: JSON.stringify(data)});
}
/**
@ -31,14 +36,18 @@ export async function restPatch(endPoint, data) {
async function _rest(endPoint, config){
endPoint.at(0) != "/" ? console.error("Carefull, you certainly should put a / at the begenning of your endPoint ") : true;
let session_token = getCookie("session_token");
let headers = new Headers({'Authorization': session_token});
config['headers'] = headers;
let headers = new Headers({
'Authorization': session_token,
'Content-Type': 'application/json',
});
config['headers'] = config['headers'] == null ? headers : config['headers'];
return toast.promise(fetch(restURL + endPoint, config),
{
pending: config['pending'] != null ? config['pending'] : 'pending',
error: config['error'] != null ? config['error'] : 'Network Failure...',
success: config['success'] != null ? config['success'] : {render(res){
return res.ok ? "Success" : "error";
console.log(res);
return res.data.ok ? "Success" : "error";
}},
})
.then( e => e.json()).catch( e => e );

View File

@ -0,0 +1,11 @@
import { restPostFile } from '@/rest/restConsumer.js'
/**
* Upload a file to the server and return the url of this image
*/
export async function uploadProfilePicture(file){
const formData = new FormData();
formData.append("file", file[0]);
return restPostFile("/upload/ProfilePicture", formData)
}