Skip to content

Commit

Permalink
Refactor profile.js and index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickFuereder committed Nov 5, 2023
1 parent 7fe4c2e commit a3ae169
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
61 changes: 44 additions & 17 deletions Assets/js/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,6 @@ document.getElementById('ca_github_link').addEventListener('click', () => LinkAc
document.getElementById('logout').addEventListener('click', () => LoginManager.logout());
document.getElementById('deleteAccount').addEventListener('click', async (e) => await doubleClickButton(e, deleteAccount));

Array.from(document.getElementsByClassName('collapsible')).forEach((element) => {
element.addEventListener("click", function() {
this.classList.toggle("active");

if (this.nextElementSibling.style.maxHeight)
this.nextElementSibling.style.maxHeight = null;
else
this.nextElementSibling.style.maxHeight = this.nextElementSibling.scrollHeight + "px";

});
});

Array.from(document.getElementsByTagName('input')).forEach((element) => {
element.addEventListener('keyup', (e) => e.target.classList.remove('invalid'));
});

LoginManager.isLoggedIn().then(async (e) => {
if (!e) {
window.location.href = 'https://login.netdb.at?redirect=' + encodeURIComponent(window.location.href);
Expand Down Expand Up @@ -200,7 +184,7 @@ LoginManager.isLoggedIn().then(async (e) => {
row.appendChild(name);
const deleteBtn = document.createElement('button');
deleteBtn.innerText = 'Delete';
deleteBtn.addEventListener('click', () => deleteTrustedSsoClient(client.id));
deleteBtn.addEventListener('click', async () => await deleteTrustedSsoClient(client.id));
row.appendChild(deleteBtn);
document.getElementById('thirdPartyAppsContainer').appendChild(row);
});
Expand All @@ -210,8 +194,51 @@ LoginManager.isLoggedIn().then(async (e) => {
user.sso_clients.forEach((client) => {
document.getElementById('ssoClientsContainer').append(createSSOClient(client.logo, client.name, client.url, client.id, client.secret));
});

Array.from(document.getElementsByClassName('collapsible')).forEach((element) => {
element.addEventListener("click", function() {
this.classList.toggle("active");

if (this.nextElementSibling.style.maxHeight)
this.nextElementSibling.style.maxHeight = null;
else
this.nextElementSibling.style.maxHeight = this.nextElementSibling.scrollHeight + "px";

});
});

Array.from(document.getElementsByTagName('input')).forEach((element) => {
element.addEventListener('keyup', (e) => e.target.classList.remove('invalid'));
});
});

async function deleteTrustedSsoClient(clientId) {
await LoginManager.validateToken();
const req = await fetch('https://api.login.netdb.at/oauth/untrust', {
method: 'POST',
headers: {
Authorization: 'Bearer ' + LoginManager.getCookie('token'),
'Content-Type': 'application/json',
},
body: "\"" + clientId + "\"",
});

if (req.status == 401) {
window.location.href = 'https://login.netdb.at?redirect=' + encodeURIComponent(window.location.href);
return;
}

const res = await req.json();

if (res.statusCode != 200) {
console.log(res);
return;
}

document.getElementById(clientId).remove();

}

function createSSOClient(logoUrl, clientName, websiteUrl, clientId, clientSecret) {
const item = document.getElementById('ssoCredentials').getElementsByTagName('template')[0].content.cloneNode(true);

Expand Down
1 change: 0 additions & 1 deletion profile/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ <h1>My Devices</h1>
</div>
<div id="thirdPartyApps" class="item">
<h1>Third Party Apps</h1>

<div id="thirdPartyAppsContainer" class="thirdPartyApps-container">
<p>No third party apps connected!</p>
</div>
Expand Down

0 comments on commit a3ae169

Please sign in to comment.