From 349b28bb8f160c9c9cc266aaa3e41bd88dfa1b8a Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 17 Jul 2021 15:50:58 -0700 Subject: [PATCH] First Commit --- .gitignore | 1 + login.html | 36 ++++++++++++++++++++++++ login.js | 45 ++++++++++++++++++++++++++++++ loginchange.html | 41 +++++++++++++++++++++++++++ loginchange.js | 60 ++++++++++++++++++++++++++++++++++++++++ register.html | 49 ++++++++++++++++++++++++++++++++ register.js | 51 ++++++++++++++++++++++++++++++++++ style.css | 51 ++++++++++++++++++++++++++++++++++ workspace.code-workspace | 8 ++++++ 9 files changed, 342 insertions(+) create mode 100644 .gitignore create mode 100644 login.html create mode 100644 login.js create mode 100644 loginchange.html create mode 100644 loginchange.js create mode 100644 register.html create mode 100644 register.js create mode 100644 style.css create mode 100644 workspace.code-workspace diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..04e8c9b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +workspace.dode-workspace \ No newline at end of file diff --git a/login.html b/login.html new file mode 100644 index 0000000..a1374dd --- /dev/null +++ b/login.html @@ -0,0 +1,36 @@ + + + + + Login + + + + + + + + + + +

Login:

+ +
+
+
+
+ +
+

+ + +
+
+ + + +
+ +

You are logged in as

+ + \ No newline at end of file diff --git a/login.js b/login.js new file mode 100644 index 0000000..9ef79b9 --- /dev/null +++ b/login.js @@ -0,0 +1,45 @@ +let uname = document.querySelector('#uname').value; // grabbing the username submitted and putting it in the variable uname +let pin = document.querySelector('#pin').value; // grabbing the pin submitted and putting it in the variable pin +const form = document.querySelector('form'); // grabbing an element on the page +const API_URL = `http://127.0.0.1:8000` + + +form.addEventListener("submit", async function(event) { + event.preventDefault(); + const formData = new FormData(form); + + uname = formData.get('uname'); + pin = formData.get('pin'); + + const loginInfo = await loginFetch(); + + if (loginInfo === "pin matches") { + login() + } else if (loginInfo === "Incorrect pin" || loginInfo === `User ${uname} does not exist.`) { + incorrectLogin() + } + +}) + +async function loginFetch() { + const rawResponse = await fetch(`${API_URL}/api/users/${uname}/${pin}`, { + method: 'GET', + headers: { + 'Accept': 'text/plain' + }, +}); +const content = await rawResponse.text(); +return content +} + +function login() { + console.log('You have logged in!') + document.querySelector("#username").innerHTML = `${uname}` + document.querySelector("#incorrect").innerHTML = '' +} + +function incorrectLogin() { + console.log('Incorrect Login!') + document.querySelector("#incorrect").innerHTML = 'Incorrect Login.' +} + \ No newline at end of file diff --git a/loginchange.html b/loginchange.html new file mode 100644 index 0000000..98fcea3 --- /dev/null +++ b/loginchange.html @@ -0,0 +1,41 @@ + + + + + Login Change + + + + + + + + + + +

Change username and/or pin:

+

(leave field blank if not changing)

+ +
+
+
+
+ +
+

+ +
+
+ +
+

+ + +
+
+ + + +
+ + \ No newline at end of file diff --git a/loginchange.js b/loginchange.js new file mode 100644 index 0000000..ee4d211 --- /dev/null +++ b/loginchange.js @@ -0,0 +1,60 @@ +let uname = document.querySelector('#uname').value; +let pin = document.querySelector('#pin').value; +let newUname = document.querySelector('#newuname').value; +let newPin = document.querySelector('#newpin').value; +// let selected = document.querySelector('#selected').value; +// let custom = document.querySelector('#custom').value; +// let pronouns = '' +let responseText; +const form = document.querySelector('form'); +const API_URL = `http://127.0.0.1:8000` + +form.addEventListener("submit", async function(event) { + event.preventDefault(); + const formData = new FormData(form); + + uname = formData.get('uname'); + pin = formData.get('pin'); + newUname = formData.get('newuname'); + newPin = formData.get('newpin'); + // selected = formData.get('selected'); + // custom = formData.get('custom') + + // if (custom !== '') { + // pronouns = custom + // } else { + // pronouns = selected + // } + + if (newUname === '') { + newUname = uname + } + if (newPin === '') { + newPin = pin + } + + const userNotFound = await getUname(); + + if (userNotFound !== `User ${uname}`) { + document.querySelector("#incorrect").innerHTML = `user ${uname} was not found` + } else { + loginChange() + } +}) + +async function getUname() { + let response = await fetch(`${API_URL}/api/users/${uname}`); + responseText = await response.text(); + return responseText; +} + +async function loginChange() { +const rawResponse = await fetch(`${API_URL}/api/users/change/${uname}/${pin}/${newUname}/${newPin}`, { + method: 'POST', + headers: { + 'Accept': 'text/plain' + }, + body: "" +}); +//rawResponse.then(window.location.replace("http://127.0.0.1:5500/login.html")) +} diff --git a/register.html b/register.html new file mode 100644 index 0000000..db32d8e --- /dev/null +++ b/register.html @@ -0,0 +1,49 @@ + + + + + Register + + + + + + + + +

Register:

+ + +
+
+
+
+ +
+
+ +
+
+ +

Or.

+ +
+

+ + +
+
+ +
+ + + + + \ No newline at end of file diff --git a/register.js b/register.js new file mode 100644 index 0000000..f3b9d26 --- /dev/null +++ b/register.js @@ -0,0 +1,51 @@ +let uname = document.querySelector('#uname').value; // grabbing the username submitted and putting it in the variable uname +let pin = document.querySelector('#pin').value; // grabbing the pin submitted and putting it in the variable pin +let selected = document.querySelector('#selected').value; +let custom = document.querySelector('#custom').value; +let pronouns = '' +let responseText; +const form = document.querySelector('form'); // grabbing an element on the page +const API_URL = `http://127.0.0.1:8000` + +form.addEventListener("submit", async function(event) { + event.preventDefault(); + const formData = new FormData(form); + + uname = formData.get('uname'); + pin = formData.get('pin'); + selected = formData.get('selected'); + custom = formData.get('custom') + + if (custom !== '') { + pronouns = custom + } else { + pronouns = selected + } + + const isTaken = await getUname(); + + if (isTaken === `User ${uname}`) { + console.log("This username is taken.") + document.querySelector("#taken").innerHTML = `${uname} is already taken.` + } else { + register() + } +}) + +async function getUname() { + let response = await fetch(`${API_URL}/api/users/${uname}`); + responseText = await response.text(); + return responseText; +} + +async function register() { +const rawResponse = await fetch(`${API_URL}/api/register/${uname.toString().toLowerCase()}/${pin.toString()}/${pronouns.toString().toLowerCase()}`, { + method: 'POST', + headers: { + 'Accept': 'text/plain' + }, + body: "" +}); +//rawResponse.then(window.location.replace("http://127.0.0.1:5500/login.html")) +} + diff --git a/style.css b/style.css new file mode 100644 index 0000000..7e17474 --- /dev/null +++ b/style.css @@ -0,0 +1,51 @@ +html { + background: #F7A8B8; + text-align: center; + font-family: "Lucida Console", "Courier New", monospace; +} + +body { + margin-top: 10%; +} + +#box { + background-color: white; + padding: 5%; + box-shadow: 10px 10px 10px black; + border-radius: 10px; + display:inline-flex; +} + +#taken { + padding-top: 1%; +} + +#incorrect { + padding-top: 1%; +} + +label { + font-family: "Lucida Console", "Courier New", monospace; +} + +input { + background-color: #55CDFC; + border-style: none; + border-bottom-style: solid; + border-bottom-color: black; + border-bottom-width: 1px; + font-family: "Lucida Console", "Courier New", monospace; +} + +input:focus { + outline: none; +} + +input[type=number]::-webkit-inner-spin-button, +input[type=number]::-webkit-outer-spin-button { + -webkit-appearance: none; +} + +input[type=number] { + -moz-appearance: textfield; +} diff --git a/workspace.code-workspace b/workspace.code-workspace new file mode 100644 index 0000000..876a149 --- /dev/null +++ b/workspace.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": {} +} \ No newline at end of file