pis #12
@ -29,9 +29,10 @@ async function createRegKey(body){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function regUser(req) {
|
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
|
// 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}
|
return {status: 201, message: "User added", api_key: apiKey}
|
||||||
} else {
|
} else {
|
||||||
return {status: 401, message: "Unautorised"}
|
return {status: 401, message: "Unautorised"}
|
||||||
|
@ -4,15 +4,28 @@ const db = require('../services/dbAccess.services');
|
|||||||
const fs = require('fs/promises')
|
const fs = require('fs/promises')
|
||||||
|
|
||||||
// Checks users registration key against issued keys
|
// Checks users registration key against issued keys
|
||||||
async function isAuthed(key) { // Needs testing
|
async function isAuthed(uuid) { // Needs testing
|
||||||
return false;
|
q = {uuid: uuid};
|
||||||
q = {uuid: key};
|
res = db.query("users", q);
|
||||||
res = db.query("registrations", q);
|
|
||||||
log.out(`authUtils.checkUser: DB Query answer: ${await res}`)
|
log.out(`authUtils.checkUser: DB Query answer: ${await res}`)
|
||||||
|
|
||||||
// Do something here to determine if authorised or not and simply return a BOOL
|
// Do something here to determine if authorised or not and simply return a BOOL
|
||||||
|
if (res[0].domain) {
|
||||||
|
db.userAtime(uuid)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return
|
// 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
|
// Creates an API key for a user
|
||||||
@ -39,5 +52,6 @@ async function generateConfirmationEmail(eml, uuid) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
isAuthed,
|
isAuthed,
|
||||||
generateKey,
|
generateKey,
|
||||||
generateConfirmationEmail
|
generateConfirmationEmail,
|
||||||
|
checkRequest
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user