-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
113 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// LOGIN | ||
|
||
function login() { | ||
const email = document.getElementById("auth-email").value; | ||
const key = document.getElementById("auth-key").value; | ||
const organization = document.getElementById("auth-organization-id").value; | ||
const encryptedKey = document.getElementById("auth-encrypted-key").value; | ||
const http = new XMLHttpRequest(); | ||
http.open("POST", "http://localhost:5775/auth"); | ||
http.setRequestHeader("Content-type", "application/json"); | ||
http.send(JSON.stringify({ | ||
email, | ||
key, | ||
organization, | ||
encrypted_key: encryptedKey, | ||
})); | ||
http.onreadystatechange = (e) => { | ||
document.getElementById("auth-result").innerHTML = getHttpResult(http); | ||
if (http.status === 200) { | ||
document.getElementById("auth-info").innerHTML = `${email} | ${organization}`; | ||
tokenSession = JSON.parse(http.responseText).token; | ||
listWorkspaces(); | ||
} | ||
} | ||
} | ||
|
||
const storageKey = "resana-secure-release-tests-key-auth"; | ||
|
||
function saveAuth() { | ||
const auth = {}; | ||
let storage = null; | ||
auth['email'] = document.getElementById("auth-email").value; | ||
auth['key'] = document.getElementById("auth-key").value; | ||
auth['organization'] = document.getElementById("auth-organization-id").value; | ||
auth['encryptedKey'] = document.getElementById("auth-encrypted-key").value; | ||
auth['password'] = document.getElementById("auth-password").value; | ||
storage = localStorage.getItem(storageKey) || "[]"; | ||
storage = JSON.parse(storage); | ||
storage.push(auth); | ||
localStorage.setItem(storageKey, JSON.stringify(storage)); | ||
} | ||
|
||
function listAuth() { | ||
let saves = []; | ||
const storage = localStorage.getItem(storageKey); | ||
saves = JSON.parse(storage) || []; | ||
const modal = document.getElementById("save-modal"); | ||
modal.style.display = "block"; | ||
const listElem = document.getElementById("saves-list"); | ||
listElem.innerHTML = ""; | ||
saves.forEach((save, index) => { | ||
listElem.innerHTML += `<li onclick="loadAuth(${index})">${save.email} | ${save.key} | ${save.organization}</li>`; | ||
}); | ||
} | ||
|
||
function loadAuth(index) { | ||
const storage = localStorage.getItem(storageKey); | ||
const saves = JSON.parse(storage) || []; | ||
document.getElementById("auth-email").value = saves[index].email; | ||
document.getElementById("auth-key").value = saves[index].key; | ||
document.getElementById("auth-organization-id").value = saves[index].organization; | ||
document.getElementById("auth-encrypted-key").value = saves[index].encryptedKey; | ||
document.getElementById("auth-password").value = saves[index].password; | ||
const modal = document.getElementById("save-modal"); | ||
modal.style.display = "none"; | ||
} | ||
|
||
function closeAuthModal() { | ||
const elem = document.getElementById("save-modal"); | ||
elem.style.display = "none"; | ||
} | ||
|
||
|
||
// LOGOUT | ||
function deconnect(force = false) { | ||
const http = new XMLHttpRequest(); | ||
http.open("DELETE", "http://localhost:5775/auth"); | ||
http.setRequestHeader("Authorization", `bearer ${tokenSession}`); | ||
http.send(); | ||
http.onreadystatechange = (e) => { | ||
document.getElementById("auth-info").innerHTML = ""; | ||
document.getElementById("logout-result").innerHTML = getHttpResult(http); | ||
} | ||
openAccount(force); | ||
} | ||
|
||
function deconnectAll(force = false) { | ||
const http = new XMLHttpRequest(); | ||
http.open("DELETE", "http://localhost:5775/auth/all"); | ||
http.setRequestHeader("Authorization", `bearer ${tokenSession}`); | ||
http.send(); | ||
http.onreadystatechange = (e) => { | ||
document.getElementById("auth-info").innerHTML = ""; | ||
document.getElementById("logout-result").innerHTML = getHttpResult(http); | ||
} | ||
openAccount(force); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,38 +183,21 @@ <h2>Auth</h2> | |
<li>Spammer le bouton "Se connecter" (avec mauvaise key) pour vérifier la protection anti-bruteforce</li> | ||
</ul> | ||
|
||
<div> | ||
Key | ||
<label class="switch"> | ||
<input id="switch-auth" type="checkbox" onchange="switchAuth()"> | ||
<span class="slider round"></span> | ||
</label> | ||
User password | ||
</div> | ||
|
||
<div id="key-auth"> | ||
<label for="key-email">Email</label> | ||
<input id="key-email" value="[email protected]"> | ||
<br> | ||
<label for="key">Key</label> | ||
<input id="key" value="P@ssw0rd"> | ||
<br> | ||
<label for="key-organization-id">ID organisation</label> | ||
<input id="key-organization-id" value="test_release_"> | ||
</div> | ||
<div id="password-auth"> | ||
<label for="password-email">Email</label> | ||
<input id="password-email" value="[email protected]"> | ||
<br> | ||
<label for="password">Mot de passe</label> | ||
<input id="password" value="P@ssw0rd"> | ||
<br> | ||
<label for="encrypted-key">Encrypted key</label> | ||
<input id="encrypted-key" value=""> | ||
<br> | ||
<label for="password-organization-id">ID organisation</label> | ||
<input id="password-organization-id" value="test_release_"> | ||
</div> | ||
<label for="auth-email">Email</label> | ||
<input id="auth-email" value="[email protected]"> | ||
<br> | ||
<label for="auth-key">Key</label> | ||
<input id="auth-key" value="P@ssw0rd"> | ||
<br> | ||
<label for="auth-organization-id">ID organisation</label> | ||
<input id="auth-organization-id" value="test_release_"> | ||
<br> | ||
<label for="auth-encrypted-key">Encrypted key</label> | ||
<input id="auth-encrypted-key" value=""> | ||
<br> | ||
<label for="auth-password">Password</label> | ||
<input id="auth-password" value=""> | ||
<br> | ||
<button onclick="login()">Se connecter</button> | ||
<button onclick="saveAuth()">Sauvegarder</button> | ||
<button onclick="listAuth()">Charger</button> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters