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

@ -12,4 +12,11 @@ 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}`
}
} }