From 353ed600ef88513b145d6903b3ca2750386c1d34 Mon Sep 17 00:00:00 2001 From: ideclon Date: Wed, 30 Nov 2022 20:46:02 +0000 Subject: [PATCH] cleanup + js modules --- index.php | 1 + js/index.js | 9 +++++++++ js/login.js | 2 ++ js/setup.js | 43 +++++++++++++++++++++++-------------------- login.html | 18 ------------------ login.php | 20 ++++++++++++++++++++ template/footer.php | 4 ++-- template/header.html | 4 ++-- 8 files changed, 59 insertions(+), 42 deletions(-) delete mode 100644 login.html create mode 100644 login.php diff --git a/index.php b/index.php index 7eaade5..a0186dd 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,4 @@ +You are connected to Mastodon as on server \ No newline at end of file diff --git a/js/index.js b/js/index.js index e69de29..b4d2c35 100644 --- a/js/index.js +++ b/js/index.js @@ -0,0 +1,9 @@ +import {accountDetails} from "./setup.js"; + +document.querySelectorAll('.mastodon_server').forEach((element) => { + element.innerHTML = accountDetails.prefs.user_server_uri +}); + +document.querySelectorAll('.mastodon_user').forEach((element) => { + element.innerHTML = JSON.parse(accountDetails.prefs.account_details).acct +}); \ No newline at end of file diff --git a/js/login.js b/js/login.js index 1d48b76..839df40 100644 --- a/js/login.js +++ b/js/login.js @@ -1,3 +1,5 @@ +import {account} from './setup.js'; + account.get().then((response) => { location.href = '/'; }).catch((err) => { diff --git a/js/setup.js b/js/setup.js index 7b6a3ae..cb5bb89 100644 --- a/js/setup.js +++ b/js/setup.js @@ -6,39 +6,40 @@ const account = new Appwrite.Account(client); const databases = new Appwrite.Databases(client); const functions = new Appwrite.Functions(client); -let accountDetailsPromise = account.get().then((res) => { - accountDetailsPromise = res -}) +let accountDetails; -if(window.location.pathname !== '/login.html') { +if (window.location.pathname !== '/login.php') { account.get().then((response) => { console.log(response); - + document.querySelectorAll('.fill-name').forEach(el => el.innerHTML = response.name); - - if(response.emailVerification == false) { + + if (response.emailVerification == false) { message_box('error', 'Your account is not verified!'); - + return } - - if(response.prefs.user_token == undefined) { + + if (response.prefs.user_token == undefined) { message_box('info', "You haven't connected to Mastodon yet! Do it now"); } }).catch((err) => { - if(err == "AppwriteException: User (role: guests) missing scope (account)") { - location.href = "login.html"; + if (err == "AppwriteException: User (role: guests) missing scope (account)") { + location.href = "login.php"; } }) + + + document.getElementById('logout').addEventListener('click', () => { + account.deleteSession('current').then((res) => { + window.location.reload(); + }); + }) + + accountDetails = await account.get(); } -document.getElementById('logout').addEventListener('click', () => { - account.deleteSession('current').then((res) => { - window.location.reload(); - }); -}) - -function message_box(type, message) { +export function message_box(type, message) { const message_box = document.getElementById('message-box'); message_box.classList.remove('info', 'error', 'success'); @@ -46,4 +47,6 @@ function message_box(type, message) { message_box.innerHTML = message; message_box.classList.add(type); message_box.style.display = 'block'; -} \ No newline at end of file +} + +export { account, databases, functions, accountDetails }; \ No newline at end of file diff --git a/login.html b/login.html deleted file mode 100644 index c816bf7..0000000 --- a/login.html +++ /dev/null @@ -1,18 +0,0 @@ - - - Login | Mastodon Algorithm - - - - -
- Login - -
-
- - -
- - - \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..610c042 --- /dev/null +++ b/login.php @@ -0,0 +1,20 @@ + + + + Login | Mastodon Algorithm + + + + + +
+ Login + +
+
+ + +
+ + \ No newline at end of file diff --git a/template/footer.php b/template/footer.php index 848601c..62fe58f 100644 --- a/template/footer.php +++ b/template/footer.php @@ -4,5 +4,5 @@ const APPWRITE_ENDPOINT = ''; const APPWRITE_PROJECT_ID = ''; const APPWRITE_DB_ID = ''; - -":''?> \ No newline at end of file + +":''?> \ No newline at end of file diff --git a/template/header.html b/template/header.html index 34b9b1d..fa45bd0 100644 --- a/template/header.html +++ b/template/header.html @@ -7,6 +7,6 @@ - Welcome, . Not you? Logout + Welcome, . Not you? Logout
- +