pis #12
3
app.js
3
app.js
@ -23,7 +23,7 @@ const kubeRtr = require('./src/routes/kube.routes'); // /kube endpoints
|
|||||||
const findRtr = require('./src/routes/find.routes'); // /find endpoints
|
const findRtr = require('./src/routes/find.routes'); // /find endpoints
|
||||||
const issueRtr = require('./src/routes/issue.routes') // /issue endpoints
|
const issueRtr = require('./src/routes/issue.routes') // /issue endpoints
|
||||||
const statRtr = require('./src/routes/stats.routes'); // /stat 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
|
// Set Server Configurations
|
||||||
const srvListen = process.env.OWL_SRV_LISTEN || "0.0.0.0"
|
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/find', findRtr);
|
||||||
app.use('/api/v1/issue', issueRtr);
|
app.use('/api/v1/issue', issueRtr);
|
||||||
app.use('/api/v1/stats', statRtr)
|
app.use('/api/v1/stats', statRtr)
|
||||||
|
app.use('/api/v1/register', regRtr)
|
||||||
|
|
||||||
// Authented Routes
|
// Authented Routes
|
||||||
app.use('/api/v1/ldbs', authenticate)
|
app.use('/api/v1/ldbs', authenticate)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const valid = [
|
module.exports = valid = [
|
||||||
"owlboard.info",
|
"owlboard.info",
|
||||||
"gwr.com",
|
"gwr.com",
|
||||||
"swrailway.com",
|
"swrailway.com",
|
||||||
@ -8,4 +8,4 @@ const valid = [
|
|||||||
|
|
||||||
// Use Network Rail Control contact book to add domains
|
// Use Network Rail Control contact book to add domains
|
||||||
|
|
||||||
module.exports = valid
|
// module.exports = valid
|
@ -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
|
|
||||||
}
|
|
26
src/controllers/registration.controllers.js
Normal file
26
src/controllers/registration.controllers.js
Normal 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
|
||||||
|
}
|
@ -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;
|
|
8
src/routes/registration.routes.js
Normal file
8
src/routes/registration.routes.js
Normal 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;
|
@ -3,23 +3,29 @@ const auth = require('../utils/auth.utils')
|
|||||||
const db = require('./dbAccess.services')
|
const db = require('./dbAccess.services')
|
||||||
const mail = require('./mail.services')
|
const mail = require('./mail.services')
|
||||||
const clean = require('../utils/sanitizer.utils')
|
const clean = require('../utils/sanitizer.utils')
|
||||||
const domList = require('../configs/domains.configs')
|
const domains = require('../configs/domains.configs')
|
||||||
|
|
||||||
async function createRegKey(eml){
|
async function createRegKey(body){
|
||||||
const domain = await clean.splitDomain(eml)
|
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")
|
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();
|
const uuid = auth.generateKey();
|
||||||
db.addRegReq(await uuid, domain)
|
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
|
if (await message == false) { // This error should be handled in the upstream function
|
||||||
const err = new Error("Message generation error");
|
const err = new Error("Message generation error");
|
||||||
log.out(`registerServices.createRegKey: Error generating registration email`, "err")
|
log.out(`registerServices.createRegKey: Error generating registration email`, "err")
|
||||||
return 500;
|
return 500;
|
||||||
}
|
}
|
||||||
return await mail.send(message);
|
if (await mail.send(message) == true) {
|
||||||
|
return {status: 201, message: "email sent"}
|
||||||
|
}
|
||||||
|
return {status: 500, message: "server error, email send failed"}
|
||||||
}
|
}
|
||||||
return 401;
|
return {status: 403, message: "forbidden, domain is not on whitelist"}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function regUser(req) {
|
async function regUser(req) {
|
Loading…
Reference in New Issue
Block a user