diff --git a/frontend/vanilla/html/activate-account.html b/frontend/vanilla/html/activate-account.html index a4f7cf1..b7fe079 100644 --- a/frontend/vanilla/html/activate-account.html +++ b/frontend/vanilla/html/activate-account.html @@ -1,51 +1,55 @@ -
- - - - - + + + + - + - - + - if(response.ok) { - document.getElementById('successDialog').style.display = 'block'; - } - else { - document.getElementById('errorDialog').style.display = 'block'; - } + + const response = await fetch(`${API_URL}/persons/me/activation`, { + method: 'POST', + headers: createHeaders(null), + body: JSON.stringify({ + code + }), + }); + + if (response.ok) { + document.getElementById('successDialog').style.display = 'block'; + } else { + document.getElementById('errorDialog').style.display = 'block'; + } + } + + + - \ No newline at end of file diff --git a/frontend/vanilla/html/login.html b/frontend/vanilla/html/login.html index 35195c6..8bf3ca1 100644 --- a/frontend/vanilla/html/login.html +++ b/frontend/vanilla/html/login.html @@ -50,9 +50,7 @@ email: email, password: password }), - headers: { - "Content-type": "application/json; charset=UTF-8" - } + headers: createHeaders(null) }); const data = await response.json(); diff --git a/frontend/vanilla/html/organization.html b/frontend/vanilla/html/organization.html index 3948678..e108de9 100644 --- a/frontend/vanilla/html/organization.html +++ b/frontend/vanilla/html/organization.html @@ -39,9 +39,7 @@ return; } const response = await fetch(`${API_URL}/organizations/${idOrganization}`, { - headers: { - "Content-type": "application/json; charset=UTF-8", - } + headers: createHeaders(null) }); const data = await response.json(); if (response.ok) { @@ -68,9 +66,7 @@ async function isOrganizationHiring(organizationId) { const response = await fetch(`${API_URL}/organizations/${organizationId}/joboffers`, { - headers: { - "Content-type": "application/json; charset=UTF-8", - } + headers: createHeaders(null) }); const data = await response.json(); return data.length > 0; diff --git a/frontend/vanilla/html/register.html b/frontend/vanilla/html/register.html index 059c903..ba3cf60 100644 --- a/frontend/vanilla/html/register.html +++ b/frontend/vanilla/html/register.html @@ -53,9 +53,7 @@ const options = { method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, + headers: createHeaders(null), body: JSON.stringify({ display_name, email, diff --git a/frontend/vanilla/html/userprofile.html b/frontend/vanilla/html/userprofile.html index e19c33f..62d1056 100644 --- a/frontend/vanilla/html/userprofile.html +++ b/frontend/vanilla/html/userprofile.html @@ -80,17 +80,12 @@ window.location.href = 'login.html'; } response = await fetch(`${API_URL}/persons/me`, { - headers: { - "Content-type": "application/json; charset=UTF-8", - "authorization": token - } + headers: createHeaders(token) }); document.getElementById('editBadge').style.display = 'block'; // show edit button } else { response = await fetch(`${API_URL}/persons/${idToDisplay}/details`, { - headers: { - "Content-type": "application/json; charset=UTF-8", - } + headers: createHeaders(null) }); } diff --git a/frontend/vanilla/js/utils.js b/frontend/vanilla/js/utils.js index b084538..536e3b9 100644 --- a/frontend/vanilla/js/utils.js +++ b/frontend/vanilla/js/utils.js @@ -12,4 +12,11 @@ function getCookie(name) { function callbackErrors(errors, func) { errors.forEach(error => func(error.msg)); +} + +function createHeaders(token) { + return { + "Content-type": "application/json; charset=UTF-8", + "Authorization": `Bearer ${token}` + } } \ No newline at end of file