1
0
forked from PGL/Clyde

Merge branch 'master' into wal/frontend/Register

This commit is contained in:
Wawilski 2024-03-08 16:37:00 +01:00
commit 0ca5640564
5 changed files with 139 additions and 38 deletions

View File

@ -1,22 +1,27 @@
<script setup> <script setup>
import { login , register} from './rest/Users.js'
import { ref } from 'vue' import { ref } from 'vue'
import i18n from './i18n.js' import i18n from './i18n.js'
const login= ref(true) const loginPage= ref(true)
const page = ref(0) const page = ref(0)
const emailID=ref("") const emailID=ref("")
const passwordIN=ref("") const passwordIN=ref("")
const submitValue= ref(i18n("login.guest.submit"))
const surname=ref("") const surname=ref("")
const firstname=ref("") const firstname=ref("")
const passwordOUT=ref("") const passwordOUT=ref("")
const passwordConfirm=ref("") const passwordConfirm=ref("")
const birthday=ref("")
const emailOUT=ref("") const emailOUT=ref("")
const address=ref("") const address=ref("")
const country=ref("") const country=ref("")
const cursus=ref("") const cursus=ref("")
const loginInfos = [{_emailID:emailID},{_passwordIN:passwordIN}] const loginInfos = [{_emailID:emailID},{_passwordIN:passwordIN}]
const registerInfos= [{_surname:surname},{_firstname:firstname},{_passwordOUT:passwordOUT},{_passwordConfirm:passwordConfirm},{_emailOUT:emailOUT},{_address:address},{_country:country},{_cursus:cursus}] const registerInfos= [{_surname:surname},{_firstname:firstname},{_birthday:birthday},{_passwordOUT:passwordOUT},
{_passwordConfirm:passwordConfirm},{_emailOUT:emailOUT},{_address:address},{_country:country},{_cursus:cursus}]
</script> </script>
@ -31,9 +36,11 @@
<div class="logBoxCenterer"> <div class="logBoxCenterer">
<div class='loginBox'> <div class='loginBox'>
<div v-if="login"> <div v-if="loginPage">
<div class="form"> <form @submit.prevent="login(emailID, passwordIN)"class="form">
<h1 style="color:rgb(239,60,168); font-family: sans-serif;">{{i18n("login.guest.signin")}}</h1> <h1 style="color:rgb(239,60,168); font-family: sans-serif;">
{{i18n("login.guest.signin")}}
</h1>
<div class="inputBox"> <div class="inputBox">
<p>ID / {{i18n("login.guest.email")}}</p> <p>ID / {{i18n("login.guest.email")}}</p>
<input type="text" v-model="emailID"> <input type="text" v-model="emailID">
@ -43,19 +50,19 @@
<input type="password" v-model="passwordIN"> <input type="password" v-model="passwordIN">
</div> </div>
<div class="register"> <div class="register">
<a @click="login=!login">{{i18n("login.guest.register")}}</a> <a @click="loginPage=!loginPage">{{i18n("login.guest.register")}}</a>
</div> </div>
<div class="inputBox"> <div class="inputBox">
<button @click="console.log(inputs)">{{i18n("login.guest.submit")}}</button> <input type="submit" v-model="submitValue">
</div>
</div> </div>
</form>
</div> </div>
<div v-else> <div v-else>
<div class="form"> <form @submit.prevent="register(surname,firstname,emailOUT)" class="form">
<h1 style="color:rgb(239,60,168); font-family: sans-serif; text-align:center;">{{i18n("login.guest.welcome")}}</h1> <h1 style="color:rgb(239,60,168); font-family: sans-serif; text-align:center;">
{{i18n("login.guest.welcome")}}
</h1>
<div v-if="page === 0"> <div v-if="page === 0">
<div class="inputBox"> <div class="inputBox">
<p>{{i18n("login.guest.surname")}}</p> <p>{{i18n("login.guest.surname")}}</p>
@ -65,6 +72,10 @@
<p>{{i18n("login.guest.firstname")}}</p> <p>{{i18n("login.guest.firstname")}}</p>
<input type="text" v-model="firstname"> <input type="text" v-model="firstname">
</div> </div>
<div class="inputBox">
<p>BIRTHDAY</p>
<input type="date" v-model="birthday">
</div>
<div class="inputBox"> <div class="inputBox">
<p>{{i18n("login.guest.password")}}</p> <p>{{i18n("login.guest.password")}}</p>
<input type="password" v-model="passwordOUT"> <input type="password" v-model="passwordOUT">
@ -78,7 +89,7 @@
<button @click="page++">{{i18n("login.guest.nextpage")}}</button> <button @click="page++">{{i18n("login.guest.nextpage")}}</button>
</div> </div>
<div @click="(login=!login) && (page=0)" class="register"> <div @click="(loginPage=!loginPage) && (page=0)" class="register">
<a>{{i18n("login.guest.alregister")}}</a> <a>{{i18n("login.guest.alregister")}}</a>
</div> </div>
</div> </div>
@ -96,7 +107,7 @@
<input type="text" v-model="country"> <input type="text" v-model="country">
</div> </div>
<div class="inputBox"> <div class="inputBox">
<p>Cursus</p> <p>CURSUS</p>
<select v-model="cursus"> <select v-model="cursus">
<option value="Chemistry">Chemistry</option> <option value="Chemistry">Chemistry</option>
<option value="Psycho">Psychology</option> <option value="Psycho">Psychology</option>
@ -109,11 +120,11 @@
<div class="switchpage"> <div class="switchpage">
<button @click="page--">{{i18n("login.guest.lastpage")}}</button> <button @click="page--">{{i18n("login.guest.lastpage")}}</button>
</div> </div>
<div @click="(login=!login) && (page=0)" class="register"> <div @click="(loginPage=!loginPage) && (page=0)" class="register">
<a>{{i18n("login.guest.alregister")}}</a> <a>{{i18n("login.guest.alregister")}}</a>
</div> </div>
</div> </div>
</div> </form>
</div> </div>
</div> </div>
</div> </div>
@ -214,7 +225,7 @@
} }
button,select{ input[type=submit],button,select{
margin-bottom:20px; margin-bottom:20px;
background-color: rgb(239,60,168); background-color: rgb(239,60,168);
cursor: pointer; cursor: pointer;
@ -231,4 +242,5 @@ button:active ,.switchpage:active{
} }
</style> </style>

View File

@ -9,7 +9,7 @@
* *
*/ */
import { getCookie } from './utils.js'; import { getCookie, setCookie } from './utils.js';
const default_lang = "EN"; const default_lang = "EN";
let langs; let langs;
@ -34,10 +34,6 @@ export default function i18n(key, options) {
return ret; return ret;
} }
//
// Those functions are utility functions use by previous exported functions.
//
/** /**
* Function that load the file with translation from the specified lang and return a dictionnary * Function that load the file with translation from the specified lang and return a dictionnary
* @param select the language to load. could be null to fetch the cookies for an answer * @param select the language to load. could be null to fetch the cookies for an answer
@ -61,3 +57,8 @@ export async function loadLangs(lang){
langs = filteredLines; langs = filteredLines;
} }
await loadLangs(); await loadLangs();
export async function setLang(lang){
setCookie("lang", lang);
await loadLangs();
}

View File

@ -0,0 +1,28 @@
import { restGet, restPost } from './restConsumer.js'
export async function login(user, pass, exp){
return restPost("/login", {login: user, password: pass, expiration: exp});
}
export async function register(user, pass, mail){
return restPost("/user", {name: user, password: pass, mail: mail});
restPost("/login", {login: user, password: pass, expiration: exp})
}
/**
* 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){
const endpoint = "/user" + id != null ? "/" + id : "";
return restGet(endpoint);
}
/**
* Reserved for secretary roles. Allow to list all user on the plateform
*/
export async function getAllUsers(){
return restGet("/users");
}

View File

@ -0,0 +1,52 @@
/**
* Courses API
*/
import { restGet, restPost, restDelete, restPatch } from './restConsumer.js'
/**
* Create a new course
*/
export async function createCourse(name, credits, faculty, teacher, assistants){
return restPost("/courses", {name: name, credits: credits, faculty: faculty, teacher: teacher, assistants: assistants} )
}
/**
* Delete the specified course
*/
export async function deleteCourse(id){
return restDelete("/course/" + id);
}
/**
* Get informations on a particular course
*
* @param id identification of the course
*
* @return all atribute of the specified course
* - name
* - credits
* - faculty
* - teacher
* - assistants : list
*/
export async function getCourse(id){
return restGet("/course/" + id);
}
/**
* Change the options of a course
*
* @param id the id of the course
* @param changes Object with value to changes
*
* The changes object can contain:
* - name
* - credits
* - faculty
* - teacher
* - assistants: should be a list and will replace all assistants
*/
export async function alterCourse(id, changes){
return restPatch("/course/" + id, changes);
}

View File

@ -2,7 +2,7 @@
* Return the content of a cookie with specified key * Return the content of a cookie with specified key
* @param key cookie name * @param key cookie name
*/ */
function getCookie(key){ export function getCookie(key){
key = key + "=" key = key + "="
let cookies = decodeURIComponent(document.cookie).split(";"); let cookies = decodeURIComponent(document.cookie).split(";");
for (let el of cookies) { for (let el of cookies) {
@ -14,4 +14,12 @@ function getCookie(key){
return ""; return "";
} }
export {getCookie}; /**
* Return the content of a cookie with specified key
* @param key cookie name
*/
export function setCookie(key, value){
cookie = key + "=" + value + ";";
document.cookie = cookie;
// Here we can apreciate the stupidity of Javascript :/
}