v2 user routes complete
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
eb80d7386e
commit
72444e9fc9
@ -1,4 +1,5 @@
|
|||||||
const statusCodes = {
|
const statusCodes = {
|
||||||
|
400: 'data not found',
|
||||||
700: 'no authentication attempt',
|
700: 'no authentication attempt',
|
||||||
701: 'invalid credentials',
|
701: 'invalid credentials',
|
||||||
702: 'domain not whitelisted',
|
702: 'domain not whitelisted',
|
||||||
@ -6,7 +7,9 @@ const statusCodes = {
|
|||||||
800: 'location code not found',
|
800: 'location code not found',
|
||||||
801: 'unable to fetch location data',
|
801: 'unable to fetch location data',
|
||||||
900: 'invalid request format',
|
900: 'invalid request format',
|
||||||
|
901: 'email not provided',
|
||||||
950: 'upstream server error',
|
950: 'upstream server error',
|
||||||
|
951: 'unknown server error'
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = statusCodes;
|
module.exports = statusCodes;
|
@ -23,7 +23,12 @@ async function request(req, res, next) {
|
|||||||
async function getUser(req, res, next) {
|
async function getUser(req, res, next) {
|
||||||
try {
|
try {
|
||||||
let uuid = req.params.uuid;
|
let uuid = req.params.uuid;
|
||||||
res.json(await reg.getUser(uuid));
|
let data = await reg.getUser(uuid);
|
||||||
|
if (data.status) {
|
||||||
|
res.status(data.status).json(data);
|
||||||
|
} else {
|
||||||
|
res.json(data);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
next(err);
|
next(err);
|
||||||
|
@ -4,6 +4,7 @@ const regCtr = require('../controllers/registration.controllers');
|
|||||||
|
|
||||||
// User
|
// User
|
||||||
router.get('/:uuid', regCtr.getUser);
|
router.get('/:uuid', regCtr.getUser);
|
||||||
|
// Not Implemented router.delete('/:uuid', regCtr.deleteUser);
|
||||||
router.post('/request', regCtr.request);
|
router.post('/request', regCtr.request);
|
||||||
router.post('/register', regCtr.register);
|
router.post('/register', regCtr.register);
|
||||||
|
|
||||||
|
@ -8,10 +8,11 @@ const errors = require('../configs/errorCodes.configs');
|
|||||||
|
|
||||||
async function createRegKey(body) {
|
async function createRegKey(body) {
|
||||||
log.out('registerServices.createRegKey: Incoming request', 'INFO');
|
log.out('registerServices.createRegKey: Incoming request', 'INFO');
|
||||||
|
if (body.email) {
|
||||||
const domain = await clean.getDomainFromEmail(body.email);
|
const domain = await clean.getDomainFromEmail(body.email);
|
||||||
log.out(`registerServices: Registration request from: ${domain}`, 'info');
|
log.out(`registerServices: Registration request from: ${domain}`, 'info');
|
||||||
if (domains.includes(domain)) {
|
if (domains.includes(domain)) {
|
||||||
log.out(`registerServices.createRegKey: Key from valid domain: ${domain}`);
|
log.out(`registerServices.createRegKey: Key from valid: ${domain}`,'info');
|
||||||
const uuid = await auth.generateKey();
|
const uuid = await auth.generateKey();
|
||||||
db.addRegReq(uuid, domain);
|
db.addRegReq(uuid, domain);
|
||||||
const message = await auth.generateConfirmationEmail(body.email, uuid);
|
const message = await auth.generateConfirmationEmail(body.email, uuid);
|
||||||
@ -27,6 +28,9 @@ async function createRegKey(body) {
|
|||||||
return {status: 500, errorCode: 950, errorMsg: errors[950]};
|
return {status: 500, errorCode: 950, errorMsg: errors[950]};
|
||||||
}
|
}
|
||||||
return {status: 403, errorCode: 702, errorMsg: errors[702]};
|
return {status: 403, errorCode: 702, errorMsg: errors[702]};
|
||||||
|
} else {
|
||||||
|
return {status: 400, errorCode: 901, errorMsg: errors[902]};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function regUser(req) { // Add input validation
|
async function regUser(req) { // Add input validation
|
||||||
@ -47,11 +51,20 @@ async function regUser(req) { // Add input validation
|
|||||||
|
|
||||||
async function getUser(uuid) {
|
async function getUser(uuid) {
|
||||||
log.out('registrationServices: Finding user for given UUID', 'dbug');
|
log.out('registrationServices: Finding user for given UUID', 'dbug');
|
||||||
|
try {
|
||||||
const filter = {
|
const filter = {
|
||||||
uuid: uuid
|
uuid: uuid
|
||||||
};
|
};
|
||||||
const res = await db.query('users', filter, false);
|
const res = await db.query('users', filter, false);
|
||||||
|
if (res.length) {
|
||||||
return res;
|
return res;
|
||||||
|
} else {
|
||||||
|
return {status: 404, errorCode:400, errorMsg: errors[400]};
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
return {status: 500, errorCode: 951, errorMsg: errors[951]};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
Loading…
Reference in New Issue
Block a user