pis #12

Merged
fred.boniface merged 95 commits from pis into main 2023-05-06 21:54:51 +01:00
4 changed files with 11 additions and 10 deletions
Showing only changes of commit f5d46a38d7 - Show all commits

View File

@ -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 {

View File

@ -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}};

View File

@ -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()
};

View File

@ -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]
}