diff options
| -rw-r--r-- | index.html | 14 | ||||
| -rw-r--r-- | login.html | 5 | ||||
| -rw-r--r-- | scripts/common/common.js | 2 | ||||
| -rw-r--r-- | scripts/common/current-user.js | 34 | ||||
| -rw-r--r-- | scripts/login.js | 31 | ||||
| -rw-r--r-- | scripts/signup.js | 41 | ||||
| -rw-r--r-- | scripts/user/profile.js | 0 | ||||
| -rw-r--r-- | scripts/user/user.js | 0 | ||||
| -rw-r--r-- | signup.html | 21 | ||||
| -rw-r--r-- | user/index.html | 37 | ||||
| -rw-r--r-- | user/profile.html | 39 |
11 files changed, 208 insertions, 16 deletions
@@ -5,14 +5,14 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ComXII</title> - <link type="text/css" rel="stylesheet" href="./styles/base.css" /> + <link type="text/css" rel="stylesheet" href="/styles/base.css" /> </head> <body> <nav> <!-- Logo for ComXII --> <div> <a href="./"> - <img id="logo" alt="ComXII Home Page" src="./assets/comxii.svg" /> + <img id="logo" alt="ComXII Home Page" src="/assets/comxii.svg" /> </a> </div> @@ -23,10 +23,10 @@ <!-- User profile --> <div id="user-nav"> - <a href="./login.html"> - <img id="user-profile" alt="User Profile Photo" src="./assets/profile.png"> + <a href="/login.html"> + <img id="user-profile" alt="User Profile Photo" src="/assets/profile.png"> </a> - <a href="./login.html" id="user-link" class="secondary" style="height: auto; margin-left: 15px;">Login</a> + <a href="/login.html" id="user-link" class="secondary" style="height: auto; margin-left: 15px;">Login</a> </div> </nav> @@ -37,5 +37,9 @@ <footer> <span>(C) <a href="https://cshift.net" class="secondary">CircleShift</a> 2026</span> </footer> + + <!-- Scripts --> + <script src="/scripts/common/common.js"></script> + <script defer src="/scripts/common/current-user.js"></script> </body> </html>
\ No newline at end of file @@ -44,5 +44,10 @@ <footer> <span>(C) <a href="https://cshift.net" class="secondary">CircleShift</a> 2026</span> </footer> + + <!-- Scripts --> + <script src="./scripts/common/common.js"></script> + <script defer src="./scripts/common/current-user.js"></script> + <script defer src="./scripts/login.js"></script> </body> </html>
\ No newline at end of file diff --git a/scripts/common/common.js b/scripts/common/common.js new file mode 100644 index 0000000..256cd21 --- /dev/null +++ b/scripts/common/common.js @@ -0,0 +1,2 @@ +const API_BASE_URL="https://comxii.net/api"; + diff --git a/scripts/common/current-user.js b/scripts/common/current-user.js new file mode 100644 index 0000000..9e29927 --- /dev/null +++ b/scripts/common/current-user.js @@ -0,0 +1,34 @@ +var User = {}; + +/** + * Handles + * @param {ProgressEvent} event + * @this {XMLHttpRequest} + */ +function update_user_data (event) { + let result = JSON.parse(this.responseText); + + if (this.status >= 400) + return; + + User = result; + + // Grab and change user links to point at user orofile, link text to username + /** @type {HTMLLinkElement} */ + let link = document.getElementById("user-link"); + /** @type {HTMLImageElement} */ + let profile_icon = document.getElementById("user-profile"); + + link.href = "/user/" + profile_icon.parentElement.href = "/user/" + link.innerText = "Go To Profile" +} + +// Run at start, grab user information and replace the login link as well as the user object +(() => { + let user_req = new XMLHttpRequest(); + user_req.addEventListener("load", update_user_data); + user_req.open("GET", API_BASE_URL + "/user"); + user_req.send(); +})(); + diff --git a/scripts/login.js b/scripts/login.js new file mode 100644 index 0000000..bc41fd4 --- /dev/null +++ b/scripts/login.js @@ -0,0 +1,31 @@ +(() => { + /** + * Login to the api layer + * @param {ProgressEvent} e + * @this {XMLHttpRequest} + */ + function login (e) { + if (this.status == 200) { + // Go back to home + window.location = "/"; + } else { + // Show invalid username/password text + alert("Invalid username or password!"); + } + } + + /** @type {HTMLInputElement} */ + let username = document.getElementById("username"); + /** @type {HTMLInputElement} */ + let password = document.getElementById("password"); + + document.getElementById("login").addEventListener("click", () => { + let login_req = new XMLHttpRequest(); + login_req.addEventListener("load", login); + login_req.open("POST", API_BASE_URL + "/user/login"); + login_req.send(JSON.stringify({ + username: username.value, + password: password.value, + })); + }) +})();
\ No newline at end of file diff --git a/scripts/signup.js b/scripts/signup.js index e69de29..f07630a 100644 --- a/scripts/signup.js +++ b/scripts/signup.js @@ -0,0 +1,41 @@ +(() => { + /** + * Signup to the api layer + * @param {ProgressEvent} e + * @this {XMLHttpRequest} + */ + function signup (e) { + if (this.status == 200) { + // Go to login + window.location = "./login.html"; + } else { + // Show invalid username/password text + alert(this.responseText); + } + } + + /** @type {HTMLInputElement} */ + let username = document.getElementById("username"); + /** @type {HTMLInputElement} */ + let email = document.getElementById("email"); + /** @type {HTMLInputElement} */ + let password = document.getElementById("password"); + /** @type {HTMLInputElement} */ + let password_confirm = document.getElementById("password_confirm"); + + document.getElementById("signup").addEventListener("click", () => { + if (password.value != password_confirm.value) { + alert("Passwords don't match!"); + return; + } + + let signup_req = new XMLHttpRequest(); + signup_req.addEventListener("load", signup); + signup_req.open("POST", API_BASE_URL + "/user"); + signup_req.send(JSON.stringify({ + username: username.value, + password: password.value, + email: email.value, + })); + }) +})();
\ No newline at end of file diff --git a/scripts/user/profile.js b/scripts/user/profile.js new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/scripts/user/profile.js diff --git a/scripts/user/user.js b/scripts/user/user.js new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/scripts/user/user.js diff --git a/signup.html b/signup.html index a6cfa89..ba5a590 100644 --- a/signup.html +++ b/signup.html @@ -5,15 +5,15 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Sign Up</title> - <link type="text/css" rel="stylesheet" href="./styles/base.css" /> - <link type="text/css" rel="stylesheet" href="./styles/signup.css" /> + <link type="text/css" rel="stylesheet" href="/styles/base.css" /> + <link type="text/css" rel="stylesheet" href="/styles/signup.css" /> </head> <body> <nav> <!-- Logo for ComXII --> <div id="logo-nav"> - <a href="./"> - <img id="logo" alt="ComXII Home Page" src="./assets/comxii.svg" /> + <a href="/"> + <img id="logo" alt="ComXII Home Page" src="/assets/comxii.svg" /> </a> </div> @@ -24,10 +24,10 @@ <!-- User profile --> <div id="user-nav"> - <a href="./login.html"> - <img id="user-profile" alt="User Profile Photo" src="./assets/profile.png"> + <a href="/login.html"> + <img id="user-profile" alt="User Profile Photo" src="/assets/profile.png"> </a> - <a href="./login.html" id="user-link" class="secondary" style="height: auto; margin-left: 15px;">Login</a> + <a href="/login.html" id="user-link" class="secondary" style="height: auto; margin-left: 15px;">Login</a> </div> </nav> @@ -39,12 +39,17 @@ <div><label for="password">Password:</label><input type="password" id="password" /></div> <div><label for="password_confirm">Confirm Password:</label><input type="password" id="password_confirm" /></div> <button id="signup">Sign Up</button> - <span style="text-align: center; margin-top:15px;">Have an account? <a href="./login.html">Login</a></span> + <span style="text-align: center; margin-top:15px;">Have an account? <a href="/login.html">Login</a></span> </div> </content> <footer> <span>(C) <a href="https://cshift.net" class="secondary">CircleShift</a> 2026</span> </footer> + + <!-- Scripts --> + <script src="/scripts/common/common.js"></script> + <script defer src="/scripts/common/current-user.js"></script> + <script defer src="/scripts/signup.js"></script> </body> </html>
\ No newline at end of file diff --git a/user/index.html b/user/index.html index e8ef4a9..886cb9a 100644 --- a/user/index.html +++ b/user/index.html @@ -4,8 +4,43 @@ <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Profile</title> + + <link type="text/css" rel="stylesheet" href="/styles/base.css" /> </head> <body> - + <nav> + <!-- Logo for ComXII --> + <div> + <a href="/"> + <img id="logo" alt="ComXII Home Page" src="/assets/comxii.svg" /> + </a> + </div> + + <!-- Nav menu --> + <div id="main-nav"> + + </div> + + <!-- User profile --> + <div id="user-nav"> + <a href="/login.html"> + <img id="user-profile" alt="User Profile Photo" src="/assets/profile.png"> + </a> + <a href="/login.html" id="user-link" class="secondary" style="height: auto; margin-left: 15px;">Login</a> + </div> + </nav> + + <content> + + </content> + + <footer> + <span>(C) <a href="https://cshift.net" class="secondary">CircleShift</a> 2026</span> + </footer> + + <!-- Scripts --> + <script src="/scripts/common/common.js"></script> + <script defer src="/scripts/common/current-user.js"></script> + <script defer src="/scripts/user/user.js"></script> </body> </html>
\ No newline at end of file diff --git a/user/profile.html b/user/profile.html index 015db48..6b89f0e 100644 --- a/user/profile.html +++ b/user/profile.html @@ -3,9 +3,44 @@ <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>User Profile</title> + <title id="title">User Profile</title> + + <link type="text/css" rel="stylesheet" href="../styles/base.css" /> </head> <body> - + <nav> + <!-- Logo for ComXII --> + <div> + <a href="../"> + <img id="logo" alt="ComXII Home Page" src="../assets/comxii.svg" /> + </a> + </div> + + <!-- Nav menu --> + <div id="main-nav"> + + </div> + + <!-- User profile --> + <div id="user-nav"> + <a href="../login.html"> + <img id="user-profile" alt="User Profile Photo" src="../assets/profile.png"> + </a> + <a href="../login.html" id="user-link" class="secondary" style="height: auto; margin-left: 15px;">Login</a> + </div> + </nav> + + <content> + + </content> + + <footer> + <span>(C) <a href="https://cshift.net" class="secondary">CircleShift</a> 2026</span> + </footer> + + <!-- Scripts --> + <script src="../scripts/common/common.js"></script> + <script defer src="../scripts/common/current-user.js"></script> + <script defer src="../scripts/user/profile.js"></script> </body> </html>
\ No newline at end of file |