Skip to content

Commit

Permalink
started cleaning up profile.js
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickFuereder committed Jan 28, 2025
1 parent 30e886b commit 599a64d
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 141 deletions.
4 changes: 2 additions & 2 deletions Assets/js/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function initSearchbar(data, id) {
}

if (e.key == 'ArrowDown') {
const currentFocus = searchbar.querySelector('.autocom-box h1.focus');
let currentFocus = searchbar.querySelector('.autocom-box h1.focus');

if (currentFocus) currentFocus.classList.remove('focus');

Expand All @@ -42,7 +42,7 @@ export function initSearchbar(data, id) {
}

if (e.key == 'ArrowUp') {
const currentFocus = searchbar.querySelector('.autocom-box h1.focus');
let currentFocus = searchbar.querySelector('.autocom-box h1.focus');

if (currentFocus) currentFocus.classList.remove('focus');

Expand Down
18 changes: 18 additions & 0 deletions Assets/js/data/auth/2fa/activate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export async function activate(mfaType) {
await LoginManager.validateToken();
const req = await fetch(`https://api.login.${LoginManager.domain}/2fa/activate`, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + LoginManager.getCookie('token'),
'Content-Type': 'application/json',
},
body: mfaType,
});

if (req.status == 401) {
window.location.href = LoginManager.buildLoginUrl(window.location.href);
return;
}

return req;
}
21 changes: 21 additions & 0 deletions Assets/js/data/auth/2fa/deactivate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export async function deactivate(password, mfaToken) {
await LoginManager.validateToken();
const req = await fetch(`https://api.login.${LoginManager.domain}/2fa/deactivate`, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + LoginManager.getCookie('token'),
'Content-Type': 'application/json',
},
body: JSON.stringify({
Password: password,
MFAToken: mfaToken,
}),
});

if (req.status == 401) {
window.location.href = LoginManager.buildLoginUrl(window.location.href);
return;
}

return req;
}
21 changes: 21 additions & 0 deletions Assets/js/data/auth/2fa/verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export async function verify(password, mfaToken) {
await LoginManager.validateToken();
const req = await fetch(`https://api.login.${LoginManager.domain}/2fa/verify`, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + LoginManager.getCookie('token'),
'Content-Type': 'application/json',
},
body: JSON.stringify({
Password: password,
MFAToken: mfaToken,
}),
});

if (req.status == 401) {
window.location.href = LoginManager.buildLoginUrl(window.location.href);
return;
}

return req;
}
23 changes: 23 additions & 0 deletions Assets/js/data/auth/changePassword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export async function changePassword(oldPw, email, pw, mfaToken) {
await LoginManager.validateToken();
const req = await fetch(`https://api.login.${LoginManager.domain}/resetpassword`, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + LoginManager.getCookie('token'),
'Content-Type': 'application/json',
},
body: JSON.stringify({
OldPassword: oldPw,
Email: email,
Password: pw,
TwoFaToken: mfaToken,
}),
});

if (req.status == 401) {
window.location.href = LoginManager.buildLoginUrl(window.location.href);
return;
}

return req;
}
21 changes: 21 additions & 0 deletions Assets/js/data/auth/deleteAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export async function deleteAccount(password, mfaToken) {
await LoginManager.validateToken();
const req = await fetch(`https://api.login.${LoginManager.domain}/user`, {
method: 'DELETE',
headers: {
Authorization: 'Bearer ' + LoginManager.getCookie('token'),
'Content-Type': 'application/json',
},
body: JSON.stringify({
Password: password,
TwoFaToken: mfaToken,
}),
});

if (req.status == 401) {
window.location.href = LoginManager.buildLoginUrl(window.location.href);
return;
}

return req;
}
23 changes: 23 additions & 0 deletions Assets/js/data/auth/oauth/saveClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export async function saveClient(clientId, logoUrl, url, name) {
await LoginManager.validateToken();
const req = await fetch(`https://api.login.${LoginManager.domain}/user/oauth`, {
method: 'PUT',
headers: {
Authorization: 'Bearer ' + LoginManager.getCookie('token'),
'Content-Type': 'application/json',
},
body: JSON.stringify({
clientId: clientId,
logoUrl: logoUrl,
url: url,
name: name,
}),
});

if (req.status == 401) {
window.location.href = LoginManager.buildLoginUrl(window.location.href);
return;
}

return req;
}
16 changes: 16 additions & 0 deletions Assets/js/data/auth/unlinkSocialAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export async function unlinkSocialAccount(provider) {
await LoginManager.validateToken();
const req = await fetch(`https://api.login.${LoginManager.domain}/unlink/` + provider, {
method: 'GET',
headers: {
Authorization: 'Bearer ' + LoginManager.getCookie('token'),
},
});

if (req.status == 401) {
window.location.href = LoginManager.buildLoginUrl(window.location.href);
return;
}

return req;
}
Loading

0 comments on commit 599a64d

Please sign in to comment.