pis #12
@ -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 util = require('../utils/auth.utils')
|
||||||
const db = require('../services/dbAccess.services')
|
const db = require('../services/dbAccess.services')
|
||||||
const mail = require('../services/mail.services')
|
const mail = require('../services/mail.services')
|
||||||
@ -6,19 +6,20 @@ const clean = require('../utils/sanitizer.utils')
|
|||||||
const domList= require('../configs/domains.configs')
|
const domList= require('../configs/domains.configs')
|
||||||
|
|
||||||
async function createRegKey(eml){
|
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) {
|
if (domain in domList.valid) {
|
||||||
const uuid = util.generateKey();
|
const uuid = util.generateKey();
|
||||||
db.addRegReq(await uuid, await domain)
|
db.addRegReq(await uuid, await domain)
|
||||||
mail.sendRegister("mail", "uuid");
|
mail.sendRegister("mail", "uuid");
|
||||||
return 201
|
return 201 // These returns still need handling
|
||||||
} else {
|
} else {
|
||||||
return 401
|
return 401 // As above
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function regUser(req) {
|
async function regUser(req) {
|
||||||
if (util.checkRequest(req.key) == true) {
|
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())
|
apiKey = await db.addUser(await util.generateKey())
|
||||||
return {status: 201, message: "User added", api_key: apiKey}
|
return {status: 201, message: "User added", api_key: apiKey}
|
||||||
} else {
|
} else {
|
||||||
|
@ -33,7 +33,7 @@ async function increment(target) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addUser(uuid, domain) {
|
async function addUser(uuid, domain) { // Needs testing
|
||||||
log.out(`dbAccess.addUser: Adding user to database`)
|
log.out(`dbAccess.addUser: Adding user to database`)
|
||||||
let doc = {uuid: uuid, domain: domain, atime: new Date}
|
let doc = {uuid: uuid, domain: domain, atime: new Date}
|
||||||
await client.connect();
|
await client.connect();
|
||||||
@ -42,7 +42,7 @@ async function addUser(uuid, domain) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addRegReq(uuid) {
|
async function addRegReq(uuid) { // Needs testing
|
||||||
log.out(`dbAccess.addRegReq: Adding registration request`)
|
log.out(`dbAccess.addRegReq: Adding registration request`)
|
||||||
let doc = {uuid: uuid, time: new Date}
|
let doc = {uuid: uuid, time: new Date}
|
||||||
await client.connect();
|
await client.connect();
|
||||||
@ -51,7 +51,7 @@ async function addRegReq(uuid) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function userAtime(uuid) {
|
async function userAtime(uuid) { // Needs testing
|
||||||
log.out(`dbAccess.userAtime: Updating access time for user`)
|
log.out(`dbAccess.userAtime: Updating access time for user`)
|
||||||
let q = {uuid: uuid};
|
let q = {uuid: uuid};
|
||||||
let n = {$set: {uuid: uuid, atime: new Date}};
|
let n = {$set: {uuid: uuid, atime: new Date}};
|
||||||
|
@ -3,7 +3,7 @@ const crypto = require('crypto')
|
|||||||
const db = require('../services/dbAccess.services')
|
const db = require('../services/dbAccess.services')
|
||||||
|
|
||||||
// Checks users registration key against issued keys
|
// Checks users registration key against issued keys
|
||||||
async function checkUser(key) {
|
async function checkUser(key) { // Needs testing
|
||||||
q = {uuid: key};
|
q = {uuid: key};
|
||||||
res = db.query("registrations", q);
|
res = db.query("registrations", q);
|
||||||
log.out(`authUtils.checkUser: DB Query answer: ${await res}`)
|
log.out(`authUtils.checkUser: DB Query answer: ${await res}`)
|
||||||
@ -11,7 +11,7 @@ async function checkUser(key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Creates an API key for a user
|
// Creates an API key for a user
|
||||||
async function generateKey() {
|
async function generateKey() { // Needs testing
|
||||||
return crypto.randomUUID()
|
return crypto.randomUUID()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ function cleanNrcc(input) {
|
|||||||
return rmPara;
|
return rmPara;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function splitDomain(mail) {
|
async function splitDomain(mail) { // Needs testing
|
||||||
split = mail.split("@")
|
split = mail.split("@")
|
||||||
return split[1]
|
return split[1]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user