1
0
forked from PGL/Clyde

Merge branch 'master' into Leo/Backend/UnitTest

This commit is contained in:
LeoMoulin 2024-03-17 10:36:00 +01:00
commit 008af10d0e
47 changed files with 1099 additions and 400 deletions

View File

@ -0,0 +1,70 @@
package ovh.herisson.Clyde.EndPoints;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
import ovh.herisson.Clyde.Services.AuthenticatorService;
import ovh.herisson.Clyde.Tables.Applications;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User;
import java.util.ArrayList;
@RestController
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
public class ApplicationsController {
AuthenticatorService authServ;
public ApplicationsController(AuthenticatorService authServ){
this.authServ = authServ;
}
/** return a list of authorized applications.
* depends on the token
*/
@GetMapping("/apps")
public ResponseEntity<Iterable<Applications>> getAuthorizedApps(@RequestHeader("Authorization") String token){
return new ResponseEntity<>(getAuthorizedApplications(token), HttpStatus.OK);
}
@GetMapping("/apps/{identifier}")
public ResponseEntity<Boolean> getAppAuthorization(@PathVariable Applications identifier, @RequestHeader("Authorization") String token){
if (getAuthorizedApplications(token).contains(identifier)){
return new ResponseEntity<>(true, HttpStatus.OK);
}
return new ResponseEntity<>(false, HttpStatus.OK);
}
public ArrayList<Applications> getAuthorizedApplications(String token){
ArrayList<Applications> authorizedApps = new ArrayList<>();
authorizedApps.add(Applications.Login);
authorizedApps.add(Applications.Profile);
User user = authServ.getUserFromToken(token);
if(user == null)
return authorizedApps;
Role posterRole = user.getRole();
if (posterRole == Role.Teacher || posterRole == Role.Student || posterRole == Role.Admin){
authorizedApps.add(Applications.Msg);
authorizedApps.add(Applications.Forum);
authorizedApps.add(Applications.Rdv);
}
if (posterRole == Role.Teacher || posterRole == Role.Secretary || posterRole == Role.Admin) authorizedApps.add(Applications.ManageCourses);
if (posterRole == Role.InscriptionService || posterRole == Role.Admin) authorizedApps.add(Applications.Inscription);
return authorizedApps;
}
}

View File

@ -0,0 +1,80 @@
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.CourseService;
import ovh.herisson.Clyde.Services.TeacherCourseService;
import ovh.herisson.Clyde.Tables.Course;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.TeacherCourse;
import ovh.herisson.Clyde.Tables.User;
import java.util.ArrayList;
import java.util.Map;
@RestController
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
public class CourseController {
private final CourseService courseServ;
private final TeacherCourseService teacherCourseServ;
private final AuthenticatorService authServ;
public CourseController(CourseService courseServ, TeacherCourseService teacherCourseServ, AuthenticatorService authServ) {
this.courseServ = courseServ;
this.teacherCourseServ = teacherCourseServ;
this.authServ = authServ;
}
@GetMapping("/course/{id}")
public ResponseEntity<Course> getCourse(@RequestHeader("Authorization") String token, @PathVariable long id){
if (authServ.getUserFromToken(token) == null)
return new UnauthorizedResponse<>(null);
return new ResponseEntity<>(courseServ.findById(id), HttpStatus.OK);
}
@PostMapping("/course")
public ResponseEntity<Course> postCourse(@RequestHeader("Authorization") String token, @RequestBody Course course){
if (authServ.isNotSecretaryOrAdmin(token))
return new UnauthorizedResponse<>(null);
return new ResponseEntity<>(courseServ.save(course), HttpStatus.CREATED);
}
@PatchMapping("/course/{id}")
public ResponseEntity<Course> patchCourse(@RequestHeader("Authorization") String token,
@RequestBody Map<String,Object> updates,
@PathVariable long id)
{
if (authServ.IsNotIn(new Role[]{Role.Admin,Role.Teacher,Role.Secretary}, token)){
return new UnauthorizedResponse<>(null);
}
return new ResponseEntity<>(courseServ.modifyData(id, updates, authServ.getUserFromToken(token).getRole()), HttpStatus.OK);
}
@PostMapping("/course/{id}")
public ResponseEntity<String> postTeachers(@RequestHeader("Authorization") String token,
@RequestBody Iterable<Long> teacherIds,
@PathVariable Long id)
{
if (authServ.IsNotIn(new Role[]{Role.Admin,Role.Secretary}, token))
return new UnauthorizedResponse<>(null);
teacherCourseServ.saveAll(teacherIds,courseServ.findById(id));
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@ -0,0 +1,60 @@
package ovh.herisson.Clyde.EndPoints;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Services.AuthenticatorService;
import ovh.herisson.Clyde.Services.CurriculumCourseService;
import ovh.herisson.Clyde.Services.CurriculumService;
import ovh.herisson.Clyde.Tables.Curriculum;
import ovh.herisson.Clyde.Tables.CurriculumCourse;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User;
import java.util.Map;
@RestController
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
public class CurriculumController {
private final CurriculumService curriculumServ;
private final AuthenticatorService authServ;
private final CurriculumCourseService curriculumCourseServ;
public CurriculumController(CurriculumService curriculumServ, AuthenticatorService authServ, CurriculumCourseService curriculumCourseServ){
this.curriculumServ = curriculumServ;
this.authServ = authServ;
this.curriculumCourseServ = curriculumCourseServ;
}
@GetMapping("/curriculum/{id}")
public ResponseEntity<Curriculum> findById(@PathVariable long id){
return new ResponseEntity<>(curriculumServ.findById(id), HttpStatus.OK);
}
@GetMapping("/curriculums")
public ResponseEntity<Iterable<Map<String, Object>>> findAllindDepth(){
return new ResponseEntity<>(curriculumCourseServ.getAllDepthCurriculum(),HttpStatus.OK);
}
@GetMapping("/curriculum")
public ResponseEntity<Iterable<CurriculumCourse>> findAll(){
return new ResponseEntity<>(curriculumCourseServ.findAll(),HttpStatus.OK);
}
/**@PostMapping("/curriculum") //todo now
public ResponseEntity<String> postCurriculum(@RequestHeader("Authorization") String token,@RequestBody Curriculum curriculum){
if (!isSecretaryOrAdmin(token)){
return new UnauthorizedResponse<>("you're not allowed to post a Curriculum");
}
CurriculumServ.save(Curriculum);
return new ResponseEntity<>("created !",HttpStatus.CREATED);
}**/
}

View File

@ -0,0 +1,86 @@
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.RequestState;
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("/requests/register")
public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
if (authServ.isNotSecretaryOrAdmin(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("/request/register/{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);
}
@GetMapping("request/user/{id}")
public ResponseEntity<InscriptionRequest> getUserInscriptionRequest(@PathVariable long id, @RequestHeader("Authorize") String token){
//todo return l'inscriptionRequest ACTUELLE du user (check si le poster est bien le même que id target ou secretariat)
return null;
}
@PatchMapping("/request/register/{id}")
public ResponseEntity<InscriptionRequest> changeRequestState(@PathVariable long id,
@RequestHeader("Authorize") String token,
@RequestBody RequestState requestState)
{
if (authServ.isNotSecretaryOrAdmin(token)) return new UnauthorizedResponse<>(null);
inscriptionServ.modifyState(id, requestState);
return null;
}
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("curriculum", inscriptionRequest.getCurriculum());
toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture());
toReturn.put("state", inscriptionRequest.getState());
return toReturn;
}
}

View File

@ -1,10 +1,12 @@
package ovh.herisson.Clyde.EndPoints;
import com.fasterxml.jackson.annotation.JsonFormat;
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.InscriptionRequest;
import java.util.Date;
@ -28,6 +30,7 @@ public class LoginController {
public LoginController(AuthenticatorService authServ){
this.authServ = authServ;
}
@PostMapping(value = "/login")
public ResponseEntity<String> login(@RequestBody RequestLogin requestLogin){
@ -40,6 +43,10 @@ public class LoginController {
responseHeaders.set("Set-Cookie",String.format("session_token=%s",sessionToken));
return ResponseEntity.ok().headers(responseHeaders).build();
}
@PostMapping("/request/register")
public ResponseEntity<String> register(@RequestBody InscriptionRequest inscriptionRequest){
authServ.register(inscriptionRequest);
return new ResponseEntity<>("Is OK", HttpStatus.CREATED);
}
}

View File

@ -4,7 +4,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Repositories.TokenRepository;
import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Services.TokenService;
import ovh.herisson.Clyde.Services.*;
import ovh.herisson.Clyde.Tables.*;
import java.util.ArrayList;
@ -20,14 +20,19 @@ public class MockController {
public final UserRepository userRepo;
public final TokenRepository tokenRepo;
public final TokenService tokenService;
public final CurriculumCourseService CurriculumCourseService;
public final CurriculumService curriculumService;
public final CourseService courseService;
ArrayList<User> mockUsers;
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService){
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService){
this.tokenRepo = tokenRepo;
this.userRepo = userRepo;
this.tokenService = tokenService;
this.CurriculumCourseService = CurriculumCourseService;
this.curriculumService = curriculumService;
this.courseService = courseService;
}
/** Saves an example of each user type by :
@ -39,13 +44,53 @@ public class MockController {
@PostMapping("/mock")
public void postMock(){
// user part
User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), null,Role.Admin,passwordEncoder.encode("admin"));
User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), null,Role.Student,passwordEncoder.encode("student"));
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Teacher,passwordEncoder.encode("secretary"));
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Secretary,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));
User lena = new User("Louille","Lena","inscriptionService@InscriptionService.com","no","yes",new Date(0), null,Role.Teacher,passwordEncoder.encode("inscriptionService"));
mockUsers = new ArrayList<>(Arrays.asList(herobrine,joe,meh,joke));
userRepo.saveAll(mockUsers);
// Course / Curriculum part
Curriculum infoBab1 = new Curriculum(1,"info");
Curriculum chemistryBab1 = new Curriculum(1,"chemistry");
Curriculum psychologyBab1 = new Curriculum(1,"psychology");
curriculumService.save(infoBab1);
curriculumService.save(chemistryBab1);
curriculumService.save(psychologyBab1);
Course progra1 = new Course(5,"Programmation et algorithimque 1",joke);
Course chemistry1 = new Course(12, "Thermochimie",joke);
Course psycho1 = new Course(21, "rien faire t'as cru c'est psycho",joke);
Course commun = new Course(2, "cours commun",joke);
courseService.save(progra1);
courseService.save(chemistry1);
courseService.save(psycho1);
courseService.save(commun);
CurriculumCourseService.save(new CurriculumCourse(infoBab1,progra1));
CurriculumCourseService.save(new CurriculumCourse(infoBab1,commun));
CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,psycho1));
CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,commun));
CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,commun));
CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,chemistry1));
}
@DeleteMapping("/mock")

View File

@ -1,10 +1,7 @@
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;
@ -13,7 +10,7 @@ import ovh.herisson.Clyde.Services.UserService;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User;
import java.io.IOException;
import java.security.Key;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@ -43,7 +40,7 @@ public class UserController {
@PostMapping("/user")
public ResponseEntity<String> postUser(@RequestBody User user,@RequestHeader("Authorization") String authorization){
if (!isSecretaryOrAdmin(authorization))
if (authServ.isNotSecretaryOrAdmin(authorization))
return new UnauthorizedResponse<>(null);
userService.save(user);
@ -53,7 +50,7 @@ public class UserController {
@GetMapping("/users")
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllUsers(@RequestHeader("Authorization") String authorization){
if (!isSecretaryOrAdmin(authorization))
if (authServ.isNotSecretaryOrAdmin(authorization))
return new UnauthorizedResponse<>(null);
Iterable<User> users = userService.getAll();
@ -78,6 +75,21 @@ public class UserController {
return new ResponseEntity<>("data modified", HttpStatus.OK);
}
@GetMapping("/teachers")
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllTeachers(@RequestHeader("Authorization") String token){
if (authServ.getUserFromToken(token) == null)
return new UnauthorizedResponse<>(null);
Iterable<User> teachers = userService.getAllTeachers();
ArrayList<HashMap<String, Object>> withoutPassword = new ArrayList<>();
for (User t: teachers){
withoutPassword.add(userWithoutPassword(t));
}
return new ResponseEntity<>(withoutPassword, HttpStatus.OK);
}
/** return user's data except password
* @param user the user to return
@ -85,7 +97,6 @@ public class UserController {
*/
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());
@ -93,18 +104,7 @@ public class UserController {
toReturn.put("country",user.getCountry());
toReturn.put("address",user.getAddress());
toReturn.put("role",user.getRole());
return toReturn;
}
private boolean isSecretaryOrAdmin(String authorization){
if (authorization ==null)
return false;
User poster = authServ.getUserFromToken(authorization);
if (poster == null) return false;
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
}
}

View File

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

View File

@ -0,0 +1,17 @@
package ovh.herisson.Clyde.Repositories;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import ovh.herisson.Clyde.Tables.Course;
import ovh.herisson.Clyde.Tables.Curriculum;
import ovh.herisson.Clyde.Tables.CurriculumCourse;
public interface CurriculumCourseRepository extends CrudRepository<CurriculumCourse,Long> {
@Query("select distinct cc.course from CurriculumCourse cc where cc.curriculum = ?1")
Iterable<Course> findCoursesByCurriculum(Curriculum curriculum);
@Query("select distinct cc.curriculum from CurriculumCourse cc")
Iterable<Curriculum> findDistinctCurriculums();
}

View File

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

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

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

View File

@ -15,4 +15,8 @@ public interface UserRepository extends CrudRepository<User, Long> {
/**
@Query(value = "select a.* from Users a ",nativeQuery = true)
Iterable<User> findAllUsers();**/
@Query("select u from User u where u.role = ovh.herisson.Clyde.Tables.Role.Teacher")
Iterable<User> findAllTeachers();
}

View File

@ -1,6 +1,8 @@
package ovh.herisson.Clyde.Services;
import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Tables.InscriptionRequest;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.Token;
import ovh.herisson.Clyde.Tables.User;
@ -11,10 +13,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){
@ -30,4 +34,34 @@ public class AuthenticatorService {
tokenService.saveToken(new Token(user, token,expirationDate));
return token;
}
public void register(InscriptionRequest inscriptionRequest) {
inscriptionService.save(inscriptionRequest);
}
public boolean isNotSecretaryOrAdmin(String authorization){
if (authorization ==null)
return true;
User poster = getUserFromToken(authorization);
if (poster == null) return true;
return poster.getRole() != Role.Secretary || poster.getRole() != Role.Admin;
}
public boolean IsNotIn(Role[] roles, String token){
if (token == null)
return true;
User poster = getUserFromToken(token);
if (poster == null) return true;
for (Role r:roles){
if (poster.getRole() == r)
return false;
}
return true;
}
}

View File

@ -0,0 +1,55 @@
package ovh.herisson.Clyde.Services;
import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.CourseRepository;
import ovh.herisson.Clyde.Tables.Course;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User;
import java.util.Map;
@Service
public class CourseService {
private final CourseRepository courseRepo;
public CourseService(CourseRepository courseRepo) {
this.courseRepo = courseRepo;
}
public Course save(Course course){
return courseRepo.save(course);
}
public Course findById(long id){
return courseRepo.findById(id);
}
public Course modifyData(long id, Map<String, Object> updates, Role role) {
Course target = courseRepo.findById(id);
if (role == Role.Teacher){
for (Map.Entry<String, Object> entry : updates.entrySet()){
if (entry.getKey().equals("title")){
target.setTitle((String) entry.getValue());
return courseRepo.save(target);
}
}
}
for (Map.Entry<String ,Object> entry: updates.entrySet()){
switch (entry.getKey()){
case "title":
target.setTitle((String) entry.getValue());
break;
case "credits":
target.setCredits((Integer) entry.getValue());
break;
case "owner":
target.setOwner((User) entry.getValue()); //todo check if is a teacher !
break;
}
}
return courseRepo.save(target);
}
}

View File

@ -0,0 +1,68 @@
package ovh.herisson.Clyde.Services;
import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.CourseRepository;
import ovh.herisson.Clyde.Repositories.CurriculumCourseRepository;
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
import ovh.herisson.Clyde.Tables.Course;
import ovh.herisson.Clyde.Tables.Curriculum;
import ovh.herisson.Clyde.Tables.CurriculumCourse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@Service
public class CurriculumCourseService {
private final CurriculumCourseRepository curriculumCourseRepo;
private final CourseRepository courseRepo;
private final CurriculumRepository curriculumRepo;
public CurriculumCourseService(CurriculumCourseRepository curriculumCourseRepository, CourseRepository courseRepo, CurriculumRepository curriculumRepo) {
this.curriculumCourseRepo = curriculumCourseRepository;
this.courseRepo = courseRepo;
this.curriculumRepo = curriculumRepo;
}
public void save(CurriculumCourse curriculumCourse){
curriculumCourseRepo.save(curriculumCourse);
}
public Iterable<CurriculumCourse> findAll(){
return curriculumCourseRepo.findAll();
}
public Map<String, Object> getDepthCurriculum(Curriculum curriculum){
HashMap<String ,Object> toReturn = new HashMap<>();
ArrayList<Course> courses = new ArrayList<>();
for (Course c: curriculumCourseRepo.findCoursesByCurriculum(curriculum)){
courses.add(c);
}
toReturn.put("courses",courses);
toReturn.put("curriculumId", curriculum.getCurriculumId());
toReturn.put("year", curriculum.getYear());
toReturn.put("option", curriculum.getOption());
return toReturn;
}
public Iterable<Map<String, Object>> getAllDepthCurriculum(){
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
for (Curriculum curriculum : curriculumCourseRepo.findDistinctCurriculums()){
toReturn.add(getDepthCurriculum(curriculum));
}
return toReturn;
}
}

View File

@ -0,0 +1,32 @@
package ovh.herisson.Clyde.Services;
import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.CourseRepository;
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
import ovh.herisson.Clyde.Tables.Curriculum;
@Service
public class CurriculumService {
private final CurriculumRepository curriculumRepo;
private final CourseRepository courseRepo;
public CurriculumService(CurriculumRepository curriculumRepo, CourseRepository courseRepo){
this.curriculumRepo = curriculumRepo;
this.courseRepo = courseRepo;
}
public void save(Curriculum curriculum){
curriculumRepo.save(curriculum);
}
public Curriculum findById(long id){
return curriculumRepo.findById(id);
}
public Iterable<Curriculum> findAll(){
return curriculumRepo.findAll();
}
}

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 ovh.herisson.Clyde.Tables.RequestState;
@Service
public class InscriptionService {
InscriptionRepository inscriptionRepo;
public InscriptionService(InscriptionRepository inscriptionRepo){
this.inscriptionRepo = inscriptionRepo;
}
public void save(InscriptionRequest inscriptionRequest){
inscriptionRepo.save(inscriptionRequest);
}
public InscriptionRequest getById(long id){
return inscriptionRepo.findById(id);
}
public Iterable<InscriptionRequest> getAll(){
return inscriptionRepo.findAll();
}
public void modifyState(long id, RequestState requestState) {
InscriptionRequest inscriptionRequest = getById(id);
inscriptionRequest.setState(requestState);
save(inscriptionRequest);
}
}

View File

@ -4,10 +4,8 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import ovh.herisson.Clyde.Repositories.FileRepository;
import ovh.herisson.Clyde.Tables.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

View File

@ -0,0 +1,39 @@
package ovh.herisson.Clyde.Services;
import org.springframework.stereotype.Controller;
import ovh.herisson.Clyde.Repositories.TeacherCourseRepository;
import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Tables.Course;
import ovh.herisson.Clyde.Tables.TeacherCourse;
import ovh.herisson.Clyde.Tables.User;
import java.util.ArrayList;
@Controller
public class TeacherCourseService {
private final TeacherCourseRepository teacherCourseRepo;
private final UserRepository userRepo;
public TeacherCourseService(TeacherCourseRepository teacherCourseRepo, UserRepository userRepo) {
this.teacherCourseRepo = teacherCourseRepo;
this.userRepo = userRepo;
}
public boolean saveAll(Iterable<Long> teacherIds, Course course){
ArrayList<Long> addedIds = new ArrayList<>();
for (Long teacherId : teacherIds){
User teacher = userRepo.findById((long) teacherId);
if ( teacher== null){
return false;
}
if (!addedIds.contains(teacherId))
{
teacherCourseRepo.save(new TeacherCourse(teacher,course));
addedIds.add(teacherId);
}
}
return true;
}
}

View File

@ -5,16 +5,15 @@ import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.TokenRepository;
import ovh.herisson.Clyde.Tables.Token;
import ovh.herisson.Clyde.Tables.User;
import java.io.UnsupportedEncodingException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Calendar;
import java.util.Date;
@Service
public class TokenService {
TokenRepository tokenRepo;
private final TokenRepository tokenRepo;
public TokenService(TokenRepository tokenRepo){
this.tokenRepo = tokenRepo;
@ -30,13 +29,10 @@ public class TokenService {
new SecureRandom().nextBytes(bytes);
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) (((bytes[i]+256)%256 %95+ 32));
while ((char)bytes[i] == ';'){
bytes[i] = new SecureRandom().generateSeed(1)[0];
}
}
// will never end up in the catch because of the way that SecureRandom.nextBytes is implemented
try {
return new String(bytes,"ISO_8859_1");
return new String(Base64.getEncoder().encode(bytes),"ISO_8859_1");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}

View File

@ -102,4 +102,8 @@ public class UserService {
public Iterable<User> getAll(){
return userRepo.findAll();
}
public Iterable<User> getAllTeachers (){return userRepo.findAllTeachers();}
}

View File

@ -0,0 +1,21 @@
package ovh.herisson.Clyde.Tables;
public enum Applications {
// without any token
Login,
// with any token
Profile,
// Students and higher authorization
Msg,
Forum,
Rdv,
// teachers and Secretary authorization
ManageCourses,
// InscriptionService authorization
Inscription
}

View File

@ -1,9 +1,6 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.*;
@Entity
public class Course {
@ -12,12 +9,15 @@ public class Course {
private int courseID;
private int credits;
private String title;
private String faculty;
public Course(int credits, String title, String faculty){
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "Users")
private User owner;
public Course(int credits, String title, User owner){
this.credits = credits;
this.title = title;
this.faculty = faculty;
this.owner = owner;
}
public Course() {}
@ -34,14 +34,6 @@ public class Course {
this.credits = credits;
}
public String getFaculty() {
return faculty;
}
public void setFaculty(String faculty){
this.faculty = faculty;
}
public String getTitle() {
return title;
}
@ -49,4 +41,12 @@ public class Course {
public void setTitle(String title){
this.title = title;
}
public User getOwner() {
return owner;
}
public void setOwner(User owner) {
this.owner = owner;
}
}

View File

@ -6,22 +6,21 @@ import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
@Entity
public class Cursus {
public class Curriculum {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int cursusId;
private int curriculumId;
private int year;
private String option;
public Cursus(int year, String option){
public Curriculum(int year, String option){
this.year = year;
this.option = option;
}
public Cursus() {}
public Curriculum() {}
public int getCursusId(){
return this.cursusId;
public int getCurriculumId(){
return this.curriculumId;
}
public int getYear(){

View File

@ -0,0 +1,45 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*;
@Entity
public class CurriculumCourse {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "Curriculum")
private Curriculum curriculum;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "Course")
private Course course;
public CurriculumCourse(Curriculum curriculum, Course course){
this.curriculum = curriculum;
this.course = course;
}
public CurriculumCourse() {}
public int getId() {
return id;
}
public Course getCourse() {
return course;
}
public void setCourse(Course course){
this.course = course;
}
public Curriculum getCurriculum() {
return curriculum;
}
public void setCurriculum(Curriculum curriculum) {
this.curriculum = curriculum;
}
}

View File

@ -1,45 +0,0 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*;
@Entity
public class CursusCourse {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Cursus")
private Cursus cursus;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Course")
private Course course;
public CursusCourse(Cursus cursus, Course course){
this.cursus = cursus;
this.course = course;
}
public CursusCourse() {}
public int getId() {
return id;
}
public Course getCourse() {
return course;
}
public void setCourse(Course course){
this.course = course;
}
public Cursus getCursus() {
return cursus;
}
public void setCursus(Cursus cursus) {
this.cursus = cursus;
}
}

View File

@ -12,25 +12,29 @@ public class InscriptionRequest {
private int id;
private String firstName;
private String lastName;
private String adress;
private String address;
private String email;
private String country;
private Date birthDate;
@ManyToOne
@JoinColumn(name="Cursus")
private Cursus cursus;
@JoinColumn(name="Curriculum")
private Curriculum curriculum;
private RequestState state;
private String profilePicture;
private String password;
public InscriptionRequest(){}
public InscriptionRequest(String lastName, String firstName, String adress, String email, String country, Date birthDate, RequestState state, String profilePicture){
public InscriptionRequest(String lastName, String firstName, String address, String email, String country, Date birthDate, RequestState state, String profilePicture, String password){
this.lastName = lastName;
this.firstName = firstName;
this.adress = adress;
this.address = address;
this.email = email;
this.country = country;
this.birthDate = birthDate;
this.state = state;
this.profilePicture = profilePicture;
this.password = password;
}
public int getId() {
@ -53,12 +57,12 @@ public class InscriptionRequest {
this.lastName = lastName;
}
public String getAdress() {
return adress;
public String getAddress() {
return address;
}
public void setAdress(String adress) {
this.adress = adress;
public void setAddress(String address) {
this.address = address;
}
public String getEmail() {
@ -85,12 +89,12 @@ public class InscriptionRequest {
this.birthDate = birthDate;
}
public Cursus getCursus() {
return cursus;
public Curriculum getCurriculum() {
return curriculum;
}
public void setCursus(Cursus cursus) {
this.cursus = cursus;
public void setCurriculum(Curriculum curriculum) {
this.curriculum = curriculum;
}
public RequestState getState() {

View File

@ -1,39 +1,38 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.*;
@Entity
public class ReinscriptionRequest {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@ManyToOne
@JoinColumn(name = "User")
@JoinColumn(name = "Users")
private User user;
@ManyToOne
@JoinColumn(name = "Cursus")
private Cursus newCursus;
@JoinColumn(name = "Curriculum")
private Curriculum newCurriculum;
private RequestState state;
//Permet de différencier les demandes de changement et une réinscription dans le même cursus
//Permet de différencier les demandes de changement et une réinscription dans le même Curriculum
//Pour la réinscription on va le mettre a 0
private boolean type = false;
public ReinscriptionRequest(){}
public ReinscriptionRequest(User user, Cursus newCursus, RequestState state, boolean type){
public ReinscriptionRequest(User user, Curriculum newCurriculum, RequestState state, boolean type){
this.user = user;
this.newCursus = newCursus;
this.newCurriculum = newCurriculum;
this.state = state;
this.type = type;
}
public ReinscriptionRequest(User user, Cursus newCursus, RequestState state){
public ReinscriptionRequest(User user, Curriculum newCurriculum, RequestState state){
this.user = user;
this.newCursus = newCursus;
this.newCurriculum = newCurriculum;
this.state = state;
}
@ -49,12 +48,12 @@ public class ReinscriptionRequest {
this.user = user;
}
public Cursus getNewCursus() {
return newCursus;
public Curriculum getNewCurriculum() {
return newCurriculum;
}
public void setNewCursus(Cursus newCursus) {
this.newCursus = newCursus;
public void setNewCurriculum(Curriculum newCurriculum) {
this.newCurriculum = newCurriculum;
}
public RequestState getState() {

View File

@ -3,5 +3,5 @@ package ovh.herisson.Clyde.Tables;
public enum RequestState {
Accepted,
Refused,
Pending;
Pending
}

View File

@ -5,5 +5,5 @@ public enum Role {
Student,
Admin,
InscriptionService,
Secretary;
}
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

@ -3,30 +3,26 @@ package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*;
@Entity
public class TeacherGivenCourse {
public class TeacherCourse {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "Users")
private User user;
@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "Course")
private Course course;
//This flag helps make the difference between an assistant or a Teacher (who owns the course)
private boolean owned;
public TeacherGivenCourse(User user, Course course, boolean owned){
public TeacherCourse(User user, Course course){
this.user = user;
this.course = course;
this.owned = owned;
}
public TeacherGivenCourse() {}
public TeacherCourse() {}
public int getId() {
return id;
@ -48,11 +44,4 @@ public class TeacherGivenCourse {
this.course = course;
}
public boolean isOwned() {
return owned;
}
public void setOwned(boolean owned) {
this.owned = owned;
}
}

View File

@ -0,0 +1,46 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*;
@Entity
public class UserCurriculum {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
//Un étudiant peut avoir plusieurs curriculums
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "Users")
private User user;
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "Curriculum")
private Curriculum curriculum;
public UserCurriculum(User user, Curriculum curriculum){
this.user = user;
this.curriculum = curriculum;
}
public UserCurriculum() {}
public int getId() {
return id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Curriculum getCurriculum() {
return curriculum;
}
public void setCurriculum(Curriculum curriculum) {
this.curriculum = curriculum;
}
}

View File

@ -1,46 +0,0 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*;
@Entity
public class UserCursus {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
//Un étudiant peut avoir plusieurs cursus
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Users")
private User user;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Cursus")
private Cursus cursus;
public UserCursus(User user, Cursus cursus){
this.user = user;
this.cursus = cursus;
}
public UserCursus() {}
public int getId() {
return id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Cursus getCursus() {
return cursus;
}
public void setCursus(Cursus cursus) {
this.cursus = cursus;
}
}

View File

@ -1,37 +1,22 @@
<script setup>
import { toast } from 'vue3-toastify';
import { ref, computed } from 'vue'
import { ref } from 'vue'
import i18n, { setLang } from './i18n.js'
import { isLogged } from '@/rest/Users.js'
// 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,
'/profil': Profil,
'/manage-courses' : Courses,
}
const currentPath = ref(window.location.hash)
window.addEventListener('hashchange', () => {
currentPath.value = window.location.hash
})
const currentView = computed(() => {
return apps[currentPath.value.slice(1) || '/']
})
import { appList, currentView } from '@/rest/apps.js'
const home=ref(i18n("app.home"))
const notifications=ref(i18n("app.notifications"))
const settings=ref(i18n("app.settings"))
const login=ref(i18n("app.login"))
const active=ref(false)
const Logged = ref(isLogged());
const apps = ref([])
appList().then(e => apps.value = e)
</script>
<template>
@ -45,11 +30,11 @@
</a></li>
<li title=home>
<a class="icon" href="#home">
<div class=" fa-solid fa-house" style="margin-top: 7px; margin-bottom: 3px;"></div>
<div class=" fa-solid fa-house" style="margin-top: 7px; margin-bottom: 3px;"></div>
</a></li>
<li style="float: right;" title=login>
<a class="icon" href="#/login">
<div class="fa-solid fa-user" style="margin-top: 7px; margin-bottom: 3px;"></div>
<div class="fa-solid fa-user" :style="Logged ? 'color: orange' : 'haha'" style="margin-top: 7px; margin-bottom: 3px; "></div>
</a></li>
<li style="float: right;" title=notifications>
<a class="icon" href="#Notifications">
@ -80,31 +65,12 @@
<div class="leftBar">
<ul class="vertical">
<li style="margin-top: 25px;" >
<a href="#Messages">
<div class="fa-solid fa-comment" style="font-size: 40px;"></div>
<div class="text">{{i18n("app.messages")}}</div>
</a></li>
<li >
<a href="#Notifications">
<div class="fa-solid fa-bell" style="font-size: 40px;" ></div>
<div class="text">{{i18n("app.notifications")}}</div>
</a></li>
<li >
<a href="#Schedule">
<div class="fa-solid fa-calendar-days" style="font-size: 40px;"></div>
<div class="text">{{i18n("app.schedules")}}</div>
</a></li>
<li ><a href="#Forum">
<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="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>
<li v-for="app in apps">
<a href="app.path">
<div class="fa-solid" :class="app.icon" style="font-size: 40px;"></div>
<div class="text">{{app.text}}</div>
</a>
</li>
</ul>
</div>
@ -273,3 +239,5 @@
}
</style>
<!-- vim:set noet sts=0 sw=4 ts=2: -->

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,32 +1,28 @@
<script setup>
import { ref } from 'vue'
import i18n from '@/i18n.js'
import { login , register } from '@/rest/Users.js'
import { login , register, disconnect } 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 curriculum=ref("")
const imageSaved = ref(false)
const ppData = ref(false)
disconnect()
</script>
@ -34,17 +30,17 @@
<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>
@ -56,7 +52,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, curriculum)" class="form">
<h1 style="color:rgb(239,60,168); font-family: sans-serif; text-align:center;">
{{i18n("login.guest.welcome")}}
</h1>
@ -75,11 +71,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">
@ -93,7 +90,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>
@ -109,7 +106,7 @@
</form>
<div class="inputBox">
<p>{{i18n("curriculum").toUpperCase()}}</p>
<select v-model="cursus">
<select v-model="curriculum">
<option value="Chemistry">Chemistry</option>
<option value="Psycho">Psychology</option>
<option value="IT">IT</option>

View File

@ -1,7 +1,7 @@
<script setup>
import i18n from "@/i18n.js"
import {ref} from 'vue'
const cursus=[
const curriculum=[
{
"id": 12,
"name": "Math pour l'info",
@ -51,8 +51,8 @@ const cursus=[
let toAdd = Object.assign({}, pattern);
function addToCourse (){
if (cursus.length>0){
toAdd.id=(cursus[cursus.length-1].id)-1;}
if (curriculum.length>0){
toAdd.id=(curriculum[curriculum.length-1].id)-1;}
else{
toAdd.id=0;
}
@ -63,7 +63,7 @@ const cursus=[
}
}
if (!isnull){
cursus.push(toAdd);
curriculum.push(toAdd);
}
toAdd= Object.assign({},pattern);
}
@ -76,7 +76,7 @@ const cursus=[
console.log("ok");
console.log(toRemove);
let rem=-1;
for(const [key, value] of Object.entries(cursus)){
for(const [key, value] of Object.entries(curriculum)){
console.log(key);
console.log(value)
if(value.name === toRemove){
@ -86,8 +86,8 @@ const cursus=[
}
console.log(rem)
if (rem > -1){
cursus.splice(rem, 1);}
console.log(cursus);
curriculum.splice(rem, 1);}
console.log(curriculum);
}
</script>
@ -130,7 +130,7 @@ const cursus=[
<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>
<option v-for="item in curriculum">{{item.name}}</option>
</select>
</div>
@ -147,7 +147,7 @@ const cursus=[
</form>
</div>
<div v-if="!createMod && !deleteMod" v-for="item in cursus" :key="item.name">
<div v-if="!createMod && !deleteMod" v-for="item in curriculum" :key="item.name">
<div style ="padding:15px 15px 15px 15px;">
<button v-if="editElementID !== item.name" @click="editElementID = item.name">
{{i18n("courses.modify")}}

View File

@ -12,7 +12,7 @@
role:"student",
address: "Radiator Springs",
email:"ClydeGhost@gmail.com",
cursus:[
curriculum:[
{
"id": 12,
"name": "Math pour l'info",
@ -132,7 +132,7 @@ const toModify = Object.assign({}, user);
{{i18n("profile.course.list")}}
</div>
<div class="listElement "
v-for="item in user.cursus">
v-for="item in user.curriculum">
<div class=" containerElement">
<div class="name"> {{item.name}} </div>
<div class="teacher">{{item.teacher}}</div>

View File

@ -8,7 +8,7 @@
address: String,
country: String,
birthDate: String,
cursus:String,
curriculum:String,
degree:String,});
</script>

View File

@ -3,33 +3,39 @@
*
* TODO: On time of writing, the backend doesn't support these endpoints so it could be modified in the future.
*/
import { restGet } from './restConsumer.js'
import {restGet, restPatch} from './restConsumer.js'
/**
* create a new register requests that can be recovered by the registering service
* TODO: add info in the Object (I don't know what will be needed)
*/
export async function createRegister(){
return restPost("/requests/register"});
return restPost("/request/register");
}
/**
* 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
* - curriculum
* - degree
*/
export async function getRegisters(id){
return restGet("/requests/register/" + id);
if(id != null)
return restGet("/request/register/" + id);
return restGet("/request/register")
}
/**
* Change the state of a requests.
*/
export async function validateRegister(id, state){
return restPost("/requests/register/" + id, {state: state});
return restPatch("/request/register/" + id, {state: state});
}

View File

@ -1,11 +1,69 @@
import { restGet, restPost } from './restConsumer.js'
import { getCookie, setCookie } from '@/utils.js'
export async function login(user, pass, exp){
return restPost("/login", {identifier: user, password: pass, expirationDate: exp});
}
export async function register(user, pass, mail){
return restPost("/user", {name: user, password: pass, mail: mail});
export function isLogged(){
return getCookie("session_token") != ""
}
export function disconnect(){
setCookie("session_token", ";expires= Thu, 01 Jan 1970 00:00:01 GMT")
}
/**
* Register a user (tokenless)
*
* @param firstname
* @param lastname
* @param birthdate
* @param password
* @param mail
* @param address
* @param country
* @param curriculum
* @param imageId id of the image in database returned when uploaded
*/
export async function register(firstname, lastname, birthDate, password, email, address, country, curriculum, imageId){
return restPost("/register", {
firstname: firstname,
lastname: lastname,
birthDate: birthDate,
password: password,
email: email,
address: address,
country: country,
curriculum: curriculum
});
}
/**
* 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,
});
}
/**

60
frontend/src/rest/apps.js Normal file
View File

@ -0,0 +1,60 @@
import { restGet } from './restConsumer.js'
import { ref, computed } from 'vue'
import i18n from '@/i18n.js'
// 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,
'/profil': Profil,
'/manage-courses' : Courses,
}
const appsList = {
'Msg': { path: '#/msg', icon: 'fa-comment', text: i18n("app.messages") },
'Notification': { path: '#/notifs', icon: 'fa-bell', text: i18n("app.notifications") },
'Forum': { path: '#/forum', icon: 'fa-envelope', text: i18n("app.forum") },
'Schedule': { path: '#/schedule', icon: 'fa-calendar-days', text: i18n("app.schedules") },
'Inscription': { path: '#/inscription', icon: 'fa-users', text: i18n("app.inscription.requests") },
'ManageCourses': { path: '#/manage-courses', icon: 'fa-book', text: i18n("app.manage.courses") },
}
const currentPath = ref(window.location.hash)
export const currentView = computed(() => {
return apps[currentPath.value.slice(1) || '/']
})
/**
* Return the list of app accesible by a logged (or not)
* user.
*/
export async function appList(){
let ret = [];
let userAppList = await restGet("/apps");
for (let userapp in userAppList) {
if(appsList[userAppList[userapp]] != null){
ret.push(appsList[userAppList[userapp]])
}
}
return ret;
}
/**
* Check if the specified page is authorized for the
* user
*/
export async function checkPage(page){
return restGet("/apps/" + page)
}
window.addEventListener('hashchange', () => {
currentPath.value = window.location.hash
})
// vim:set noet sts=0 sw=4 ts=2 tw=2:

View File

@ -0,0 +1,41 @@
/**
* curriculum API
*/
import { restGet, restPostn, restDelete, restPatch } from './restConsumer.js'
/**
* Create a new curriculum (bundle of courses)
* @param courses list of courses
*/
export async function createcurriculum(courses){
return restPost("/curriculum", {courses: courses} );
}
/**
* Delete the specified curriculum
*/
export async function deletecurriculum(id){
return restDelete("/curriculum/" + id);
}
/**
* Get informations on a particular curriculum
*
* @param id identification of the curriculum
*
* @return list of courses
*/
export async function getcurriculum(id){
return restGet("/curriculum/" + id);
}
/**
* Modify the courses of a curriculum
*
* @param id the id of the curriculum
* @param courses list of new courses
*/
export async function altercurriculum(id, courses){
return restPatch("/curriculum/" + id, courses);
}

View File

@ -1,41 +0,0 @@
/**
* cursus API
*/
import { restGet, restPostn, restDelete, restPatch } from './restConsumer.js'
/**
* Create a new cursus (bundle of courses)
* @param courses list of courses
*/
export async function createCursus(courses){
return restPost("/cursus", {courses: courses} );
}
/**
* Delete the specified cursus
*/
export async function deleteCursus(id){
return restDelete("/cursus/" + id);
}
/**
* Get informations on a particular cursus
*
* @param id identification of the cursus
*
* @return list of courses
*/
export async function getCursus(id){
return restGet("/cursus/" + id);
}
/**
* Modify the courses of a cursus
*
* @param id the id of the cursus
* @param courses list of new courses
*/
export async function alterCursus(id, courses){
return restPatch("/cursus/" + id, courses);
}

View File

@ -46,7 +46,6 @@ async function _rest(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){
console.log(res);
return res.data.ok ? "Success" : "error";
}},
})