diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 8239a07..35ed21a 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -53,5 +53,5 @@ jobs: scp -o "StrictHostKeyChecking=no" -o "LogLevel=ERROR" -i key -r * ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:api/ - name: restarting the backend run: | - ssh -o "StrictHostKeyChecking=no" -o "LogLevel=ERROR" -i key ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "cd api/backend && docker build -t clyde/backend . && docker rm clyde_backend_prod -f || true && docker run --rm -d --name clyde_backend_prod -p 4000:8080 clyde/backend && docker image prune -f" + ssh -o "StrictHostKeyChecking=no" -o "LogLevel=ERROR" -i key ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} 'cd api/backend && docker build -t clyde/backend . && docker rm clyde_backend_prod -f || true && docker run --rm -d -u $(id -u clyde):$(id -g clyde) -v /var/run/postgresql:/var/run/postgresql --name clyde_backend_prod -p 4000:8080 clyde/backend && docker image prune -f' - run: echo "The backend has been deployed. running at https://clyde.herisson.ovh/api" diff --git a/.gitignore b/.gitignore index 24a8972..93aac47 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ build .project .settings +.idea/ diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 007222b..ae0a6c9 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -20,6 +20,8 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-mail") implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter-data-jpa") + implementation("com.kohlschutter.junixsocket:junixsocket-core:2.9.0") // implementation("org.springframework.session:spring-session-jdbc") developmentOnly("org.springframework.boot:spring-boot-devtools") developmentOnly("org.springframework.boot:spring-boot-docker-compose") diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java new file mode 100644 index 0000000..affb301 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java @@ -0,0 +1,44 @@ +package ovh.herisson.Clyde.EndPoints; + + +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import ovh.herisson.Clyde.Repositories.UserRepository; +import ovh.herisson.Clyde.Tables.User; + + +@RestController +@CrossOrigin(origins = "http://localhost:5173") +public class UserController { + + private final UserRepository userRepo; + + public UserController(UserRepository userRepo){ + this.userRepo = userRepo; + } + + @GetMapping("/user") + public ResponseEntity getUsers(@RequestHeader("Authorization") String token){ + //TODO + // Get the token thru the data base + // tokenRepo.findToken(token) => User userFromToken + // si role != secretary => return error : ResponseEntity(null, HttpStatus.UNAUTHORIZED) + return new ResponseEntity(/**userRepo.findById(userFromToken.id),**/ HttpStatus.OK); + } + + @PostMapping("/user") + public ResponseEntity postUser(@RequestBody User user){ + userRepo.save(user); + return new ResponseEntity(String.format("Account created with ID:%s",user.getRegNo()),HttpStatus.CREATED); + } + + @GetMapping("/users") + public Iterable getAllUsers(){//TODO ne l'accepter que si c'est le secrétariat + return userRepo.findAll(); + } + + +} + diff --git a/backend/src/main/java/ovh/herisson/Clyde/JdbcConfig.java b/backend/src/main/java/ovh/herisson/Clyde/JdbcConfig.java index c310d52..2fb978c 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/JdbcConfig.java +++ b/backend/src/main/java/ovh/herisson/Clyde/JdbcConfig.java @@ -29,7 +29,7 @@ public class JdbcConfig { public DataSource psqlSourceProd(){ DriverManagerDataSource source = new DriverManagerDataSource(); source.setDriverClassName("org.postgresql.Driver"); - source.setUrl("jdbc:postgresql://localhost:5432/clyde"); + source.setUrl("jdbc:postgresql:clyde?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg=/var/run/postgresql/.s.PGSQL.5432"); source.setUsername("clyde"); return source; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserRepository.java new file mode 100644 index 0000000..38f9ae0 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserRepository.java @@ -0,0 +1,16 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.User; + +import java.util.List; + +public interface UserRepository extends CrudRepository { + + User findById(long id); + + /** + @Query(value = "select a.* from Users a ",nativeQuery = true) + Iterable findAllUsers();**/ +} \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java new file mode 100644 index 0000000..54e167a --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java @@ -0,0 +1,52 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Course { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int courseID; + private int credits; + private String title; + private String faculty; + + public Course(int credits, String title, String faculty){ + this.credits = credits; + this.title = title; + this.faculty = faculty; + } + + public Course() {} + + public int getCourseID() { + return courseID; + } + + public int getCredits() { + return credits; + } + + public void setCredits(int credits){ + this.credits = credits; + } + + public String getFaculty() { + return faculty; + } + + public void setFaculty(String faculty){ + this.faculty = faculty; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title){ + this.title = title; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java new file mode 100644 index 0000000..5167197 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Cursus.java @@ -0,0 +1,43 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Cursus { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int cursusId; + private int year; + private String option; + + public Cursus(int year, String option){ + this.year = year; + this.option = option; + } + + public Cursus() {} + + public int getCursusId(){ + return this.cursusId; + } + + public int getYear(){ + return this.year; + } + + public void setYear(int year){ + this.year = year; + } + + public String getOption(){ + return this.option; + } + + public void setOption(String option){ + this.option = option; + } + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java new file mode 100644 index 0000000..e48e6a3 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/CursusCourse.java @@ -0,0 +1,43 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +@Entity +public class CursusCourse { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @JoinColumn(name = "Cursus") + private int cursusId; + + @JoinColumn(name = "Course") + private int courseId; + + public CursusCourse(int cursusId, int courseId){ + this.cursusId = cursusId; + this.courseId = courseId; + } + + public CursusCourse() {} + + public int getId() { + return id; + } + + public int getCourseId() { + return courseId; + } + + public void setCourseId(int courseId){ + this.courseId = courseId; + } + + public int getCursusId() { + return cursusId; + } + + public void setCursusId(int cursusId) { + this.cursusId = cursusId; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java new file mode 100644 index 0000000..bb14f3f --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Role.java @@ -0,0 +1,8 @@ +package ovh.herisson.Clyde.Tables; + +public enum Role { + Teacher, + Student, + Admin, + Secretary; +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Secretary.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Secretary.java new file mode 100644 index 0000000..cf533a0 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Secretary.java @@ -0,0 +1,41 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +@Entity +public class Secretary { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @JoinColumn(name = "Users") + private int regNo; + private String faculty; + + public Secretary(int regNo, String faculty){ + this.regNo = regNo; + this.faculty = faculty; + } + + public Secretary() {} + + public int getId() { + return id; + } + + public int getRegNo() { + return regNo; + } + + public void setRegNo(int regNo) { + this.regNo = regNo; + } + + public String getFaculty() { + return faculty; + } + + public void setFaculty(String faculty) { + this.faculty = faculty; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherGivenCourse.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherGivenCourse.java new file mode 100644 index 0000000..9cb931e --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherGivenCourse.java @@ -0,0 +1,55 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +@Entity +public class TeacherGivenCourse { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @JoinColumn(name = "Users") + private int regNo; + + @JoinColumn(name = "Course") + private int courseId; + + //This flag helps make the difference between an assistant or a Teacher (who owns the course) + private boolean owned; + + public TeacherGivenCourse(int regNo, int courseId, boolean owned){ + this.regNo = regNo; + this.courseId = courseId; + this.owned = owned; + } + + public TeacherGivenCourse() {} + + public int getId() { + return id; + } + + public int getRegNo() { + return regNo; + } + + public void setRegNo(int regNo) { + this.regNo = regNo; + } + + public int getCourseId() { + return courseId; + } + + public void setCourseId(int courseId) { + this.courseId = courseId; + } + + public boolean isOwned() { + return owned; + } + + public void setOwned(boolean owned) { + this.owned = owned; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java new file mode 100644 index 0000000..ec59cbf --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java @@ -0,0 +1,40 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +@Entity +public class Token { + @GeneratedValue(strategy = GenerationType.AUTO) + @Id + private int id; + + @JoinColumn(name ="Users") + private int regNo; + private String token; + + public Token(int regNo, String token){ + this.regNo = regNo; + this.token = token; + } + + public Token(){} + public int getId() { + return id; + } + + public int getRegNo() { + return regNo; + } + + public void setRegNo(int regNo) { + this.regNo = regNo; + } + + public String getToken(){ + return token; + } + + public void setToken(String data) { + this.token = data; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java new file mode 100644 index 0000000..746ac3b --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java @@ -0,0 +1,103 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +import java.util.Date; + +//Classe représentant un utilisateur l'attribut password demande surement un peu de rafinement niveau sécurité +//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 String lastName; + private String firstName; + private String email; + private String address; + private String country; + private Date birthDate; + private ovh.herisson.Clyde.Tables.Role role; + private String password; + public User(String lastName, String firstName, String email, String address, String country, Date birthDate, Role role, String password){ + this.lastName = lastName; + this.firstName = firstName; + this.email = email; + this.address = address; + this.country = country; + this.birthDate = birthDate; + this.role = role; + this.password = password; + } + + public User() {} + + public int getRegNo(){ + return this.regNo; + } + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getAddress() { + return address; + } + + public void setAddress(String adress) { + this.address = adress; + } + + 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 ovh.herisson.Clyde.Tables.Role getRole() { + return role; + } + + public void setRole(ovh.herisson.Clyde.Tables.Role role) { + this.role = role; + } + public String getPassword(){ + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java new file mode 100644 index 0000000..4de1559 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCursus.java @@ -0,0 +1,42 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +@Entity +public class UserCursus { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + @JoinColumn(name = "Users") + private int regNo; + + @JoinColumn(name = "Cursus") + private int cursusId; + + public UserCursus(int regNo, int cursusId){ + this.regNo = regNo; + this.cursusId = cursusId; + } + + public UserCursus() {} + + public int getId() { + return id; + } + + public int getRegNo() { + return regNo; + } + + public void setRegNo(int regNo) { + this.regNo = regNo; + } + + public int getCursusId() { + return cursusId; + } + + public void setCursusId(int cursusId) { + this.cursusId = cursusId; + } +} diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index ef0c300..df288a6 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -1 +1,2 @@ +spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect diff --git a/frontend/login.html b/frontend/login/index.html similarity index 100% rename from frontend/login.html rename to frontend/login/index.html diff --git a/frontend/src/i18n.js b/frontend/src/i18n.js index 2b0a2a4..eaf2dac 100644 --- a/frontend/src/i18n.js +++ b/frontend/src/i18n.js @@ -24,7 +24,7 @@ let langs; * * @return :string The translated text */ -function i18n(key, options) { +export default function i18n(key, options) { let ret = langs[key]; if(options != null){ for (let key in options) { @@ -34,14 +34,6 @@ function i18n(key, options) { return ret; } -async function reloadLang(){ - langs = await loadLangs(); -} -reloadLang(); - -export default i18n; - - // // Those functions are utility functions use by previous exported functions. // @@ -51,11 +43,11 @@ export default i18n; * @param select the language to load. could be null to fetch the cookies for an answer * if nothing is found. default to EN.txt */ -async function loadLangs(lang){ +export async function loadLangs(lang){ lang = lang != null ? lang : getCookie("lang"); lang = lang != "" ? lang : default_lang; - const filename = "./i18n/" + lang.toUpperCase() + ".txt"; + const filename = "/i18n/" + lang.toUpperCase() + ".txt"; const content = await (await fetch(filename)).text(); const lines = content.split("\n"); @@ -66,5 +58,6 @@ async function loadLangs(lang){ filteredLines[line.substr(0, split)] = line.substr(split+1, line.length); }; } - return filteredLines; + langs = filteredLines; } +await loadLangs(); diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 5c45e1d..7ff998b 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -8,6 +8,15 @@ export default defineConfig({ plugins: [ vue(), ], + build: { + rollupOptions:{ + input:{ + main: './index.html', + login: './login/index.html' + } + + } + }, resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url))