38 lines
1.4 KiB
JavaScript
38 lines
1.4 KiB
JavaScript
const log = require('../utils/log.utils') // Currently no logging on this page
|
|
const auth = require('../utils/auth.utils')
|
|
const db = require('./dbAccess.services')
|
|
const mail = require('./mail.services')
|
|
const clean = require('../utils/sanitizer.utils')
|
|
const domList = require('../configs/domains.configs')
|
|
|
|
async function createRegKey(eml){
|
|
const domain = await clean.splitDomain(eml)
|
|
log.out(`registerServices: New registration request from domain: ${domain}`, "info")
|
|
if (domList.valid.includes(domain)) { // Needs testing
|
|
const uuid = auth.generateKey();
|
|
db.addRegReq(await uuid, domain)
|
|
const message = auth.generateConfirmationEmail(eml, uuid)
|
|
if (await message == false) { // This error should be handled in the upstream function
|
|
const err = new Error("Message generation error");
|
|
log.out(`registerServices.createRegKey: Error generating registration email`, "err")
|
|
return 500;
|
|
}
|
|
return await mail.send(message);
|
|
}
|
|
return 401;
|
|
}
|
|
|
|
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
|
|
} |