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>
<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;">
<p>Your account has been activated! Welcome onboard.</p>
<p>Log in <a href="login.html">here</a></p>
</div>
<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>
<div id="errorDialog" class="alert alert-danger" role="alert" style="display: none;">
URL either invalid or account already activated.
</div>
<body>
<script src="../js/constants.js"></script>
<script>
window.addEventListener("load", async function () {
await activateAccount();
});
<div id="successDialog" class="alert alert-success" role="alert" style="display: none;">
<p>Your account has been activated! Welcome onboard.</p>
<p>Log in <a href="login.html">here</a></p>
</div>
async function activateAccount () {
const code = new URLSearchParams(window.location.search).get('q');
if(!code){
document.getElementById('errorDialog').style.display = 'block';
return;
}
<div id="errorDialog" class="alert alert-danger" role="alert" style="display: none;">
URL either invalid or account already activated.
</div>
const response = await fetch(`${API_URL}/persons/me/activation`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
code
}),
});
<script src="../js/constants.js"></script>
<script src="../js/utils.js"></script>
if(response.ok) {
document.getElementById('successDialog').style.display = 'block';
}
else {
document.getElementById('errorDialog').style.display = 'block';
}
<script>
window.addEventListener("load", async function () {
await activateAccount();
});
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>

View File

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

View File

@ -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;

View File

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

View File

@ -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)
});
}

View File

@ -13,3 +13,10 @@ 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}`
}
}