commit b2f9dceef14b6427b649499975f4859aebf17399 Author: ideclon Date: Tue Nov 29 21:30:09 2022 +0000 inital commit - sign in to mastodon diff --git a/connect.php b/connect.php new file mode 100644 index 0000000..521cf5d --- /dev/null +++ b/connect.php @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/css/styles.css b/css/styles.css new file mode 100644 index 0000000..2d23170 --- /dev/null +++ b/css/styles.css @@ -0,0 +1,21 @@ +.message-box { + display: none; + margin: 10px; + padding: 8px; + border-radius: 10px; + outline-style: solid; + outline-width: 2px; + + background-color: lightgray; + outline-color: gray; +} + +.message-box.info { + background-color: lightblue; + outline-color: blue; +} + +.message-box.error { + background-color: lightpink; + outline-color: red; +} \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..7eaade5 --- /dev/null +++ b/index.php @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/js/connect.js b/js/connect.js new file mode 100644 index 0000000..077dc98 --- /dev/null +++ b/js/connect.js @@ -0,0 +1,27 @@ +account.getPrefs().then((response) => { + if(response.user_token !== undefined) { + message_box('info', 'You\'re already conneted! Go home'); + + return + }; + + if(response.user_server_uri == undefined) { + document.getElementById('instance-connect').style.display = 'block'; + + return + } + +}); + +document.getElementById('instance-connect').addEventListener('submit', (event) => { + event.preventDefault(); + + const server_url = document.getElementById('server-url').value; + + functions.createExecution('servers', '{"action": "register_server", "user_id": "' + accountDetailsPromise['$id'] + '", "server_url": "' + server_url + '"}') + .then((res) => { + // console.log(JSON.parse(res.response)['redirect_uri']); + window.location.href = JSON.parse(res.response).redirect_uri; + }) + +}); \ No newline at end of file diff --git a/js/index.js b/js/index.js new file mode 100644 index 0000000..e69de29 diff --git a/js/login.js b/js/login.js new file mode 100644 index 0000000..1d48b76 --- /dev/null +++ b/js/login.js @@ -0,0 +1,22 @@ +account.get().then((response) => { + location.href = '/'; +}).catch((err) => { + return; +}) + +document.querySelectorAll('#login')[0].addEventListener('click', () => { + const email = document.getElementById('email').value; + const password = document.getElementById('password').value; + + const error = document.getElementById('error-message'); + + if(email == '' || password == '') { + error.innerHTML = 'Email address or password is blank
' + } else { + account.createEmailSession(email, password).then((response) => { + location.href = '/'; + }).catch((err) => { + error.innerHTML = err.message + '
'; + }) + } +}) \ No newline at end of file diff --git a/js/setup.js b/js/setup.js new file mode 100644 index 0000000..7b6a3ae --- /dev/null +++ b/js/setup.js @@ -0,0 +1,49 @@ +const client = new Appwrite.Client() + .setEndpoint(APPWRITE_ENDPOINT) // Your API Endpoint + .setProject(APPWRITE_PROJECT_ID); // Your project ID + +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 +}) + +if(window.location.pathname !== '/login.html') { + account.get().then((response) => { + console.log(response); + + document.querySelectorAll('.fill-name').forEach(el => el.innerHTML = response.name); + + if(response.emailVerification == false) { + message_box('error', 'Your account is not verified!'); + + return + } + + 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"; + } + }) +} + +document.getElementById('logout').addEventListener('click', () => { + account.deleteSession('current').then((res) => { + window.location.reload(); + }); +}) + +function message_box(type, message) { + const message_box = document.getElementById('message-box'); + + message_box.classList.remove('info', 'error', 'success'); + + message_box.innerHTML = message; + message_box.classList.add(type); + message_box.style.display = 'block'; +} \ No newline at end of file diff --git a/login.html b/login.html new file mode 100644 index 0000000..c816bf7 --- /dev/null +++ b/login.html @@ -0,0 +1,18 @@ + + + Login | Mastodon Algorithm + + + + +
+ Login + +
+
+ + +
+ + + \ No newline at end of file diff --git a/redirect.php b/redirect.php new file mode 100644 index 0000000..39969f5 --- /dev/null +++ b/redirect.php @@ -0,0 +1,15 @@ +GO HOME'); +} +require('template/header.html'); +require('template/footer.php'); +?> + \ No newline at end of file diff --git a/template/footer.php b/template/footer.php new file mode 100644 index 0000000..848601c --- /dev/null +++ b/template/footer.php @@ -0,0 +1,8 @@ + + + +":''?> \ No newline at end of file diff --git a/template/header.html b/template/header.html new file mode 100644 index 0000000..34b9b1d --- /dev/null +++ b/template/header.html @@ -0,0 +1,12 @@ + + + Mastodon Algorithm + + + + + + + Welcome, . Not you? Logout + +