diff --git a/main b/main index 7cedd61..5ca7571 100644 --- a/main +++ b/main @@ -579,14 +579,14 @@ async def signup(): async def logout(): return await render_template("logout.html") -@app.route("/homeserver") -async def homeserver(): - return await render_template("homeserver.html") - @app.route("/app") async def mainapp(): return await render_template("main.html") +@app.route("/dashboard") +async def dashboard(): + return await render_template("dashboard.html") + @app.route("/.well-known/openid-configuration") async def openid(): return await render_template("openid.json") diff --git a/static/css/dashboard.css b/static/css/dashboard.css new file mode 100644 index 0000000..d4507d7 --- /dev/null +++ b/static/css/dashboard.css @@ -0,0 +1,61 @@ +body { + font-family: Arial, sans-serif; + text-align: center; + overflow-wrap: anywhere; +} + +.newoauth, .oauthlist, .oauthentry { + width: calc(100% - 17.5vh); + margin-top: 7vh; + margin-left: 7vh; + margin-right: 7vh; + padding: 15px 10px 30px; + border-style: solid; + border-image: none; + border-radius: 8px; + border-width: 1px; + font-size: 17px; + background-color: rgb(235, 255, 235); +} + +.oauthentry { + display: flex; + flex-direction: column; + justify-content: center; + padding: 5px; + background-color: lightcyan; +} + +.oauthentry button { + padding: 10px; + background-color: red; + color: white +} + +.oauthentry button:hover { + background-color: black; +} + +button { + border: 1px solid black; + padding: 3px; + border-radius: 5px; + background-color: lightcyan; + transition: all 0.3s ease 0s; +} + +button:hover { + background-color: white; +} + +h { + display: block; + margin-top: 20px; + font-size: 20px; +} + +input { + padding: 3px; + border-radius: 5px; + border: black solid 1px; +} diff --git a/static/js/dashboard.js b/static/js/dashboard.js new file mode 100644 index 0000000..399c32c --- /dev/null +++ b/static/js/dashboard.js @@ -0,0 +1,79 @@ +function attempt() { + if (document.getElementById("appidbox").value.match(/^[A-Za-z]+$/)) { + fetch("https://auth.hectabit.org/api/newauth", { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + appId: document.getElementById("appidbox").value, + secretKey: localStorage.getItem("DONOTSHARE-secretkey") + }) + }) + .then(response => { + async function doStuff() { + let code = await response.json() + if (response.status == 200) { + document.getElementById("status").innerText = "Your key is: " + code["key"] + ". This will only be shown once!" + getauths(); + } else if (response.status == 500) { + document.getElementById("status").innerText = "Whoops... Something went wrong. Please try again later. (Error Code 500)" + } else if (response.status == 401) { + document.getElementById("status").innerText = "AppID already taken. (Error Code 401)" + } else { + document.getElementById("status").innerText = "Unkown error encountered. (Error Code " + response.status + ")" + } + } + doStuff() + }) + } +} + +function getauths() { + fetch("https://auth.hectabit.org/api/listauth", { + method: "POST", + body: JSON.stringify({ + secretKey: localStorage.getItem("DONOTSHARE-secretkey") + }), + headers: { + "Content-Type": "application/json; charset=UTF-8" + } + }) + .then((response) => { + async function doStuff() { + let responseData = await response.json() + document.querySelectorAll(".oauthentry").forEach((el) => el.remove()); + for (let i in responseData) { + let oauthElement = document.createElement("div") + let oauthText = document.createElement("p") + let oauthRemoveButton = document.createElement("button") + oauthText.innerText = "Client ID: " + responseData[i]["appId"] + oauthRemoveButton.innerText = "Delete Permanently" + oauthRemoveButton.addEventListener("click", (event) => { + if (window.confirm("Are you SURE you would like to delete this FOREVER?") == true) { + fetch("https://auth.hectabit.org/api/deleteauth", { + method: "POST", + body: JSON.stringify({ + secretKey: localStorage.getItem("DONOTSHARE-secretkey"), + appId: responseData[i]["appId"] + }), + headers: { + "Content-Type": "application/json; charset=UTF-8" + } + }) + oauthElement.remove() + } + }); + + oauthElement.append(oauthText) + oauthElement.append(oauthRemoveButton) + oauthElement.classList.add("oauthentry") + + document.getElementById("oauthlist").append(oauthElement) + } + } + doStuff() + }); +} + +getauths() diff --git a/static/js/homeserver.js b/static/js/homeserver.js deleted file mode 100644 index d86a65e..0000000 --- a/static/js/homeserver.js +++ /dev/null @@ -1,54 +0,0 @@ -let homeserverBox = document.getElementById("homeserverBox") -let statusBox = document.getElementById("statusBox") -let changeButton = document.getElementById("changeButton") - -function showElements(yesorno) { - if (!yesorno) { - homeserverBox.classList.add("hidden") - changeButton.classList.add("hidden") - } - else { - homeserverBox.classList.remove("hidden") - changeButton.classList.remove("hidden") - } -} - -changeButton.addEventListener("click", (event) => { - async function doStuff() { - let remote = homeserverBox.value - - if (remote == "") { - statusBox.innerText = "A homeserver is required!" - return - } - - showElements(false) - statusBox.innerText = "Connecting to homeserver..." - - fetch(remote + "/api/version") - .then((response) => response) - .then((response) => { - async function doStuff() { - if (response.status == 200) { - localStorage.setItem("homeserverURL", remote) - - if (document.referrer !== "") { - window.location.href = document.referrer; - } - else { - window.location.href = "../login"; - } - } - else if (response.status == 404) { - statusBox.innerText = "Not a valid homeserver!" - } - else { - statusBox.innerText = "Something went wrong!" - showElements(true) - } - } - doStuff() - }); - } - doStuff() -}); diff --git a/templates/dashboard.html b/templates/dashboard.html new file mode 100644 index 0000000..9d089c7 --- /dev/null +++ b/templates/dashboard.html @@ -0,0 +1,19 @@ + + + + + + + +
+ Submit a new OAuth2 App +

+

AppID:

+ + +
+
+ Your existing apps +
+ + diff --git a/templates/homeserver.html b/templates/homeserver.html deleted file mode 100644 index f214861..0000000 --- a/templates/homeserver.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - Change homeserver - - - - - - - - - - -

Image by perga (@pergagreen on discord)

- -
-

Homeserver

-

Change your homeserver

-

- -
-

-

Please put in the URL in standard format; https://, http://, etc.

-
- - - - - diff --git a/templates/login.html b/templates/login.html index c38918a..17ed7ab 100644 --- a/templates/login.html +++ b/templates/login.html @@ -34,7 +34,6 @@

Don't have an account? If so, Create one here!

-

Your homeserver is loading...

Change
Privacy & Terms diff --git a/templates/signup.html b/templates/signup.html index 1a0a023..2149bc7 100644 --- a/templates/signup.html +++ b/templates/signup.html @@ -32,7 +32,6 @@

Already have an account? If so, Login instead!

Please note that it's impossible to reset your password, do not forget it!

-

Your homeserver is loading...

Change
Privacy & Terms