pis #12
@ -1,5 +1,5 @@
|
|||||||
const log = require('../utils/log.utils')
|
const log = require('../utils/log.utils')
|
||||||
const mail = require('nodemailer'); //>> Probs wrong
|
const mail = require('nodemailer') //>> Probs wrong
|
||||||
|
|
||||||
const fromAddr = process.env.OWL_EML_FROM
|
const fromAddr = process.env.OWL_EML_FROM
|
||||||
const smtpUser = process.env.OWL_EML_USER
|
const smtpUser = process.env.OWL_EML_USER
|
||||||
@ -18,16 +18,16 @@ let transporter = mail.createTransport({
|
|||||||
})
|
})
|
||||||
|
|
||||||
async function send(message){ // message is an object containing strings for: *to, cc, bcc, *subject, *txt, html (* denotes required)
|
async function send(message){ // message is an object containing strings for: *to, cc, bcc, *subject, *txt, html (* denotes required)
|
||||||
log.out(`mailServices.send: Message send request received`, "info")
|
log.out('mailServices.send: Message send request received', 'info')
|
||||||
message.from = fromAddr
|
message.from = fromAddr
|
||||||
try {
|
try {
|
||||||
var res = await transporter.sendMail(message)
|
var res = await transporter.sendMail(message)
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
log.out(`mailServices.send: Message send failed: ${err}`, "err")
|
log.out(`mailServices.send: Message send failed: ${err}`, 'err')
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
log.out(`mailServices.send: SMTP Response: ${res.response}`)
|
log.out(`mailServices.send: SMTP Response: ${res.response}`)
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -7,21 +7,21 @@ const domains = require('../configs/domains.configs')
|
|||||||
const errors = require('../configs/errorCodes.configs')
|
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')
|
||||||
const domain = await clean.getDomainFromEmail(body.email) // The function should validate the email
|
const domain = await clean.getDomainFromEmail(body.email) // The function should validate the email
|
||||||
log.out(`registerServices: New registration request from domain: ${domain}`, "info")
|
log.out(`registerServices: New registration request from domain: ${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: ${domain}`)
|
||||||
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 registration email`, "err")
|
log.out('registerServices.createRegKey: Error generating registration email', 'err')
|
||||||
return 500;
|
return 500
|
||||||
}
|
}
|
||||||
if (await mail.send(message) == true) {
|
if (await mail.send(message) == true) {
|
||||||
return {status: 201, message: "email sent"}
|
return {status: 201, message: 'email sent'}
|
||||||
}
|
}
|
||||||
return {status: 500, errorCode: 950, errorMsg: errors[950]}
|
return {status: 500, errorCode: 950, errorMsg: errors[950]}
|
||||||
}
|
}
|
||||||
@ -29,16 +29,16 @@ async function createRegKey(body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function regUser(req) { // Add input validation
|
async function regUser(req) { // Add input validation
|
||||||
log.out(`Read UUID: ${req.uuid}`, "dbug")
|
log.out(`Read UUID: ${req.uuid}`, 'dbug')
|
||||||
log.out(`registrationServices.regUser: Checking validity of : ${req.uuid}`, "info")
|
log.out(`registrationServices.regUser: Checking validity of : ${req.uuid}`, 'info')
|
||||||
const res = await auth.checkRequest(req.uuid)
|
const res = await auth.checkRequest(req.uuid)
|
||||||
log.out(`registrationServices.regUser: checkRequest returned: ${JSON.stringify(res)}`, "info")
|
log.out(`registrationServices.regUser: checkRequest returned: ${JSON.stringify(res)}`, 'info')
|
||||||
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)
|
||||||
if (apiKey) {
|
if (apiKey) {
|
||||||
db.delRegReq(req.uuid)
|
db.delRegReq(req.uuid)
|
||||||
return {status: 201, message: "User added", api_key: uuid}
|
return {status: 201, message: 'User added', api_key: uuid}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {status: 401, errorCode: 703, errorMsg: errors[703]}
|
return {status: 401, errorCode: 703, errorMsg: errors[703]}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
const htmlShrink = require('html-minifier').minify
|
const htmlShrink = require('html-minifier').minify
|
||||||
|
|
||||||
module.exports = async function minify(input) { // Do I need to name this function?
|
module.exports = async function minifyMail(input) {
|
||||||
// Minify HTML input, including inline styles.
|
// Minify HTML input, including inline styles.
|
||||||
|
//let inline = cssInliner(input) ??
|
||||||
|
return htmlShrink(input)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user