v1.0.0
This commit is contained in:
47
web/lib/pages/auth/script.js
Normal file
47
web/lib/pages/auth/script.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const Auth = {
|
||||
init: async () => {
|
||||
let html = await fetch('/lib/pages/auth/index.html').then((response) => response.text());
|
||||
app.innerHTML = html;
|
||||
|
||||
document.getElementById("page-auth-form").addEventListener("submit", async function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
let uuid = document.getElementById("auth-forms-uuid").value;
|
||||
|
||||
uuid = uuid.replace("https://sheep-service.com/?uuid=", "");
|
||||
uuid = uuid.replace("https://sheep-service.com?uuid=", "");
|
||||
uuid = uuid.replace("https://sheep-service.com?/hash=", "");
|
||||
uuid = uuid.replace("https://sheep-service.com?hash=", "");
|
||||
|
||||
console.log(uuid);
|
||||
|
||||
const URL = `${CONFIG.api}auth`;
|
||||
USER = await fetch(URL, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
"Content-Type": "application/json, text/plain, */*",
|
||||
"Authorization": uuid
|
||||
}
|
||||
}).then(response => {
|
||||
if (response.status === 401) {
|
||||
localStorage.removeItem("uuid");
|
||||
Router.navigate(`/auth`);
|
||||
} else {
|
||||
localStorage.setItem("uuid", uuid);
|
||||
Router.navigate(`/`, false);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
});
|
||||
|
||||
console.log("USER Info: ", USER);
|
||||
|
||||
|
||||
if (USER.possibilities.can_view_sheeps) document.getElementById("li-sheeps").style.display = "";
|
||||
if (USER.possibilities.can_add_schedule) document.getElementById("li-schedule").style.display = "";
|
||||
if (USER.possibilities.can_manager_territory) document.getElementById("li-territory").style.display = "";
|
||||
if (USER.possibilities.can_view_stand) document.getElementById("li-stand").style.display = "";
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user