update HTML for Bearer token update

This commit is contained in:
xfarrow 2024-03-21 17:34:16 +01:00
parent 572ca83a8f
commit bb86034835
6 changed files with 57 additions and 59 deletions

View File

@ -1,9 +1,14 @@
<html> <html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> <head>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
</head> integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<body> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous">
</script>
</head>
<body>
<div id="successDialog" class="alert alert-success" role="alert" style="display: none;"> <div id="successDialog" class="alert alert-success" role="alert" style="display: none;">
<p>Your account has been activated! Welcome onboard.</p> <p>Your account has been activated! Welcome onboard.</p>
@ -15,37 +20,36 @@
</div> </div>
<script src="../js/constants.js"></script> <script src="../js/constants.js"></script>
<script src="../js/utils.js"></script>
<script> <script>
window.addEventListener("load", async function () { window.addEventListener("load", async function () {
await activateAccount(); await activateAccount();
}); });
async function activateAccount () { async function activateAccount() {
const code = new URLSearchParams(window.location.search).get('q'); const code = new URLSearchParams(window.location.search).get('q');
if(!code){ if (!code) {
document.getElementById('errorDialog').style.display = 'block'; document.getElementById('errorDialog').style.display = 'block';
return; return;
} }
const response = await fetch(`${API_URL}/persons/me/activation`, { const response = await fetch(`${API_URL}/persons/me/activation`, {
method: 'POST', method: 'POST',
headers: { headers: createHeaders(null),
'Content-Type': 'application/json'
},
body: JSON.stringify({ body: JSON.stringify({
code code
}), }),
}); });
if(response.ok) { if (response.ok) {
document.getElementById('successDialog').style.display = 'block'; document.getElementById('successDialog').style.display = 'block';
} } else {
else {
document.getElementById('errorDialog').style.display = 'block'; document.getElementById('errorDialog').style.display = 'block';
} }
} }
</script> </script>
</body> </body>
</html> </html>

View File

@ -50,9 +50,7 @@
email: email, email: email,
password: password password: password
}), }),
headers: { headers: createHeaders(null)
"Content-type": "application/json; charset=UTF-8"
}
}); });
const data = await response.json(); const data = await response.json();

View File

@ -39,9 +39,7 @@
return; return;
} }
const response = await fetch(`${API_URL}/organizations/${idOrganization}`, { const response = await fetch(`${API_URL}/organizations/${idOrganization}`, {
headers: { headers: createHeaders(null)
"Content-type": "application/json; charset=UTF-8",
}
}); });
const data = await response.json(); const data = await response.json();
if (response.ok) { if (response.ok) {
@ -68,9 +66,7 @@
async function isOrganizationHiring(organizationId) { async function isOrganizationHiring(organizationId) {
const response = await fetch(`${API_URL}/organizations/${organizationId}/joboffers`, { const response = await fetch(`${API_URL}/organizations/${organizationId}/joboffers`, {
headers: { headers: createHeaders(null)
"Content-type": "application/json; charset=UTF-8",
}
}); });
const data = await response.json(); const data = await response.json();
return data.length > 0; return data.length > 0;

View File

@ -53,9 +53,7 @@
const options = { const options = {
method: 'POST', method: 'POST',
headers: { headers: createHeaders(null),
'Content-Type': 'application/json'
},
body: JSON.stringify({ body: JSON.stringify({
display_name, display_name,
email, email,

View File

@ -80,17 +80,12 @@
window.location.href = 'login.html'; window.location.href = 'login.html';
} }
response = await fetch(`${API_URL}/persons/me`, { response = await fetch(`${API_URL}/persons/me`, {
headers: { headers: createHeaders(token)
"Content-type": "application/json; charset=UTF-8",
"authorization": token
}
}); });
document.getElementById('editBadge').style.display = 'block'; // show edit button document.getElementById('editBadge').style.display = 'block'; // show edit button
} else { } else {
response = await fetch(`${API_URL}/persons/${idToDisplay}/details`, { response = await fetch(`${API_URL}/persons/${idToDisplay}/details`, {
headers: { headers: createHeaders(null)
"Content-type": "application/json; charset=UTF-8",
}
}); });
} }

View File

@ -13,3 +13,10 @@ function getCookie(name) {
function callbackErrors(errors, func) { function callbackErrors(errors, func) {
errors.forEach(error => func(error.msg)); errors.forEach(error => func(error.msg));
} }
function createHeaders(token) {
return {
"Content-type": "application/json; charset=UTF-8",
"Authorization": `Bearer ${token}`
}
}