2024-03-18 17:28:14 +01:00
|
|
|
import { restGet, restPost, restPatch, restDelete} from './restConsumer.js'
|
2024-03-16 13:56:29 +01:00
|
|
|
import { getCookie, setCookie } from '@/utils.js'
|
2024-03-05 13:18:57 +01:00
|
|
|
|
|
|
|
export async function login(user, pass, exp){
|
2024-03-09 16:22:38 +01:00
|
|
|
return restPost("/login", {identifier: user, password: pass, expirationDate: exp});
|
2024-03-05 14:58:56 +01:00
|
|
|
}
|
|
|
|
|
2024-03-16 13:56:29 +01:00
|
|
|
export function isLogged(){
|
|
|
|
return getCookie("session_token") != ""
|
|
|
|
}
|
|
|
|
|
|
|
|
export function disconnect(){
|
|
|
|
setCookie("session_token", ";expires= Thu, 01 Jan 1970 00:00:01 GMT")
|
|
|
|
}
|
|
|
|
|
2024-03-15 14:46:39 +01:00
|
|
|
/**
|
|
|
|
* Register a user (tokenless)
|
|
|
|
*
|
|
|
|
* @param firstname
|
|
|
|
* @param lastname
|
|
|
|
* @param birthdate
|
|
|
|
* @param password
|
|
|
|
* @param mail
|
|
|
|
* @param address
|
|
|
|
* @param country
|
2024-03-16 10:17:04 +01:00
|
|
|
* @param curriculum
|
2024-03-15 14:46:39 +01:00
|
|
|
* @param imageId id of the image in database returned when uploaded
|
|
|
|
*/
|
2024-03-29 10:55:59 +01:00
|
|
|
export async function register(firstname, lastname, birthDate, password, email, address, country, curriculumId, imageId, identityCardId, submissionDate){
|
2024-03-15 14:46:39 +01:00
|
|
|
return restPost("/register", {
|
2024-03-18 11:55:51 +01:00
|
|
|
firstName: firstname,
|
|
|
|
lastName: lastname,
|
2024-03-15 14:46:39 +01:00
|
|
|
birthDate: birthDate,
|
|
|
|
password: password,
|
|
|
|
email: email,
|
|
|
|
address: address,
|
|
|
|
country: country,
|
2024-03-18 11:55:51 +01:00
|
|
|
curriculumId: curriculumId,
|
2024-03-29 10:55:59 +01:00
|
|
|
profilePicture: imageId,
|
|
|
|
identityCard : identityCardId,
|
|
|
|
submissionDate : submissionDate
|
2024-03-15 14:46:39 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2024-03-29 10:55:59 +01:00
|
|
|
* PS: the password is not required as it is generated by the backend and sent to the user
|
2024-03-15 14:46:39 +01:00
|
|
|
* 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,
|
|
|
|
});
|
2024-03-05 13:18:57 +01:00
|
|
|
}
|
2024-03-06 14:08:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get informations on a specific user.
|
|
|
|
* Leaving the id empty will return the user's value based on his token
|
|
|
|
* if the user is not authenticated. then an empty array should be returned
|
|
|
|
*/
|
|
|
|
export async function getUser(id){
|
2024-03-17 22:00:56 +01:00
|
|
|
const endpoint = "/user/" + id;
|
2024-03-06 14:08:39 +01:00
|
|
|
return restGet(endpoint);
|
|
|
|
}
|
|
|
|
|
2024-03-13 09:54:56 +01:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2024-03-06 14:08:39 +01:00
|
|
|
/**
|
|
|
|
* Reserved for secretary roles. Allow to list all user on the plateform
|
|
|
|
*/
|
|
|
|
export async function getAllUsers(){
|
|
|
|
return restGet("/users");
|
|
|
|
}
|
|
|
|
|
2024-03-13 18:22:28 +01:00
|
|
|
/**
|
|
|
|
* Return the list of teachers
|
|
|
|
*
|
|
|
|
* @return a list of teachers
|
|
|
|
* each elements is of the form
|
|
|
|
* - id
|
|
|
|
* - name
|
|
|
|
* - role
|
|
|
|
*/
|
|
|
|
export async function getTeachers(){
|
2024-03-17 15:59:12 +01:00
|
|
|
return restGet("/teachers")
|
2024-03-13 18:22:28 +01:00
|
|
|
}
|
2024-03-13 09:54:56 +01:00
|
|
|
|
2024-03-16 14:31:44 +01:00
|
|
|
|
|
|
|
export async function getStudents(){
|
2024-03-17 15:59:12 +01:00
|
|
|
return restGet("/students")
|
2024-03-16 14:31:44 +01:00
|
|
|
}
|
2024-03-13 09:54:56 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2024-03-18 18:47:00 +01:00
|
|
|
export async function alterSelf(id,data){
|
|
|
|
console.log(data)
|
|
|
|
return restPatch("/user/"+id, data);
|
2024-03-13 09:54:56 +01:00
|
|
|
}
|
2024-03-18 17:28:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function deleteUser(id){
|
|
|
|
return restDelete("/user/" + id)
|
|
|
|
}
|