From f5d46a38d768a010ce972fea20f58a92ed972143 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 4 Apr 2023 22:15:51 +0100 Subject: [PATCH] Added comments for further development Signed-off-by: Fred Boniface --- src/services/auth.services.js | 9 +++++---- src/services/dbAccess.services.js | 6 +++--- src/utils/auth.utils.js | 4 ++-- src/utils/sanitizer.utils.js | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/services/auth.services.js b/src/services/auth.services.js index e4a4248..6b7c3d6 100644 --- a/src/services/auth.services.js +++ b/src/services/auth.services.js @@ -1,4 +1,4 @@ -const log = require('../utils/log.utils') +const log = require('../utils/log.utils') // Currently no logging on this page const util = require('../utils/auth.utils') const db = require('../services/dbAccess.services') const mail = require('../services/mail.services') @@ -6,19 +6,20 @@ const clean = require('../utils/sanitizer.utils') const domList= require('../configs/domains.configs') async function createRegKey(eml){ - const domain = clean.splitDomain(eml) // Obtain mail domain as that is all that needs storing + const domain = clean.splitDomain(eml) if (domain in domList.valid) { const uuid = util.generateKey(); db.addRegReq(await uuid, await domain) mail.sendRegister("mail", "uuid"); - return 201 + return 201 // These returns still need handling } else { - return 401 + return 401 // As above } } async function regUser(req) { if (util.checkRequest(req.key) == true) { + // Run DB Query to get the email domain to store alongside the api_key apiKey = await db.addUser(await util.generateKey()) return {status: 201, message: "User added", api_key: apiKey} } else { diff --git a/src/services/dbAccess.services.js b/src/services/dbAccess.services.js index a7ee618..8006551 100644 --- a/src/services/dbAccess.services.js +++ b/src/services/dbAccess.services.js @@ -33,7 +33,7 @@ async function increment(target) { return; } -async function addUser(uuid, domain) { +async function addUser(uuid, domain) { // Needs testing log.out(`dbAccess.addUser: Adding user to database`) let doc = {uuid: uuid, domain: domain, atime: new Date} await client.connect(); @@ -42,7 +42,7 @@ async function addUser(uuid, domain) { return res; } -async function addRegReq(uuid) { +async function addRegReq(uuid) { // Needs testing log.out(`dbAccess.addRegReq: Adding registration request`) let doc = {uuid: uuid, time: new Date} await client.connect(); @@ -51,7 +51,7 @@ async function addRegReq(uuid) { return res; } -async function userAtime(uuid) { +async function userAtime(uuid) { // Needs testing log.out(`dbAccess.userAtime: Updating access time for user`) let q = {uuid: uuid}; let n = {$set: {uuid: uuid, atime: new Date}}; diff --git a/src/utils/auth.utils.js b/src/utils/auth.utils.js index 98d84fa..fdaf571 100644 --- a/src/utils/auth.utils.js +++ b/src/utils/auth.utils.js @@ -3,7 +3,7 @@ const crypto = require('crypto') const db = require('../services/dbAccess.services') // Checks users registration key against issued keys -async function checkUser(key) { +async function checkUser(key) { // Needs testing q = {uuid: key}; res = db.query("registrations", q); log.out(`authUtils.checkUser: DB Query answer: ${await res}`) @@ -11,7 +11,7 @@ async function checkUser(key) { } // Creates an API key for a user -async function generateKey() { +async function generateKey() { // Needs testing return crypto.randomUUID() }; diff --git a/src/utils/sanitizer.utils.js b/src/utils/sanitizer.utils.js index 3c3db19..c1fdbaa 100644 --- a/src/utils/sanitizer.utils.js +++ b/src/utils/sanitizer.utils.js @@ -38,7 +38,7 @@ function cleanNrcc(input) { return rmPara; } -async function splitDomain(mail) { +async function splitDomain(mail) { // Needs testing split = mail.split("@") return split[1] }