pis #12

Merged
fred.boniface merged 95 commits from pis into main 2023-05-06 21:54:51 +01:00
7 changed files with 51 additions and 31 deletions
Showing only changes of commit 38cf679da7 - Show all commits

3
app.js
View File

@ -23,7 +23,7 @@ const kubeRtr = require('./src/routes/kube.routes'); // /kube endpoints
const findRtr = require('./src/routes/find.routes'); // /find endpoints
const issueRtr = require('./src/routes/issue.routes') // /issue endpoints
const statRtr = require('./src/routes/stats.routes'); // /stat endpoints
const auth = require('./src/routes/auth.routes'); // /auth endpoints
const regRtr = require('./src/routes/registration.routes'); // /auth endpoints
// Set Server Configurations
const srvListen = process.env.OWL_SRV_LISTEN || "0.0.0.0"
@ -60,6 +60,7 @@ app.use('/api/v1/kube', kubeRtr);
app.use('/api/v1/find', findRtr);
app.use('/api/v1/issue', issueRtr);
app.use('/api/v1/stats', statRtr)
app.use('/api/v1/register', regRtr)
// Authented Routes
app.use('/api/v1/ldbs', authenticate)

View File

@ -1,4 +1,4 @@
const valid = [
module.exports = valid = [
"owlboard.info",
"gwr.com",
"swrailway.com",
@ -8,4 +8,4 @@ const valid = [
// Use Network Rail Control contact book to add domains
module.exports = valid
// module.exports = valid

View File

@ -1,14 +0,0 @@
const auth = require('../services/auth.services');
async function register(req, res, next){
try {
res.json(await auth.addUser(req.body))
} catch (err) {
console.error(`Controller Error`, err.message);
next(err);
}
}
module.exports = {
register
}

View File

@ -0,0 +1,26 @@
const reg = require('../services/registration.services');
async function register(req, res, next) {
try {
let response = await reg.addUser(req.body)
res.status(response.status).json(response)
} catch (err) {
console.error(`Controller Error`, err.message)
next(err)
}
}
async function request(req, res, next) {
try {
let response = await reg.createRegKey(req.body)
res.status(response.status).json(response)
} catch (err) {
console.error(err)
next(err)
}
}
module.exports = {
register,
request
}

View File

@ -1,7 +0,0 @@
const express = require('express');
const router = express.Router();
const authController = require('../controllers/auth.controllers');
router.post('/register', authController.register);
module.exports = router;

View File

@ -0,0 +1,8 @@
const express = require('express');
const router = express.Router();
const regController = require('../controllers/registration.controllers');
router.post('/request', regController.request);
router.post('/register', regController.register)
module.exports = router;

View File

@ -3,23 +3,29 @@ 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')
const domains = require('../configs/domains.configs')
async function createRegKey(eml){
const domain = await clean.splitDomain(eml)
async function createRegKey(body){
log.out(`registerServices.createRegKey: Incoming request`, "INFO")
log.out(`registerServices.createRegKey: ${JSON.stringify(domains)}`)
const domain = await clean.splitDomain(body.email)
log.out(`registerServices: New registration request from domain: ${domain}`, "info")
if (domList.valid.includes(domain)) { // Needs testing
if (domains.includes(domain)) { // Needs testing
log.out(`registerServices.createRegKey: Key from valid domain: ${domain}`)
const uuid = auth.generateKey();
db.addRegReq(await uuid, domain)
const message = auth.generateConfirmationEmail(eml, uuid)
const message = auth.generateConfirmationEmail(body.email, 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);
if (await mail.send(message) == true) {
return {status: 201, message: "email sent"}
}
return 401;
return {status: 500, message: "server error, email send failed"}
}
return {status: 403, message: "forbidden, domain is not on whitelist"}
}
async function regUser(req) {