newStaffLDB-API #48
@ -1,4 +1,3 @@
|
|||||||
const log = require("../utils/logs.utils");
|
|
||||||
const auth = require("../utils/auth.utils");
|
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");
|
||||||
@ -6,23 +5,21 @@ const clean = require("../utils/sanitizer.utils");
|
|||||||
const domains = require("../configs/domains.configs");
|
const domains = require("../configs/domains.configs");
|
||||||
const errors = require("../configs/errorCodes.configs");
|
const errors = require("../configs/errorCodes.configs");
|
||||||
|
|
||||||
|
import { logger } from "../utils/logger.utils";
|
||||||
|
|
||||||
async function createRegKey(body) {
|
async function createRegKey(body) {
|
||||||
log.out("registerServices.createRegKey: Incoming request", "INFO");
|
logger.debug("registerServices.createRegKey: Incoming request");
|
||||||
if (body.email) {
|
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");
|
logger.info(`registerServices: Registration request from: ${domain}`);
|
||||||
if (domains.includes(domain)) {
|
if (domains.includes(domain)) {
|
||||||
log.out(
|
logger.debug(`registerServices.createRegKey: Key from valid: ${domain}`);
|
||||||
`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);
|
||||||
if (!message) {
|
if (!message) {
|
||||||
const err = new Error("Message generation error");
|
const err = new Error("Message generation error");
|
||||||
log.out("registerServices.createRegKey: Error generating email", "err");
|
logger.error(err, 'registerServices.createRegKey: Error generating email');
|
||||||
log.out(err, "err");
|
|
||||||
return 500;
|
return 500;
|
||||||
}
|
}
|
||||||
if ((await mail.send(message)) == true) {
|
if ((await mail.send(message)) == true) {
|
||||||
@ -38,10 +35,9 @@ async function createRegKey(body) {
|
|||||||
|
|
||||||
async function regUser(req) {
|
async function regUser(req) {
|
||||||
// Add input validation
|
// Add input validation
|
||||||
log.out(`Read UUID: ${req.uuid}`, "dbug");
|
logger.trace(`Read UUID: ${req.uuid}`);
|
||||||
log.out(`registrationServices.regUser: Request from: ${req.uuid}`, "info");
|
|
||||||
const res = await auth.checkRequest(req.uuid);
|
const res = await auth.checkRequest(req.uuid);
|
||||||
log.out(`registrationServices.regUser: ${JSON.stringify(res)}`, "info");
|
logger.debug(res, 'registrationServices');
|
||||||
if (res.result) {
|
if (res.result) {
|
||||||
const uuid = await auth.generateKey();
|
const uuid = await auth.generateKey();
|
||||||
const apiKey = await db.addUser(uuid, res.domain);
|
const apiKey = await db.addUser(uuid, res.domain);
|
||||||
@ -54,7 +50,6 @@ async function regUser(req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getUser(uuid) {
|
async function getUser(uuid) {
|
||||||
log.out("registrationServices: Finding user for given UUID", "dbug");
|
|
||||||
try {
|
try {
|
||||||
const filter = {
|
const filter = {
|
||||||
uuid: uuid,
|
uuid: uuid,
|
||||||
|
Loading…
Reference in New Issue
Block a user