backend/src/services/auth.services.js
Fred Boniface 7d0b9f9d44 Add comments
Signed-off-by: Fred Boniface <fred@fjla.uk>
2023-04-05 01:09:50 +01:00

33 lines
1.1 KiB
JavaScript

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')
const clean = require('../utils/sanitizer.utils')
const domList= require('../configs/domains.configs')
async function createRegKey(eml){ // Needs moving to register.services
const domain = clean.splitDomain(eml)
if (domain in domList.valid) { // Don't know if this is correct
const uuid = util.generateKey();
db.addRegReq(await uuid, await domain)
mail.sendRegister("mail", "uuid");
return 201 // These returns still need handling
} else {
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 {
return {status: 401, message: "Unautorised"}
}
}
module.exports = {
regUser,
createRegKey
}