Compare commits

...

37 commits

Author SHA1 Message Date
esy
e09818ca6b feat: add license
Some checks failed
Build / build (push) Failing after 39s
Build / deploy (push) Has been skipped
2024-09-23 20:07:50 +00:00
71f5928c66 ci: swapped out gitlab for forgejo actions
All checks were successful
Build / build (push) Successful in 13s
Build / deploy (push) Successful in 8s
2024-08-09 21:16:59 +01:00
36c5e5bbae Merge branch '#7-multiple-ssh-keys' into 'main'
Frontend for new SSH page

Closes #7

See merge request compsoc1/skynet/ldap/frontend!12
2024-02-18 17:28:20 +00:00
daragh
92a83a2079
fmt , made default textarea bigger 2024-02-18 16:47:22 +00:00
daragh
0851e9934d
fix : styling and word wrap 2024-02-18 16:30:16 +00:00
daragh
e4a48864ad
fix : trailing slash 2024-02-18 13:34:31 +00:00
daragh
318b4136b0
fix : correct api endpoints 2024-02-18 13:32:29 +00:00
daragh
dcbce9942b
Table now refreshes after deleting / adding key
Can get keys multiple times, ssh key is now an attribute of the row, so
no weird logic when deleting the key.
Tested with mockoon seems to be working.
2024-02-18 02:42:06 +00:00
daragh
5f11bbce09 feat : changed post_request to be more general and return true/false based on response 2024-01-01 18:36:48 +00:00
daragh
c215c710b9 fix : remove ssh from modify page , added ssh page to index.html 2024-01-01 18:01:43 +00:00
daragh
cb806ad893 fix : rename ssh.js 2024-01-01 17:16:50 +00:00
daragh
7c2a3e6414 fix : now can catch any errors thrown by awaiting req.json() 2024-01-01 17:16:10 +00:00
daragh
7100dad705 fix : moved ssh stuff int src/ 2024-01-01 17:02:37 +00:00
daragh
a12bd3e040 Merge branch 'main' of https://gitlab.skynet.ie/compsoc1/skynet/ldap/frontend into #7-multiple-ssh-keys
# Conflicts:
#	src/index.html
2024-01-01 16:48:44 +00:00
d3b4c822b9 Merge branch '#9-not-correctly-showing-errors' into 'main'
Fix errors not being propogated to teh end user.

Closes #9

See merge request compsoc1/skynet/ldap/frontend!13
2024-01-01 10:11:01 +00:00
9042ce0df9 feat: since most pages were posting to the api and displaying any errors its easier to turn it into a shared function for easy refactoring.
Related to #9
2024-01-01 10:06:21 +00:00
4881be37e1 feat: Moved the JS out of the username reminder page into its own file
Related to #9
2024-01-01 09:44:21 +00:00
741bb8c7ca feat: Moved the JS out of the ssh recovery page into its own file
Related to #9
2024-01-01 09:41:24 +00:00
ae433303b8 feat: Moved the JS out of the password recovery_reset page into its own file
Related to #9
2024-01-01 09:36:30 +00:00
eec783bd77 feat: Moved the JS out of the password recovery page into its own file
Related to #9
2024-01-01 09:31:32 +00:00
ad55bf81ef fix: not going to give these their own folder 2024-01-01 09:28:22 +00:00
68953f0d5f feat: Moved the JS out of the signup page into its own file
Related to #9
2024-01-01 09:24:48 +00:00
da7adea36e feat: Moved the JS out of the register page into its own file
Related to #9
2024-01-01 09:19:34 +00:00
019d22695f feat: Moved the JS out of the password reset page into its own file
Related to #9
2024-01-01 09:09:38 +00:00
a7bde90cb8 feat: Moved the JS out of the modify page into its own file
Related to #9
2024-01-01 09:09:38 +00:00
daragh
c6e0714485
fmt : newline 2023-12-31 08:35:16 +00:00
daragh
202c89ca74
fix : early return, logging errors into frontend 2023-12-31 08:18:33 +00:00
daragh
9b9ea81206
fix : removed testing api endpoints with actual 2023-12-31 07:09:31 +00:00
daragh
128794648c
feat : made input for new key textarea, split keys on their comment to display in table. Made js code use async/await instead of then.
Works fine with mockoon but might need more testing with actual LDAP server.
2023-12-30 23:27:32 +00:00
daragh
7f40a4b259
feat : added link to SSH page from main page
Might also need to remove SSH stuff from modify page
2023-12-30 04:07:35 +00:00
daragh
0af81c6efa
fix : fetch paths 2023-12-30 01:55:45 +00:00
daragh
040fdeaf4a
Merge remote-tracking branch 'origin/#7-multiple-ssh-keys' into #7-multiple-ssh-keys 2023-12-30 01:48:06 +00:00
daragh
115f0257e5
feat : frontend for adding & deleting keys 2023-12-30 01:47:41 +00:00
b2c23910fb Merge branch frontend:main into #7-multiple-ssh-keys 2023-12-27 20:02:09 +00:00
520464b73d Merge branch '#8_deal_with_new_auth_process' into 'main'
feat: adjust any form that takes the users username and pass so its in the auth field.

Closes #8

See merge request compsoc1/skynet/ldap/frontend!11
2023-12-27 14:49:29 +00:00
ec5ecd504c feat: adjust any form that takes teh suers username and pass so its in the auth field.
Closes #8
2023-12-27 14:47:29 +00:00
daragh
1e2d2c0408
feat : added frontend for getting ssh keys 2023-12-24 22:15:06 +00:00
23 changed files with 605 additions and 360 deletions

View file

@ -0,0 +1,28 @@
name: Build
on:
push:
branches:
- 'main'
jobs:
build:
# build it using teh base nixos system, helps with caching
runs-on: nix
steps:
# get the repo first
- uses: https://code.forgejo.org/actions/checkout@v4
- name: "Build it locally"
run: nix build --verbose
# deploy it upstream
deploy:
# runs on teh default docker dontainer
runs-on: docker
needs: [ build ]
steps:
- name: "Deploy to Skynet"
uses: https://forgejo.skynet.ie/Skynet/actions-deploy-to-skynet@v2
with:
input: 'skynet_ldap_frontend'
token: ${{ secrets.API_TOKEN_FORGEJO }}

View file

@ -1,17 +0,0 @@
# from https://docs.gitlab.com/ee/ci/pipelines/multi_project_pipelines.html
# only a deploy stage
stages:
- deploy
nixos:
stage: deploy
variables:
PACKAGE_NAME: "skynet_ldap_frontend"
UPDATE_FLAKE: "yes"
trigger: compsoc1/skynet/nixos
only:
refs:
- main

9
LICENSE Normal file
View file

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2024 Skynet
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -15,7 +15,7 @@
<main class="page-body"> <main class="page-body">
<section> <section>
<h2> <h2>
<a href="./signup.html">Sign-up</a> <a href="signup.html">Sign-up</a>
</h2> </h2>
<p> <p>
Please use this if you have yet to activate an account on Skynet before. Please use this if you have yet to activate an account on Skynet before.
@ -23,7 +23,7 @@
</section> </section>
<section> <section>
<h2> <h2>
<a href="./password.html">Change Password</a> <a href="password.html">Change Password</a>
</h2> </h2>
<p> <p>
Please use this service to change your Skynet password Please use this service to change your Skynet password
@ -31,10 +31,10 @@
</section> </section>
<section> <section>
<h2> <h2>
<a href="./modify.html">Account modification</a> <a href="modify.html">Account modification</a>
</h2> </h2>
<p> <p>
Please use this service to modify your user data (email, login ssh key, etc.) Please use this service to modify your user data (email, login, etc.)
</p> </p>
</section> </section>
<section> <section>
@ -53,6 +53,14 @@
Please use this service to reset your password. Please use this service to reset your password.
</p> </p>
</section> </section>
<section>
<h2>
<a href="modify_ssh.html">SSH</a>
</h2>
<p>
Please use this service to add or remove SSH keys from your Skynet account.
</p>
</section>
</main> </main>
<footer class="page-footer"> <footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span> UL Computer Society 2023-<span id="year">2023</span>

23
src/js/lib.js Normal file
View file

@ -0,0 +1,23 @@
export async function request(url, body, form_status, method) {
try {
const req = await fetch(url, {
method: method,
body: JSON.stringify(body),
mode: "cors"
});
if (req.status !== 200) {
form_status.innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
}
let temp = await req.json();
if (temp.result === 'error') {
form_status.innerHTML = `<span style='background-color: red; color: white'>${temp.error}</span>`;
} else {
form_status.innerHTML = "<span style='background-color: green; color: white'>Success</span>";
return true;
}
} catch (e) {
form_status.innerHTML = `<span style='background-color: red; color: white'>${e}</span>`;
}
return false;
}

View file

@ -3,13 +3,13 @@
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<title>Modify Account</title> <title>Modify Account</title>
<link href="./images/favicon/favicon-16x16.png" rel="icon" type="image/png"/> <link href="images/favicon/favicon-16x16.png" rel="icon" type="image/png"/>
<link href="./stylesheets/index.css" rel="stylesheet" type="text/css"/> <link href="stylesheets/index.css" rel="stylesheet" type="text/css"/>
</head> </head>
<body> <body>
<div class="wrapper"> <div class="wrapper">
<header class="page-header"> <header class="page-header">
<img alt="Sharky, our mascot" height="81.56" src="./images/sharky.svg" width="145"/> <img alt="Sharky, our mascot" height="81.56" src="images/sharky.svg" width="145"/>
<h1>Skynet Self Service</h1> <h1>Skynet Self Service</h1>
</header> </header>
<main class="page-body"> <main class="page-body">
@ -17,7 +17,7 @@
<p> <p>
Modify details of your Skynet account. Modify details of your Skynet account.
</p> </p>
<form id="reset"> <form id="form">
<table id="table"> <table id="table">
<tr> <tr>
<td><label for="user">Username</label></td> <td><label for="user">Username</label></td>
@ -28,15 +28,13 @@
<td><input id="pass" name="pass" type="password"/> <br/></td> <td><input id="pass" name="pass" type="password"/> <br/></td>
</tr> </tr>
<tr> <tr>
<td><label for="field">Field</label></td> <td><label for="dropdown">Field</label></td>
<td> <td>
<select id="field" onchange="selectField()"> <select id="dropdown">
<option selected="selected" value="">Please select an option</option> <option selected="selected" value="">Please select an option</option>
<option value="mail">Email</option> <option value="mail">Email</option>
<option value="sshPublicKey">SSH key</option>
<option value="cn">First name & Surname</option> <option value="cn">First name & Surname</option>
<option value="sn">Surname</option> <option value="sn">Surname</option>
<option value="skDiscord">Discord username</option>
</select> </select>
</td> </td>
</tr> </tr>
@ -45,57 +43,12 @@
<td><input id="value" name="value" type="text"/> <br/></td> <td><input id="value" name="value" type="text"/> <br/></td>
</tr> </tr>
<tr> <tr>
<td colspan="2"><input type="Submit" value="Submit"/></td> <td colspan="2"><input type="Submit" value="Submit" id="button"/></td>
</tr> </tr>
</table> </table>
</form> </form>
<p id="formStatus"></p> <p id="formStatus"></p>
<script> <script type="module" src="modify.js"></script>
const formEl = document.getElementById("reset");
formEl.addEventListener('submit', (listener) => formHandler(listener));
function formHandler(listener) {
listener.preventDefault();
const formData = new FormData(formEl);
const field = document.getElementById('field').value;
if (field !== "") {
const user = formData.get("user");
const pass = formData.get("pass");
const value = formData.get("value");
const object = {user: user, pass: pass, field: field, value: value}
fetch('https://api.account.skynet.ie/ldap/update', {
method: 'POST',
body: JSON.stringify(object),
mode: "cors"
}).then(res => {
if (res.status === 200) {
let temp = res.json();
if (temp.result === 'error') {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>${temp.error}</span>`;
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
}
} else if (res.status === 500) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
}
}).catch(() => document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>");
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Please select a field to modify</span>";
}
}
function selectField() {
const field = document.getElementById('field').value;
const value = document.getElementById('value');
if (field === 'mail') {
value.type = 'email';
} else {
value.type = 'text';
}
}
</script>
</main> </main>
<footer class="page-footer"> <footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span> UL Computer Society 2023-<span id="year">2023</span>

39
src/modify.js Normal file
View file

@ -0,0 +1,39 @@
import {request} from "./js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
const form_status = document.getElementById("formStatus");
const button = document.getElementById("button");
button.addEventListener('submit', formHandler);
const dropdown = document.getElementById("dropdown");
dropdown.addEventListener('onchange', selectField);
async function formHandler(listener) {
listener.preventDefault();
const formData = new FormData(form);
const dropdown_value = dropdown.value;
if (dropdown_value === "") {
form_status.innerHTML = "<span style='background-color: red; color: white'>Please select a field to modify</span>";
return;
}
const user = formData.get("user");
const pass = formData.get("pass");
const value = formData.get("value");
const body = {auth: {user: user, pass: pass}, field: dropdown_value, value: value};
let url = 'https://api.account.skynet.ie/ldap/update';
await request(url, body, form_status, 'POST');
}
function selectField() {
if (dropdown.value === 'mail') {
document.getElementById('value').type = 'email';
} else {
document.getElementById('value').type = 'text';
}
}

95
src/modify_ssh.html Normal file
View file

@ -0,0 +1,95 @@
<!DOCTYPE html>
<html lang="en-ie">
<head>
<meta charset="UTF-8"/>
<title>SSH</title>
<link href="images/favicon/favicon-16x16.png" rel="icon" type="image/png"/>
<link href="stylesheets/index.css" rel="stylesheet" type="text/css"/>
<script type="module" src="modify_ssh.js"></script>
</head>
<style>
.center {
margin-left: auto;
margin-right: auto;
}
.center, .center th, .center td {
border: 1px solid white;
}
.center {
border-spacing: 0;
}
.center th, .center td {
margin: 3px;
}
#key_table {
display: none;
}
textarea {
width: 650px;
height: 57px;
}
</style>
<body>
<div class="wrapper">
<header class="page-header">
<img alt="Sharky, our mascot" height="81.56" src="images/sharky.svg" width="145"/>
<h1>Skynet Self Service</h1>
</header>
<main class="page-body">
<h2>SSH</h2>
<p>
Add / Remove SSH Keys from your account.
</p>
<form id="ssh_form">
<table id="table">
<tr>
<td><label for="user">Username</label></td>
<td><input id="user" name="user" type="text"/> <br/></td>
</tr>
<tr>
<td><label for="pass">Password</label></td>
<td><input id="pass" name="pass" type="password"/> <br/></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" id="get_keys"> Show current keys</button>
</td>
</tr>
</table>
</form>
<p id="formStatus"></p>
<div> SSH Keys</div>
<form id="add_key_form">
<label for="key_input"></label>
<textarea name="key_input" rows="4" cols="30" id="key_input"
placeholder="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINS2UR/o+nK8lNHHTj5I84ZAAp6P+ZhXqhedMfx0KHE4 My skynet key!"></textarea>
<button type="button" id="add_key_button"> Add key</button>
</form>
<br>
<table id="key_table" class="center">
<tr>
<th>Name</th>
<th>Key</th>
<th>Remove</th>
</tr>
</table>
</main>
<footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span>
<script>
document.getElementById('year').textContent = new Date().getFullYear().toString()
</script>
</footer>
</div>
</body>
</html>

139
src/modify_ssh.js Normal file
View file

@ -0,0 +1,139 @@
function update_table(keys) {
let table = document.getElementById("key_table")
//removing old table
while (table.rows.length > 0) {
table.deleteRow(0);
}
keys.forEach(key => {
add_to_table(key);
})
}
async function get_keys() {
let username = document.getElementById("user").value;
let password = document.getElementById("pass").value;
let request = {auth: {user: username, pass: password}};
try {
const response = await fetch('https://api.account.skynet.ie/ldap/ssh', {
method: 'POST',
body: JSON.stringify(request),
mode: 'cors',
});
if (response.status !== 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failed to fetch</span>";
return;
}
const data = await response.json();
if (data.result !== "success") {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>Error: ${data.error}</span>`;
return;
}
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success: Got keys</span>";
let keys = data.success;
document.getElementById('key_table').style.display = "table";
update_table(keys)
} catch (err) {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>Error: ${err}</span>`;
console.log(err);
}
}
async function add_key() {
let username = document.getElementById("user").value;
let password = document.getElementById("pass").value;
let key = document.getElementById("key_input").value;
let request = {auth: {user: username, pass: password}, key: key};
try {
const response = await fetch('https://api.account.skynet.ie/ldap/ssh/add', {
method: 'POST',
body: JSON.stringify(request),
mode: 'cors',
});
if (response.status !== 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failed to fetch</span>";
return;
}
const data = await response.json();
if (data.result !== "success") {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>Error: ${data.error}</span>`;
return;
}
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success: Added key </span>";
let keys = data.success;
update_table(keys);
} catch (err) {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>Error: ${err}</span>`;
console.log(err);
}
}
async function delete_key(row_idx, key) {
let username = document.getElementById("user").value;
let password = document.getElementById("pass").value;
let request = {auth: {user: username, pass: password}, key: key};
try {
const response = await fetch('https://api.account.skynet.ie/ldap/ssh', {
method: 'DELETE',
body: JSON.stringify(request),
mode: 'cors',
});
if (response.status !== 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failed to fetch</span>";
return;
}
const data = await response.json();
if (data.result !== "success") {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>Error: ${data.error}</span>`;
return;
}
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success: Deleted key </span>";
let keys = data.success;
update_table(keys);
} catch (err) {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>Error: ${err}</span>`;
console.log(err);
}
}
function add_to_table(key) {
let table = document.getElementById("key_table");
let row = table.insertRow();
row.setAttribute("ssh_key", key);
let cell_name = row.insertCell(0);
let cell_key = row.insertCell(1);
//This is just for displaying the key, probably can be simplified
//Splitting by spaces, first two make the key + type, rest is a comment/name of the key
let key_split = key.split(' ');
cell_key.textContent = `${key_split[0]} ${key_split[1]}`;
//Names for SSH keys can have multiple spaces
let comment = "";
for (let i = 2; i < key_split.length; i++) {
comment += " " + key_split[i];
}
if (key_split.length === 2) {
comment = "No comment";
}
cell_name.textContent = comment;
let cell_delete = row.insertCell(2);
let delete_button = document.createElement("button");
delete_button.innerHTML = "Delete";
cell_delete.appendChild(delete_button);
cell_delete.addEventListener("click", function () {
delete_key(row.rowIndex, row.getAttribute("ssh_key"));
});
}
document.addEventListener("DOMContentLoaded", () => {
document.getElementById("ssh_form").addEventListener("submit", function (event) {
event.preventDefault();
get_keys();
});
document.getElementById("add_key_button").addEventListener("click", add_key);
});

View file

@ -3,13 +3,13 @@
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<title>Password reset</title> <title>Password reset</title>
<link href="./images/favicon/favicon-16x16.png" rel="icon" type="image/png"/> <link href="images/favicon/favicon-16x16.png" rel="icon" type="image/png"/>
<link href="./stylesheets/index.css" rel="stylesheet" type="text/css"/> <link href="stylesheets/index.css" rel="stylesheet" type="text/css"/>
</head> </head>
<body> <body>
<div class="wrapper"> <div class="wrapper">
<header class="page-header"> <header class="page-header">
<img alt="Sharky, our mascot" height="81.56" src="./images/sharky.svg" width="145"/> <img alt="Sharky, our mascot" height="81.56" src="images/sharky.svg" width="145"/>
<h1>Skynet Self Service</h1> <h1>Skynet Self Service</h1>
</header> </header>
<main class="page-body"> <main class="page-body">
@ -17,7 +17,7 @@
<p> <p>
Change your Skynet password. Change your Skynet password.
</p> </p>
<form id="reset"> <form id="form">
<table id="table"> <table id="table">
<tr> <tr>
<td><label for="user">Username</label></td> <td><label for="user">Username</label></td>
@ -36,41 +36,12 @@
<td><input id="newPW2" name="newPWConfirm" type="password"/> <br/></td> <td><input id="newPW2" name="newPWConfirm" type="password"/> <br/></td>
</tr> </tr>
<tr> <tr>
<td colspan="2"><input type="Submit" value="Submit"/></td> <td colspan="2"><input id="button" type="Submit" value="Submit"/></td>
</tr> </tr>
</table> </table>
</form> </form>
<p id="formStatus"></p> <p id="formStatus"></p>
<script> <script type="module" src="password.js"></script>
const formEl = document.getElementById("reset");
formEl.addEventListener('submit', (listener) => formHandler(listener));
function formHandler(listener) {
listener.preventDefault();
const formData = new FormData(formEl);
const user = formData.get("user");
const pass = formData.get("pass");
const newPW = formData.get("newPW");
if (newPW === formData.get("newPWConfirm")) {
const object = {user: user, pass: pass, field: "userPassword", value: newPW}
fetch('https://api.account.skynet.ie/ldap/update', {
method: 'POST',
body: JSON.stringify(object),
mode: "cors"
}).then(res => {
if (res.status === 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
} else if (res.status === 500) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
}
}).catch(() => document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>");
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: new passwords don't match</span>";
}
}
</script>
</main> </main>
<footer class="page-footer"> <footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span> UL Computer Society 2023-<span id="year">2023</span>

28
src/password.js Normal file
View file

@ -0,0 +1,28 @@
import {request} from "./js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
const form_status = document.getElementById("formStatus");
const button = document.getElementById("button");
button.addEventListener('submit', formHandler);
async function formHandler(listener) {
listener.preventDefault();
const formData = new FormData(form);
const user = formData.get("user");
const pass = formData.get("pass");
const newPW = formData.get("newPW");
if (newPW !== formData.get("newPWConfirm")) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: new passwords don't match</span>";
return;
}
const body = {auth: {user: user, pass: pass}, field: "userPassword", value: newPW}
let url = 'https://api.account.skynet.ie/ldap/update';
await request(url, body, form_status, 'POST');
}

View file

@ -15,9 +15,11 @@
<main class="page-body"> <main class="page-body">
<h2>Forgot Password</h2> <h2>Forgot Password</h2>
<p> <p>
Request a password reset sent to your linked email. <br> Enter either email address or skynet username. </br> Request a password reset sent to your linked email.
<br>
Enter either email address or skynet username.
</p> </p>
<form id="recovery"> <form id="form">
<table id="table"> <table id="table">
<tr> <tr>
<td><label for="username">Username</label></td> <td><label for="username">Username</label></td>
@ -31,58 +33,12 @@
<td><input id="email" name="email" type="text"/> <br/></td> <td><input id="email" name="email" type="text"/> <br/></td>
</tr> </tr>
<tr> <tr>
<td colspan="2"><input type="submit" value="submit"/></td> <td colspan="2"><input id="button" type="submit" value="submit"/></td>
</tr> </tr>
</table> </table>
</form> </form>
<p id="formStatus"></p> <p id="formStatus"></p>
<script> <script type="module" src="password.js"></script>
const formEl = document.getElementById('recovery');
formEl.addEventListener('submit', formHandler);
async function formHandler(listener) {
listener.preventDefault();
// reset teh form status
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Please wait.</span>";
const formData = new FormData(formEl);
const username = formData.get('username').trim();
const email = formData.get('email').trim();
if (username.length === 0 && email.length === 0) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Please enter username or email</span>";
return;
}
let to_send = {
email: email
};
// assuming username is not empty it is the preferred method
if (username.length > 0) {
to_send = {user: username};
}
let url = "https://api.account.skynet.ie/ldap/recover/password";
try {
let req = await fetch(url, {
method: 'POST',
body: JSON.stringify(to_send),
mode: "cors"
});
if (req.status === 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success Please check emails</span>";
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
}
} catch (e) {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>Error: ${e}</span>`;
}
}
</script>
</main> </main>
<footer class="page-footer"> <footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span> UL Computer Society 2023-<span id="year">2023</span>

50
src/recovery/password.js Normal file
View file

@ -0,0 +1,50 @@
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
const form_status = document.getElementById("formStatus");
const button = document.getElementById("button");
button.addEventListener('submit', formHandler);
async function formHandler(listener) {
listener.preventDefault();
// reset teh form status
form_status.innerHTML = "<span style='background-color: green; color: white'>Please wait.</span>";
const formData = new FormData(form);
const username = formData.get('username').trim();
const email = formData.get('email').trim();
if (username.length === 0 && email.length === 0) {
form_status.innerHTML = "<span style='background-color: red; color: white'>Please enter username or email</span>";
return;
}
let to_send = {
email: email
};
// assuming username is not empty it is the preferred method
if (username.length > 0) {
to_send = {user: username};
}
let url = "https://api.account.skynet.ie/ldap/recover/password";
try {
let req = await fetch(url, {
method: 'POST',
body: JSON.stringify(to_send),
mode: "cors"
});
if (req.status === 200) {
form_status.innerHTML = "<span style='background-color: green; color: white'>Success Please check emails</span>";
} else {
form_status.innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
}
} catch (e) {
form_status.innerHTML = `<span style='background-color: red; color: white'>Error: ${e}</span>`;
}
}

View file

@ -17,7 +17,7 @@
<p> <p>
Enter a new password for your Skynet account below. Enter a new password for your Skynet account below.
</p> </p>
<form id="reset"> <form id="form">
<table id="table"> <table id="table">
<tr> <tr>
<td><label for="pass1">New Password</label> </td> <td><label for="pass1">New Password</label> </td>
@ -28,59 +28,12 @@
<td><input id="pass2" name="confirm" type="password"/> <br/> </td> <td><input id="pass2" name="confirm" type="password"/> <br/> </td>
</tr> </tr>
<tr> <tr>
<td colspan="2"><input type="submit"/> </td> <td colspan="2"><input id="button" type="submit"/> </td>
</tr> </tr>
</table> </table>
</form> </form>
<p id="formStatus"></p> <p id="formStatus"></p>
<script> <script type="module" src="password_reset.js"></script>
const formEl = document.getElementById("reset");
formEl.addEventListener('submit', (listener) => formHandler(listener));
const url = new URL(window.location.href);
const urlParam = new URLSearchParams(url.search);
const auth = urlParam.get("auth");
async function formHandler(listener) {
listener.preventDefault();
// reset
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Please wait.</span>";
const formData = new FormData(formEl);
const pass = formData.get("password");
const confirm = formData.get("confirm");
if (pass !== confirm) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Passwords don't match</span>";
return;
}
let url = "https://api.account.skynet.ie/ldap/recover/password/auth";
let req;
try {
req = await fetch(url, {
method: 'POST',
body: JSON.stringify({auth: auth, pass: pass}),
mode: "cors"
});
} catch (e) {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>${e}</span>`;
return;
}
if (req.status !== 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
return;
}
let data = req.json();
if (data.result === 'error') {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>${data.error}</span>`;
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
}
}
</script>
</main> </main>
<footer class="page-footer"> <footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span> UL Computer Society 2023-<span id="year">2023</span>

View file

@ -0,0 +1,37 @@
import {request} from "../js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
const form_status = document.getElementById("formStatus");
const button = document.getElementById("button");
button.addEventListener('submit', formHandler);
async function formHandler(listener) {
listener.preventDefault();
// reset
form_status.innerHTML = "<span style='background-color: green; color: white'>Please wait.</span>";
const formData = new FormData(form);
const pass = formData.get("password");
const confirm = formData.get("confirm");
if (pass !== confirm) {
form_status.innerHTML = "<span style='background-color: red; color: white'>Failure: Passwords don't match</span>";
return;
}
const urlParam = new URLSearchParams(new URL(window.location.href).search);
const auth = urlParam.get("auth");
if(!auth){
return;
}
let url = "https://api.account.skynet.ie/ldap/recover/password/auth";
let body = {auth: auth, pass: pass};
await request(url, body, form_status, 'POST');
}

View file

@ -15,7 +15,9 @@
<main class="page-body"> <main class="page-body">
<h1>SSH key recovery</h1> <h1>SSH key recovery</h1>
<p> <p>
Recover a legacy skynet account using your username and set a new email address to link to the account. Use this only if you do not remember the account password and the linked account email is lost or incorrect.<br> Enter skynet username & email you have used with UL Wolves. </br> Recover a legacy skynet account using your username and set a new email address to link to the account. Use this only if you do not remember the account password and the linked account email is lost or incorrect.
<br>
Enter skynet username & email you have used with UL Wolves.
</p> </p>
<form id="form"> <form id="form">
@ -29,51 +31,12 @@
<td><input id="mail" name="mail" type="email"/> <br/></td> <td><input id="mail" name="mail" type="email"/> <br/></td>
</tr> </tr>
<tr> <tr>
<td colspan="2"><input type="submit" value="submit"/></td> <td colspan="2"><input id="button" type="submit" value="submit"/></td>
</tr> </tr>
</table> </table>
</form> </form>
<p id="formStatus"></p> <p id="formStatus"></p>
<script> <script type="module" src="ssh-request.js"></script>
const formEl = document.getElementById("form");
formEl.addEventListener('submit', formHandler);
function formHandler(listener) {
listener.preventDefault();
const formData = new FormData(formEl);
const object = {user: formData.get('user'), email: formData.get('mail')};
fetch('https://api.account.skynet.ie/ldap/recover/ssh/request', {
method: 'POST',
body: JSON.stringify(object),
mode: "cors"
})
.then(status)
.then(json)
.catch(() => {
document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>";
});
}
function status(res) {
if (res.status === 200) {
return res.json();
} else if (res.status === 500) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
}
}
function json(temp) {
if (temp) {
if (temp.result === 'error') {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>${temp.error}</span>`;
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
}
}
}
</script>
</main> </main>
<footer class="page-footer"> <footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span> UL Computer Society 2023-<span id="year">2023</span>

View file

@ -0,0 +1,19 @@
import {request} from "../js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
const form_status = document.getElementById("formStatus");
const button = document.getElementById("button");
button.addEventListener('submit', formHandler);
async function formHandler(listener) {
listener.preventDefault();
const formData = new FormData(form);
const body = {user: formData.get('user'), email: formData.get('mail')};
let url = 'https://api.account.skynet.ie/ldap/recover/ssh/request';
await request(url, body, form_status, 'POST');
}

View file

@ -18,47 +18,20 @@
<p> <p>
Get a reminder email of your Skynet username. Get a reminder email of your Skynet username.
</p> </p>
<form id="reset"> <form id="form">
<table id="table"> <table id="table">
<tr> <tr>
<td><label for="email">Email Address</label></td> <td><label for="email">Email Address</label></td>
<td><input id="email" name="email" type="text"/> <br/></td> <td><input id="email" name="email" type="text"/> <br/></td>
</tr> </tr>
<tr> <tr>
<td colspan="2"><input type="Submit" value="Submit"/></td> <td colspan="2"><input id="button" type="Submit" value="Submit"/></td>
</tr> </tr>
</table> </table>
</form> </form>
<p id="formStatus"></p> <p id="formStatus"></p>
</div> </div>
<script> <script type="module" src="username.js"></script>
const formEl = document.getElementById("reset");
formEl.addEventListener('submit', (listener) => formHandler(listener));
function formHandler(listener) {
listener.preventDefault();
// reset
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Please wait.</span>";
const formData = new FormData(formEl);
const email = formData.get("email");
const object = {email: email};
fetch('https://api.account.skynet.ie/ldap/recover/username', {
method: 'POST',
body: JSON.stringify(object),
mode: "cors"
}).then(res => {
if (res.status === 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
} else if (res.status === 500) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
}
}).catch(() => document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>");
}
</script>
</main> </main>
<footer class="page-footer"> <footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span> UL Computer Society 2023-<span id="year">2023</span>

25
src/recovery/username.js Normal file
View file

@ -0,0 +1,25 @@
import {request} from "../js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
const form_status = document.getElementById("formStatus");
const button = document.getElementById("button");
button.addEventListener('submit', formHandler);
async function formHandler(listener) {
listener.preventDefault();
// reset
form_status.innerHTML = "<span style='background-color: green; color: white'>Please wait.</span>";
const formData = new FormData(form);
const email = formData.get("email");
const body = {email: email};
let url = 'https://api.account.skynet.ie/ldap/recover/username';
await request(url, body, form_status, 'POST');
}

View file

@ -3,13 +3,13 @@
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<title>Skynet Register</title> <title>Skynet Register</title>
<link href="./images/favicon/favicon-16x16.png" rel="icon" type="image/png"/> <link href="images/favicon/favicon-16x16.png" rel="icon" type="image/png"/>
<link href="./stylesheets/index.css" rel="stylesheet" type="text/css"/> <link href="stylesheets/index.css" rel="stylesheet" type="text/css"/>
</head> </head>
<body> <body>
<div class="wrapper"> <div class="wrapper">
<header class="page-header"> <header class="page-header">
<img alt="Sharky, our mascot" height="81.56" src="./images/sharky.svg" width="145"/> <img alt="Sharky, our mascot" height="81.56" src="images/sharky.svg" width="145"/>
<h1>Skynet Self Service</h1> <h1>Skynet Self Service</h1>
</header> </header>
<main class="page-body"> <main class="page-body">
@ -23,7 +23,7 @@
<br> <br>
It must be lowercase, start with a letter and contain only 0-9 a-z and _- It must be lowercase, start with a letter and contain only 0-9 a-z and _-
</p> </p>
<form id="register"> <form id="form">
<table id="table"> <table id="table">
<tr> <tr>
<td><label for="user">Username</label></td> <td><label for="user">Username</label></td>
@ -38,53 +38,12 @@
<td><input id="confirm" name="confirm" type="password"/></td> <td><input id="confirm" name="confirm" type="password"/></td>
</tr> </tr>
<tr> <tr>
<td colspan="2"><input type="Submit" value="Submit"/></td> <td colspan="2"><input id="button" type="Submit" value="Submit"/></td>
</tr> </tr>
</table> </table>
</form> </form>
<p id="formStatus"></p> <p id="formStatus"></p>
<script> <script type="module" src="register.js"></script>
const formEl = document.getElementById("register");
formEl.addEventListener('submit', (listener) => formHandler(listener));
function formHandler(listener) {
listener.preventDefault();
const formData = new FormData(formEl);
const pass = formData.get("pass");
if (pass === formData.get("confirm")) {
const url = new URL(window.location.href);
const urlParam = new URLSearchParams(url.search);
const auth = urlParam.get("auth");
const user = formData.get("user");
const object = {auth: auth, user: user, pass: pass};
fetch('https://api.account.skynet.ie/ldap/new/account', {
method: 'POST',
body: JSON.stringify(object),
mode: "cors"
}).then(res => {
if (res.status === 200) {
return res.json();
} else if (res.status === 500) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
}
})
.then((temp) => {
if (temp) {
if (temp.result === 'error') {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>${temp.error}</span>`;
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
}
}
})
.catch(() => document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>");
} else {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>Passwords don't match</span>`;
}
}
</script>
</main> </main>
<footer class="page-footer"> <footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span> UL Computer Society 2023-<span id="year">2023</span>

35
src/register.js Normal file
View file

@ -0,0 +1,35 @@
import {request} from "./js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
const form_status = document.getElementById("formStatus");
const button = document.getElementById("button");
button.addEventListener('submit', formHandler);
async function formHandler(listener) {
listener.preventDefault();
const formData = new FormData(form);
const pass = formData.get("pass");
if (pass !== formData.get("confirm")) {
form_status.innerHTML = `<span style='background-color: red; color: white'>Passwords don't match</span>`;
return;
}
const urlParam = new URLSearchParams(new URL(window.location.href).search);
const auth = urlParam.get("auth");
// if there is no auth value then return here
if(!auth){
return;
}
const user = formData.get("user");
const body = {auth: auth, user: user, pass: pass};
let url = 'https://api.account.skynet.ie/ldap/new/account';
await request(url, body, form_status, 'POST');
}

View file

@ -30,48 +30,23 @@
<body> <body>
<div class="wrapper"> <div class="wrapper">
<header class="page-header"> <header class="page-header">
<img alt="Sharky, our mascot" height="81.56" src="./images/sharky.svg" width="145"/> <img alt="Sharky, our mascot" height="81.56" src="images/sharky.svg" width="145"/>
<h1>Skynet Self Service</h1> <h1>Skynet Self Service</h1>
</header> </header>
<main class="page-body"> <main class="page-body">
<h2>Welcome to Skynet</h2> <h2>Welcome to Skynet</h2>
<p> <p>
If you previously had an account please <a href="./modify.html">set your email</a> to be the same as UL Wolves. If you previously had an account please <a href="modify.html">set your email</a> to be the same as UL Wolves.
<br/> <br/>
If you are a new user, please fill in the form below with the email that you use on ul wolves. If you are a new user, please fill in the form below with the email that you use on ul wolves.
</p> </p>
<form id="register"> <form id="form">
<label for="mail">Email address</label> <label for="mail">Email address</label>
<input id="mail" name="email" type="email"/> <br/> <input id="mail" name="email" type="email"/> <br/>
<input type="submit" value="Submit"/> <input id="button" type="submit" value="Submit"/>
</form> </form>
<p id="formStatus"></p> <p id="formStatus"></p>
<script> <script type="module" src="signup.js"></script>
const formEl = document.getElementById('register');
formEl.addEventListener('submit', (listener) => formHandler(listener));
function formHandler(listener) {
listener.preventDefault();
//HTML below taken from the W3 schools tutorial ()
document.getElementById('formStatus').innerHTML = "<div class='loader'></div>"
const formData = new FormData(formEl);
const email = formData.get("email");
const object = {email: email};
fetch('https://api.account.skynet.ie/ldap/new/email', {
method: 'POST',
body: JSON.stringify(object),
mode: "cors"
}).then(res => {
if (res.status === 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
} else if (res.status === 500) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
}
}).catch(() => document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>");
}
</script>
</main> </main>
<footer class="page-footer"> <footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span> UL Computer Society 2023-<span id="year">2023</span>

24
src/signup.js Normal file
View file

@ -0,0 +1,24 @@
import {request} from "./js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
const form_status = document.getElementById("formStatus");
const button = document.getElementById("button");
button.addEventListener('submit', formHandler);
async function formHandler(listener) {
listener.preventDefault();
//HTML below taken from the W3 schools tutorial ()
form_status.innerHTML = "<div class='loader'></div>"
const formData = new FormData(form);
const email = formData.get("email");
const body = {email: email};
let url = 'https://api.account.skynet.ie/ldap/new/email';
await request(url, body, form_status, 'POST');
}