j'ai envie de me pendre
This commit is contained in:
		@ -1,10 +1,15 @@
 | 
				
			|||||||
package ovh.herisson.Clyde.EndPoints;
 | 
					package ovh.herisson.Clyde.EndPoints;
 | 
				
			||||||
import com.fasterxml.jackson.annotation.JsonFormat;
 | 
					import com.fasterxml.jackson.annotation.JsonFormat;
 | 
				
			||||||
 | 
					import jakarta.persistence.Column;
 | 
				
			||||||
import org.springframework.http.HttpHeaders;
 | 
					import org.springframework.http.HttpHeaders;
 | 
				
			||||||
import org.springframework.http.ResponseEntity;
 | 
					import org.springframework.http.ResponseEntity;
 | 
				
			||||||
import org.springframework.web.bind.annotation.*;
 | 
					import org.springframework.web.bind.annotation.*;
 | 
				
			||||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
 | 
					import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
 | 
				
			||||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
 | 
					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.Date;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -40,6 +45,24 @@ public class LoginController {
 | 
				
			|||||||
        responseHeaders.set("Set-Cookie",String.format("session_token=%s",sessionToken));
 | 
					        responseHeaders.set("Set-Cookie",String.format("session_token=%s",sessionToken));
 | 
				
			||||||
        return ResponseEntity.ok().headers(responseHeaders).build();
 | 
					        return ResponseEntity.ok().headers(responseHeaders).build();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @PostMapping("/register")
 | 
				
			||||||
 | 
					    public ResponseEntity<String> register(@RequestBody InscriptionRequest inscriptionRequest){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        authServ.register(inscriptionRequest);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        String sessionToken = authServ.login();
 | 
				
			||||||
 | 
					        if (sessionToken == null){
 | 
				
			||||||
 | 
					            return new UnauthorizedResponse<>("Identifier or Password incorrect");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        HttpHeaders responseHeaders = new HttpHeaders();
 | 
				
			||||||
 | 
					        responseHeaders.set("Set-Cookie",String.format("session_token=%s",sessionToken));
 | 
				
			||||||
 | 
					        return ResponseEntity.ok().headers(responseHeaders).build();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					package ovh.herisson.Clyde.Repositories;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.springframework.data.repository.CrudRepository;
 | 
				
			||||||
 | 
					import ovh.herisson.Clyde.Tables.InscriptionRequest;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public interface InscriptionRepository extends CrudRepository<InscriptionRequest,Long> {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,6 +1,8 @@
 | 
				
			|||||||
package ovh.herisson.Clyde.Services;
 | 
					package ovh.herisson.Clyde.Services;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.springframework.stereotype.Service;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
 | 
					import ovh.herisson.Clyde.EndPoints.LoginController;
 | 
				
			||||||
 | 
					import ovh.herisson.Clyde.Tables.InscriptionRequest;
 | 
				
			||||||
import ovh.herisson.Clyde.Tables.Token;
 | 
					import ovh.herisson.Clyde.Tables.Token;
 | 
				
			||||||
import ovh.herisson.Clyde.Tables.User;
 | 
					import ovh.herisson.Clyde.Tables.User;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -30,4 +32,9 @@ public class AuthenticatorService {
 | 
				
			|||||||
        tokenService.saveToken(new Token(user, token,expirationDate));
 | 
					        tokenService.saveToken(new Token(user, token,expirationDate));
 | 
				
			||||||
        return token;
 | 
					        return token;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void register(InscriptionRequest inscriptionRequest) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					package ovh.herisson.Clyde.Services;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
 | 
					import ovh.herisson.Clyde.Repositories.InscriptionRepository;
 | 
				
			||||||
 | 
					import ovh.herisson.Clyde.Tables.InscriptionRequest;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Service
 | 
				
			||||||
 | 
					public class InscriptionService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    InscriptionRepository incriptionRepo;
 | 
				
			||||||
 | 
					    public void save(InscriptionRequest inscriptionRequest){
 | 
				
			||||||
 | 
					        incriptionRepo.save(inscriptionRequest);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public InscriptionService(InscriptionRepository inscriptionRepo){
 | 
				
			||||||
 | 
					        this.incriptionRepo = inscriptionRepo;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //todo return sans le mdp
 | 
				
			||||||
 | 
					    public InscriptionRequest getById(int id){
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -13,6 +13,12 @@ public class Cursus {
 | 
				
			|||||||
    private int year;
 | 
					    private int year;
 | 
				
			||||||
    private String option;
 | 
					    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){
 | 
					    public Cursus(int year, String option){
 | 
				
			||||||
        this.year = year;
 | 
					        this.year = year;
 | 
				
			||||||
        this.option = option;
 | 
					        this.option = option;
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					package ovh.herisson.Clyde.Tables;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public enum CursusType {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    infoBab1,
 | 
				
			||||||
 | 
					    chemistryBab1,
 | 
				
			||||||
 | 
					    psychologyBab1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -9,7 +9,7 @@ public class InscriptionRequest {
 | 
				
			|||||||
    private int id;
 | 
					    private int id;
 | 
				
			||||||
    private String firstName;
 | 
					    private String firstName;
 | 
				
			||||||
    private String lastName;
 | 
					    private String lastName;
 | 
				
			||||||
    private String adress;
 | 
					    private String address;
 | 
				
			||||||
    private String email;
 | 
					    private String email;
 | 
				
			||||||
    private String country;
 | 
					    private String country;
 | 
				
			||||||
    private Date birthDate;
 | 
					    private Date birthDate;
 | 
				
			||||||
@ -19,15 +19,19 @@ public class InscriptionRequest {
 | 
				
			|||||||
    private Cursus cursus;
 | 
					    private Cursus cursus;
 | 
				
			||||||
    private RequestState state;
 | 
					    private RequestState state;
 | 
				
			||||||
    private String profilePicture;
 | 
					    private String profilePicture;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String password;
 | 
				
			||||||
    public InscriptionRequest(){}
 | 
					    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.lastName = lastName;
 | 
				
			||||||
        this.firstName = firstName;
 | 
					        this.firstName = firstName;
 | 
				
			||||||
        this.adress = adress;
 | 
					        this.address = address;
 | 
				
			||||||
        this.email = email;
 | 
					        this.email = email;
 | 
				
			||||||
        this.country = country;
 | 
					        this.country = country;
 | 
				
			||||||
        this.birthDate = birthDate;
 | 
					        this.birthDate = birthDate;
 | 
				
			||||||
        this.state = state;
 | 
					        this.state = state;
 | 
				
			||||||
 | 
					        this.profilePicture = profilePicture;
 | 
				
			||||||
 | 
					        this.password = password;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public int getId() {
 | 
					    public int getId() {
 | 
				
			||||||
@ -50,12 +54,12 @@ public class InscriptionRequest {
 | 
				
			|||||||
        this.lastName = lastName;
 | 
					        this.lastName = lastName;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String getAdress() {
 | 
					    public String getAddress() {
 | 
				
			||||||
        return adress;
 | 
					        return address;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void setAdress(String adress) {
 | 
					    public void setAddress(String address) {
 | 
				
			||||||
        this.adress = adress;
 | 
					        this.address = address;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String getEmail() {
 | 
					    public String getEmail() {
 | 
				
			||||||
 | 
				
			|||||||
@ -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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -9,11 +9,11 @@ public class UserCursus {
 | 
				
			|||||||
    private int id;
 | 
					    private int id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Un étudiant peut avoir plusieurs cursus
 | 
					    //Un étudiant peut avoir plusieurs cursus
 | 
				
			||||||
    @ManyToOne(fetch = FetchType.LAZY)
 | 
					    @ManyToOne(fetch = FetchType.EAGER)
 | 
				
			||||||
    @JoinColumn(name = "Users")
 | 
					    @JoinColumn(name = "Users")
 | 
				
			||||||
    private User user;
 | 
					    private User user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @OneToOne(fetch = FetchType.LAZY)
 | 
					    @OneToOne(fetch = FetchType.EAGER)
 | 
				
			||||||
    @JoinColumn(name = "Cursus")
 | 
					    @JoinColumn(name = "Cursus")
 | 
				
			||||||
    private Cursus cursus;
 | 
					    private Cursus cursus;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user