33 lines
1.1 KiB
JavaScript
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
|
|
} |