pis #12

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

View File

@ -29,9 +29,10 @@ async function createRegKey(body){
}
async function regUser(req) {
if (util.checkRequest(req.key) == true) {
let res = auth.checkRequest(req.key)
if (res.status) {
// Run DB Query to get the email domain to store alongside the api_key
apiKey = await db.addUser(await util.generateKey())
apiKey = await db.addUser(await util.generateKey(), res.domain)
return {status: 201, message: "User added", api_key: apiKey}
} else {
return {status: 401, message: "Unautorised"}

View File

@ -4,15 +4,28 @@ const db = require('../services/dbAccess.services');
const fs = require('fs/promises')
// Checks users registration key against issued keys
async function isAuthed(key) { // Needs testing
return false;
q = {uuid: key};
res = db.query("registrations", q);
async function isAuthed(uuid) { // Needs testing
q = {uuid: uuid};
res = db.query("users", q);
log.out(`authUtils.checkUser: DB Query answer: ${await res}`)
// Do something here to determine if authorised or not and simply return a BOOL
return
if (res[0].domain) {
db.userAtime(uuid)
return true
}
return false
}
// Checks whether a registration request key is valid
async function checkRequest(key) {
let collection = "registrations"
let query = {uuid: key}
const res = await db.query(collection, query)
log.out(`authUtils.checkRequest: DB Query result: ${res}`, "info")
if (res[0].time) {
return {result: true, domain: res[0].date}
}
return {result: false}
}
// Creates an API key for a user
@ -39,5 +52,6 @@ async function generateConfirmationEmail(eml, uuid) {
module.exports = {
isAuthed,
generateKey,
generateConfirmationEmail
generateConfirmationEmail,
checkRequest
}