beautified

This commit is contained in:
xfarrow 2024-03-04 16:49:36 +01:00
parent 3ea41c82d4
commit d9c3f6f55a
18 changed files with 427 additions and 300 deletions

View File

@ -38,7 +38,9 @@ app.use(cors()); // Enable CORS for all routes
app.use(rateLimit({ app.use(rateLimit({
windowMs: process.env.LIMITER_WINDOW, windowMs: process.env.LIMITER_WINDOW,
max: process.env.LIMITER_MAXIMUM_PER_WINDOW, max: process.env.LIMITER_MAXIMUM_PER_WINDOW,
message: { error: 'Too many requests from this IP, please try again later' } message: {
error: 'Too many requests from this IP, please try again later'
}
})); // Apply the rate limiter middleware to all routes })); // Apply the rate limiter middleware to all routes
/* /*

View File

@ -71,7 +71,9 @@ async function removeOrganizationAdmin (personId, organizationId) {
// TODO: If the user instead deletes their entire profile, the organization will not be deleted. Fix. (database schema) // TODO: If the user instead deletes their entire profile, the organization will not be deleted. Fix. (database schema)
const remainingAdministrators = await transaction('OrganizationAdministrator') const remainingAdministrators = await transaction('OrganizationAdministrator')
.where({ id_organization: organizationId }); .where({
id_organization: organizationId
});
if (remainingAdministrators.length === 0) { if (remainingAdministrators.length === 0) {
// If no more users, delete the organization // If no more users, delete the organization

View File

@ -98,7 +98,9 @@ async function updateOrganization (organization, organizationId, requester) {
*/ */
async function deleteOrganization(organizationId, requester) { async function deleteOrganization(organizationId, requester) {
const numberOfDeletedRows = await knex('Organization') const numberOfDeletedRows = await knex('Organization')
.where({ id: organizationId }) .where({
id: organizationId
})
.whereExists(function () { .whereExists(function () {
this.select('*') this.select('*')
.from('OrganizationAdministrator') .from('OrganizationAdministrator')

View File

@ -59,7 +59,9 @@ async function getPersonByEmail (email) {
async function getPersonById(id) { async function getPersonById(id) {
return await knex('Person') return await knex('Person')
.select('*') .select('*')
.where({ id }) .where({
id
})
.first(); .first();
} }
@ -124,7 +126,9 @@ async function updatePerson (person, person_id) {
*/ */
async function deletePerson(personId) { async function deletePerson(personId) {
await knex('Person') await knex('Person')
.where({ id: personId }) .where({
id: personId
})
.del(); .del();
} }
@ -132,7 +136,9 @@ async function confirmActivation (personId) {
await knex.transaction(async (tr) => { await knex.transaction(async (tr) => {
await knex('Person') await knex('Person')
.where('id', personId) .where('id', personId)
.update({enabled: true}); .update({
enabled: true
});
await tr('ActivationLink') await tr('ActivationLink')
.where('person_id', personId) .where('person_id', personId)

View File

@ -26,18 +26,26 @@ const jwtUtils = require('../utils/middleware_utils');
async function addOrganizationAdmin(req, res) { async function addOrganizationAdmin(req, res) {
// Ensure that the required fields are present before proceeding // Ensure that the required fields are present before proceeding
if (!req.body.organization_id || !req.body.person_id) { if (!req.body.organization_id || !req.body.person_id) {
return res.status(400).json({ error: 'Invalid request' }); return res.status(400).json({
error: 'Invalid request'
});
} }
try { try {
const success = await organizationAdminModel.addOrganizationAdministrator(req.body.person_id, req.body.organization_id, req.jwt.person_id); const success = await organizationAdminModel.addOrganizationAdministrator(req.body.person_id, req.body.organization_id, req.jwt.person_id);
if (success) { if (success) {
return res.status(200).json({ success: true }); return res.status(200).json({
success: true
});
} }
return res.status(403).json({ error: 'Forbidden' }); return res.status(403).json({
error: 'Forbidden'
});
} catch (error) { } catch (error) {
console.error(`Error in function ${addOrganizationAdmin.name}: ${error}`); console.error(`Error in function ${addOrganizationAdmin.name}: ${error}`);
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({
error: 'Internal server error'
});
} }
} }
@ -53,15 +61,21 @@ async function addOrganizationAdmin (req, res) {
async function removeOrganizationAdmin(req, res) { async function removeOrganizationAdmin(req, res) {
// Ensure that the required fields are present before proceeding // Ensure that the required fields are present before proceeding
if (!req.body.organization_id) { if (!req.body.organization_id) {
return res.status(400).json({ error: 'Invalid request' }); return res.status(400).json({
error: 'Invalid request'
});
} }
try { try {
await organizationAdminModel.removeOrganizationAdmin(req.jwt.person_id, req.body.organization_id); await organizationAdminModel.removeOrganizationAdmin(req.jwt.person_id, req.body.organization_id);
return res.status(200).json({ success: true }); return res.status(200).json({
success: true
});
} catch (error) { } catch (error) {
console.error(`Error in function ${removeOrganizationAdmin.name}: ${error}`); console.error(`Error in function ${removeOrganizationAdmin.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' }); return res.status(500).json({
error: 'Internal server error'
});
} }
} }

View File

@ -26,7 +26,9 @@ const jwtUtils = require('../utils/middleware_utils');
async function createOrganizationPost(req, res) { async function createOrganizationPost(req, res) {
// Ensure that the required fields are present before proceeding // Ensure that the required fields are present before proceeding
if (!req.body.organization_id || !req.body.content) { if (!req.body.organization_id || !req.body.content) {
return res.status(400).json({ error: 'Invalid request' }); return res.status(400).json({
error: 'Invalid request'
});
} }
const organization = organizationPostModel.createOrganizationPost( const organization = organizationPostModel.createOrganizationPost(
@ -39,7 +41,9 @@ async function createOrganizationPost (req, res) {
return res.status(200).json(insertedOrganization); return res.status(200).json(insertedOrganization);
} catch (error) { } catch (error) {
console.error(`Error in function ${createOrganizationPost.name}: ${error}`); console.error(`Error in function ${createOrganizationPost.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' }); return res.status(500).json({
error: 'Internal server error'
});
} }
} }
@ -56,13 +60,19 @@ async function deleteOrganizationPost (req, res) {
const success = await organizationPostModel.deleteOrganizationPost(req.params.id, req.jwt.person_id); const success = await organizationPostModel.deleteOrganizationPost(req.params.id, req.jwt.person_id);
if (success) { if (success) {
return res.status(200).json({ success: true }); return res.status(200).json({
success: true
});
} }
return res.status(401).json({ error: 'Forbidden' }); return res.status(401).json({
error: 'Forbidden'
});
} catch (error) { } catch (error) {
console.error(`Error in function ${deleteOrganizationPost.name}: ${error}`); console.error(`Error in function ${deleteOrganizationPost.name}: ${error}`);
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({
error: 'Internal server error'
});
} }
} }

View File

@ -27,7 +27,9 @@ const jwtUtils = require('../utils/middleware_utils');
async function createOrganization(req, res) { async function createOrganization(req, res) {
// Ensure that the required fields are present before proceeding // Ensure that the required fields are present before proceeding
if (!req.body.name) { if (!req.body.name) {
return res.status(400).json({ error: 'Invalid request' }); return res.status(400).json({
error: 'Invalid request'
});
} }
try { try {
@ -36,7 +38,9 @@ async function createOrganization (req, res) {
return res.status(200).json(insertedOrganization); return res.status(200).json(insertedOrganization);
} catch (error) { } catch (error) {
console.error(`Error in function ${createOrganization.name}: ${error}`); console.error(`Error in function ${createOrganization.name}: ${error}`);
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({
error: 'Internal server error'
});
} }
} }
@ -66,19 +70,27 @@ async function updateOrganization (req, res) {
} }
if (Object.keys(updateOrganization).length === 0) { if (Object.keys(updateOrganization).length === 0) {
return res.status(400).json({ error: 'Bad request. No data to update' }); return res.status(400).json({
error: 'Bad request. No data to update'
});
} }
try { try {
const isUpdateSuccessful = organizationModel.updateOrganization(updateOrganization, req.params.id, req.jwt.person_id); const isUpdateSuccessful = organizationModel.updateOrganization(updateOrganization, req.params.id, req.jwt.person_id);
if (isUpdateSuccessful) { if (isUpdateSuccessful) {
return res.status(200).json({ success: 'true' }); return res.status(200).json({
success: 'true'
});
} else { } else {
return res.status(404).json({ error: 'Organization either not found or insufficient permissions' }); return res.status(404).json({
error: 'Organization either not found or insufficient permissions'
});
} }
} catch (error) { } catch (error) {
console.error(`Error in function ${updateOrganization.name}: ${error}`); console.error(`Error in function ${updateOrganization.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' }); return res.status(500).json({
error: 'Internal server error'
});
} }
} }
@ -92,12 +104,18 @@ async function deleteOrganization (req, res) {
try { try {
const isDeleteSuccessful = await organizationModel.deleteOrganization(req.params.id, req.jwt.person_id); const isDeleteSuccessful = await organizationModel.deleteOrganization(req.params.id, req.jwt.person_id);
if (isDeleteSuccessful) { if (isDeleteSuccessful) {
return res.status(200).json({ success: true }); return res.status(200).json({
success: true
});
} }
return res.status(403).json({ error: 'Forbidden' }); return res.status(403).json({
error: 'Forbidden'
});
} catch (error) { } catch (error) {
console.error(`Error in function ${deleteOrganization.name}: ${error}`); console.error(`Error in function ${deleteOrganization.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' }); return res.status(500).json({
error: 'Internal server error'
});
} }
} }
@ -116,11 +134,15 @@ async function getOrganization (req, res) {
if (organization) { if (organization) {
return res.status(200).json(organization); return res.status(200).json(organization);
} else { } else {
return res.status(404).json({ error: 'Not found' }); return res.status(404).json({
error: 'Not found'
});
} }
} catch (error) { } catch (error) {
console.error(`Error in function ${getOrganization.name}: ${error}`); console.error(`Error in function ${getOrganization.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' }); return res.status(500).json({
error: 'Internal server error'
});
} }
} }

View File

@ -31,14 +31,20 @@ const express = require('express');
async function registerPerson(req, res) { async function registerPerson(req, res) {
// Does this server allow users to register? // Does this server allow users to register?
if (process.env.ALLOW_USER_REGISTRATION === 'false') { if (process.env.ALLOW_USER_REGISTRATION === 'false') {
return res.status(403).json({ error: 'Users cannot register on this server' }); return res.status(403).json({
error: 'Users cannot register on this server'
});
} }
// Ensure that the required fields are present before proceeding // Ensure that the required fields are present before proceeding
if (!req.body.display_name || !req.body.email || !req.body.password) { if (!req.body.display_name || !req.body.email || !req.body.password) {
return res.status(400).json({ error: 'Some or all required fields are missing' }); return res.status(400).json({
error: 'Some or all required fields are missing'
});
} }
if (!validator.validateEmail(req.body.email)) { if (!validator.validateEmail(req.body.email)) {
return res.status(400).json({ error: 'The email is not in a valid format' }); return res.status(400).json({
error: 'The email is not in a valid format'
});
} }
// Generate activation link token // Generate activation link token
@ -50,7 +56,9 @@ async function registerPerson (req, res) {
// Check whether e-mail exists already (enforced by database constraints) // Check whether e-mail exists already (enforced by database constraints)
const existingUser = await personModel.getPersonByEmail(req.body.email); const existingUser = await personModel.getPersonByEmail(req.body.email);
if (existingUser) { if (existingUser) {
return res.status(409).json({ error: 'E-mail already in use' }); return res.status(409).json({
error: 'E-mail already in use'
});
} }
const personToInsert = personModel.createPerson( const personToInsert = personModel.createPerson(
req.body.email, req.body.email,
@ -63,10 +71,14 @@ async function registerPerson (req, res) {
req.body.about_me, req.body.about_me,
req.body.qualification); req.body.qualification);
await personModel.registerPerson(personToInsert, activationLink); await personModel.registerPerson(personToInsert, activationLink);
return res.status(200).json({ activationLink }); return res.status(200).json({
activationLink
});
} catch (error) { } catch (error) {
console.error(`Error in function ${registerPerson.name}: ${error}`); console.error(`Error in function ${registerPerson.name}: ${error}`);
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({
error: 'Internal server error'
});
} }
} }
@ -83,20 +95,28 @@ async function registerPerson (req, res) {
async function login(req, res) { async function login(req, res) {
// Ensure that the required fields are present before proceeding // Ensure that the required fields are present before proceeding
if (!req.body.email || !req.body.password) { if (!req.body.email || !req.body.password) {
return res.status(400).json({ error: 'Invalid request' }); return res.status(400).json({
error: 'Invalid request'
});
} }
try { try {
const person = await personModel.getPersonByEmailAndPassword(req.body.email, req.body.password); const person = await personModel.getPersonByEmailAndPassword(req.body.email, req.body.password);
if (person) { if (person) {
const token = jwtUtils.generateToken(person.id); const token = jwtUtils.generateToken(person.id);
return res.status(200).json({ token }); return res.status(200).json({
token
});
} else { } else {
return res.status(401).json({ error: 'Invalid credentials' }); return res.status(401).json({
error: 'Invalid credentials'
});
} }
} catch (error) { } catch (error) {
console.error(`Error in function ${login.name}: ${error}`); console.error(`Error in function ${login.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' }); return res.status(500).json({
error: 'Internal server error'
});
} }
} }
@ -116,10 +136,14 @@ async function getPerson (req, res) {
delete person.password; // remove password field for security reasons delete person.password; // remove password field for security reasons
return res.status(200).send(person); return res.status(200).send(person);
} }
return res.status(404).json({ error: 'Not found' }); return res.status(404).json({
error: 'Not found'
});
} catch (error) { } catch (error) {
console.error(`Error in function ${getPerson.name}: ${error}`); console.error(`Error in function ${getPerson.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' }); return res.status(500).json({
error: 'Internal server error'
});
} }
} }
@ -138,10 +162,14 @@ async function getMyself (req, res) {
delete person.password; delete person.password;
return res.status(200).send(person); return res.status(200).send(person);
} }
return res.status(404).json({ error: 'Not found' }); return res.status(404).json({
error: 'Not found'
});
} catch (error) { } catch (error) {
console.error(`Error in function ${getMyself.name}: ${error}`); console.error(`Error in function ${getMyself.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' }); return res.status(500).json({
error: 'Internal server error'
});
} }
} }
@ -167,7 +195,9 @@ async function updatePerson (req, res) {
if (validator.isPostgresDateFormatValid(req.body.date_of_birth)) { if (validator.isPostgresDateFormatValid(req.body.date_of_birth)) {
updatePerson.date_of_birth = req.body.date_of_birth; updatePerson.date_of_birth = req.body.date_of_birth;
} else { } else {
return res.status(400).json({ error: 'Date of birth format not valid. Please specify a YYYY-MM-DD date' }); return res.status(400).json({
error: 'Date of birth format not valid. Please specify a YYYY-MM-DD date'
});
} }
} }
@ -190,30 +220,42 @@ async function updatePerson (req, res) {
// If we are tying to change password, the old password must be provided // If we are tying to change password, the old password must be provided
if (req.body.old_password || req.body.new_password) { if (req.body.old_password || req.body.new_password) {
if (!req.body.old_password) { if (!req.body.old_password) {
return res.status(401).json({ error: 'The old password must be specified' }); return res.status(401).json({
error: 'The old password must be specified'
});
} }
if (!req.body.new_password) { if (!req.body.new_password) {
return res.status(401).json({ error: 'The new password must be specified' }); return res.status(401).json({
error: 'The new password must be specified'
});
} }
const user = await personModel.getPersonById(req.jwt.person_id); const user = await personModel.getPersonById(req.jwt.person_id);
const passwordMatches = await bcrypt.compare(req.body.old_password, user.password); const passwordMatches = await bcrypt.compare(req.body.old_password, user.password);
if (passwordMatches) { if (passwordMatches) {
updatePerson.password = await bcrypt.hash(req.body.new_password, 10); updatePerson.password = await bcrypt.hash(req.body.new_password, 10);
} else { } else {
return res.status(401).json({ error: 'Password verification failed' }); return res.status(401).json({
error: 'Password verification failed'
});
} }
} }
if (Object.keys(updatePerson).length === 0) { if (Object.keys(updatePerson).length === 0) {
return res.status(400).json({ error: 'Bad request. No data to update' }); return res.status(400).json({
error: 'Bad request. No data to update'
});
} }
try { try {
await personModel.updatePerson(updatePerson, req.jwt.person_id); await personModel.updatePerson(updatePerson, req.jwt.person_id);
return res.status(200).json({ success: 'true' }); return res.status(200).json({
success: 'true'
});
} catch (error) { } catch (error) {
console.error(`Error in function ${updatePerson.name}: ${error}`); console.error(`Error in function ${updatePerson.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' }); return res.status(500).json({
error: 'Internal server error'
});
} }
} }
@ -230,10 +272,14 @@ async function deletePerson (req, res) {
// TODO: Delete Organization if this user was its only administrator // TODO: Delete Organization if this user was its only administrator
try { try {
await personModel.deletePerson(req.jwt.person_id); await personModel.deletePerson(req.jwt.person_id);
return res.status(200).json({ success: true }); return res.status(200).json({
success: true
});
} catch (error) { } catch (error) {
console.error(`Error in function ${deletePerson.name}: ${error}`); console.error(`Error in function ${deletePerson.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' }); return res.status(500).json({
error: 'Internal server error'
});
} }
} }
@ -249,13 +295,19 @@ async function confirmActivation(req, res){
try { try {
const personId = await activationModel.getPersonIdByIdentifier(req.query.q); const personId = await activationModel.getPersonIdByIdentifier(req.query.q);
if (!personId) { if (!personId) {
return res.status(401).json({error: 'Activation Link either not valid or expired'}); return res.status(401).json({
error: 'Activation Link either not valid or expired'
});
} }
await personModel.confirmActivation(personId); await personModel.confirmActivation(personId);
return res.status(200).json({ success: true }); return res.status(200).json({
success: true
});
} catch (error) { } catch (error) {
console.error(`Error in function ${confirmActivation.name}: ${error}`); console.error(`Error in function ${confirmActivation.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' }); return res.status(500).json({
error: 'Internal server error'
});
} }
} }

View File

@ -30,12 +30,16 @@ function verifyToken (req, res, next) {
const token = req.headers.authorization; const token = req.headers.authorization;
if (!token) { if (!token) {
return res.status(401).send({ error: 'No token provided' }); return res.status(401).send({
error: 'No token provided'
});
} }
jwt.verify(token, process.env.JWT_SECRET_KEY, (err, decoded) => { jwt.verify(token, process.env.JWT_SECRET_KEY, (err, decoded) => {
if (err) { if (err) {
return res.status(401).send({ error: 'Failed to authenticate token' }); return res.status(401).send({
error: 'Failed to authenticate token'
});
} }
// If the token is valid, store the decoded data in the request object // If the token is valid, store the decoded data in the request object

View File

@ -1,10 +1,12 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Log in - Blink</title> <title>Log in - Blink</title>
<link rel="stylesheet" href="../css/login-register.css"> <link rel="stylesheet" href="../css/login-register.css">
</head> </head>
<body> <body>
<!-- partial:index.partial.html --> <!-- partial:index.partial.html -->
<div id="login-form-wrap"> <div id="login-form-wrap">
@ -12,11 +14,13 @@
<form id="login-form" method="POST"> <form id="login-form" method="POST">
<p> <p>
<input type="email" id="email" name="email" placeholder="Email Address" required><i class="validation"><span></span><span></span></i> <input type="email" id="email" name="email" placeholder="Email Address" required><i
class="validation"><span></span><span></span></i>
</p> </p>
<p> <p>
<input type="password" id="password" name="password" placeholder="Password" required><i class="validation"><span></span><span></span></i> <input type="password" id="password" name="password" placeholder="Password" required><i
class="validation"><span></span><span></span></i>
</p> </p>
<p> <p>
@ -24,7 +28,8 @@
</p> </p>
</form> </form>
<div id="create-account-wrap"> <div id="create-account-wrap">
<p>Not a member? <a href="./register.html">Create Account</a><p> <p>Not a member? <a href="./register.html">Create Account</a>
<p>
</div> </div>
</div> </div>
@ -42,7 +47,8 @@
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
email: email, email: email,
password: password }), password: password
}),
headers: { headers: {
"Content-type": "application/json; charset=UTF-8" "Content-type": "application/json; charset=UTF-8"
} }
@ -54,12 +60,12 @@
console.log(`Login was successful. Token is ${data.token}`); console.log(`Login was successful. Token is ${data.token}`);
document.cookie = `token=${data.token};`; document.cookie = `token=${data.token};`;
window.location.href = 'userprofile.html?id=myself'; window.location.href = 'userprofile.html?id=myself';
} } else {
else{
alert(data.error); alert(data.error);
} }
} }
</script> </script>
</body> </body>
</html> </html>

View File

@ -1,11 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Title</title> <title>Title</title>
<link rel="stylesheet" href="../css/organization.css"> <link rel="stylesheet" href="../css/organization.css">
</head> </head>
<body style="display: none;"> <body style="display: none;">
<div class="container"> <div class="container">
<div class="hiring-badge" style="display: none;" id="isHiringBadge">Now Hiring</div> <div class="hiring-badge" style="display: none;" id="isHiringBadge">Now Hiring</div>
@ -45,8 +47,7 @@
if (response.ok) { if (response.ok) {
populateFields(data.name, data.location, data.description, data.is_hiring); populateFields(data.name, data.location, data.description, data.is_hiring);
document.body.style.display = "block"; // Show page document.body.style.display = "block"; // Show page
} } else {
else {
alert(data.error); alert(data.error);
} }
} }
@ -59,17 +60,15 @@
if (isHiring === true) { if (isHiring === true) {
document.getElementById('isHiring').textContent = 'Yes'; document.getElementById('isHiring').textContent = 'Yes';
document.getElementById('isHiringBadge').style.display = 'block'; document.getElementById('isHiringBadge').style.display = 'block';
} } else if (isHiring === false) {
else if (isHiring === false) {
document.getElementById('isHiring').textContent = 'No'; document.getElementById('isHiring').textContent = 'No';
} } else {
else {
document.getElementById('isHiring').textContent = 'Not specified'; document.getElementById('isHiring').textContent = 'Not specified';
} }
} }
</script> </script>
</body> </body>
</html> </html>

View File

@ -1,11 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Sign Up to Blink</title> <title>Sign Up to Blink</title>
<link rel="stylesheet" href="../css/login-register.css"> <link rel="stylesheet" href="../css/login-register.css">
<script src=""></script> <script src=""></script>
</head> </head>
<body> <body>
<!-- partial:index.partial.html --> <!-- partial:index.partial.html -->
<div id="login-form-wrap"> <div id="login-form-wrap">
@ -13,15 +15,18 @@
<form id="login-form"> <form id="login-form">
<p> <p>
<input type="text" id="displayname" name="displayname" placeholder="Your name" required><i class="validation"><span></span><span></span></i> <input type="text" id="displayname" name="displayname" placeholder="Your name" required><i
class="validation"><span></span><span></span></i>
</p> </p>
<p> <p>
<input type="email" id="email" name="email" placeholder="Email Address" required><i class="validation"><span></span><span></span></i> <input type="email" id="email" name="email" placeholder="Email Address" required><i
class="validation"><span></span><span></span></i>
</p> </p>
<p> <p>
<input type="password" id="password" name="password" placeholder="Password" required><i class="validation"><span></span><span></span></i> <input type="password" id="password" name="password" placeholder="Password" required><i
class="validation"><span></span><span></span></i>
</p> </p>
<p> <p>
@ -29,7 +34,8 @@
</p> </p>
</form> </form>
<div id="create-account-wrap"> <div id="create-account-wrap">
<p>Already a member? <a href="./login.html">Login</a><p> <p>Already a member? <a href="./login.html">Login</a>
<p>
</div> </div>
</div> </div>
@ -37,7 +43,6 @@
<script src="../js/utils.js"></script> <script src="../js/utils.js"></script>
<script> <script>
function register() { function register() {
const display_name = document.getElementById('displayname').value; const display_name = document.getElementById('displayname').value;
const email = document.getElementById('email').value; const email = document.getElementById('email').value;
@ -53,7 +58,11 @@
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ display_name, email, password }), body: JSON.stringify({
display_name,
email,
password
}),
}; };
fetch(`${API_URL}/register`, options) fetch(`${API_URL}/register`, options)
@ -73,4 +82,5 @@
</script> </script>
</body> </body>
</html> </html>

View File

@ -1,11 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Page Title</title> <title>Page Title</title>
<link rel="stylesheet" href="../css/profile.css"> <link rel="stylesheet" href="../css/profile.css">
</head> </head>
<body style="display: none;"> <body style="display: none;">
<div class="container"> <div class="container">
<div class="edit-badge" style="display: none;" id="editBadge" onclick="editProfile()">Edit</div> <div class="edit-badge" style="display: none;" id="editBadge" onclick="editProfile()">Edit</div>
@ -69,8 +71,7 @@
"authorization": token "authorization": token
} }
}); });
} } else {
else {
response = await fetch(`${API_URL}/person/${idToDisplay}/details`, { response = await fetch(`${API_URL}/person/${idToDisplay}/details`, {
headers: { headers: {
"Content-type": "application/json; charset=UTF-8", "Content-type": "application/json; charset=UTF-8",
@ -82,11 +83,9 @@
if (response.ok) { if (response.ok) {
populateFields(data.display_name, data.email, data.about_me, data.qualification); populateFields(data.display_name, data.email, data.about_me, data.qualification);
document.body.style.display = 'block'; // Show page document.body.style.display = 'block'; // Show page
} } else if (response.status == 401) {
else if (response.status == 401){
window.location.href = 'login.html'; window.location.href = 'login.html';
} } else {
else{
alert(`Unable to load profile. Error: ${data.error}`); alert(`Unable to load profile. Error: ${data.error}`);
} }
} }
@ -102,9 +101,8 @@
function editProfile() { function editProfile() {
alert('Editing'); alert('Editing');
} }
</script> </script>
</body> </body>
</html>
</html>