pis #12
@ -1,5 +1,5 @@
|
||||
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 smtpUser = process.env.OWL_EML_USER
|
||||
@ -8,28 +8,28 @@ const smtpHost = process.env.OWL_EML_HOST
|
||||
const smtpPort = process.env.OWL_EML_PORT
|
||||
|
||||
let transporter = mail.createTransport({
|
||||
host: smtpHost,
|
||||
port: smtpPort,
|
||||
secure: false, // Must be false for STARTTLS on port 587
|
||||
auth: {
|
||||
user: smtpUser,
|
||||
pass: smtpPass
|
||||
}
|
||||
host: smtpHost,
|
||||
port: smtpPort,
|
||||
secure: false, // Must be false for STARTTLS on port 587
|
||||
auth: {
|
||||
user: smtpUser,
|
||||
pass: smtpPass
|
||||
}
|
||||
})
|
||||
|
||||
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
|
||||
try {
|
||||
var res = await transporter.sendMail(message)
|
||||
} catch(err) {
|
||||
log.out(`mailServices.send: Message send failed: ${err}`, "err")
|
||||
return false;
|
||||
log.out(`mailServices.send: Message send failed: ${err}`, 'err')
|
||||
return false
|
||||
}
|
||||
log.out(`mailServices.send: SMTP Response: ${res.response}`)
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
send
|
||||
send
|
||||
}
|
@ -7,44 +7,44 @@ const domains = require('../configs/domains.configs')
|
||||
const errors = require('../configs/errorCodes.configs')
|
||||
|
||||
async function createRegKey(body) {
|
||||
log.out(`registerServices.createRegKey: Incoming request`, "INFO")
|
||||
const domain = await clean.getDomainFromEmail(body.email) // The function should validate the email
|
||||
log.out(`registerServices: New registration request from domain: ${domain}`, "info")
|
||||
if (domains.includes(domain)) {
|
||||
log.out(`registerServices.createRegKey: Key from valid domain: ${domain}`)
|
||||
const uuid = await auth.generateKey();
|
||||
db.addRegReq(uuid, domain)
|
||||
const message = await auth.generateConfirmationEmail(body.email, uuid)
|
||||
if (!message) {
|
||||
const err = new Error("Message generation error");
|
||||
log.out(`registerServices.createRegKey: Error generating registration email`, "err")
|
||||
return 500;
|
||||
}
|
||||
if (await mail.send(message) == true) {
|
||||
return {status: 201, message: "email sent"}
|
||||
}
|
||||
return {status: 500, errorCode: 950, errorMsg: errors[950]}
|
||||
log.out('registerServices.createRegKey: Incoming request', 'INFO')
|
||||
const domain = await clean.getDomainFromEmail(body.email) // The function should validate the email
|
||||
log.out(`registerServices: New registration request from domain: ${domain}`, 'info')
|
||||
if (domains.includes(domain)) {
|
||||
log.out(`registerServices.createRegKey: Key from valid domain: ${domain}`)
|
||||
const uuid = await auth.generateKey()
|
||||
db.addRegReq(uuid, domain)
|
||||
const message = await auth.generateConfirmationEmail(body.email, uuid)
|
||||
if (!message) {
|
||||
const err = new Error('Message generation error')
|
||||
log.out('registerServices.createRegKey: Error generating registration email', 'err')
|
||||
return 500
|
||||
}
|
||||
return {status: 403, errorCode: 702, errorMsg: errors[702]}
|
||||
if (await mail.send(message) == true) {
|
||||
return {status: 201, message: 'email sent'}
|
||||
}
|
||||
return {status: 500, errorCode: 950, errorMsg: errors[950]}
|
||||
}
|
||||
return {status: 403, errorCode: 702, errorMsg: errors[702]}
|
||||
}
|
||||
|
||||
async function regUser(req) { // Add input validation
|
||||
log.out(`Read UUID: ${req.uuid}`, "dbug")
|
||||
log.out(`registrationServices.regUser: Checking validity of : ${req.uuid}`, "info")
|
||||
log.out(`Read UUID: ${req.uuid}`, 'dbug')
|
||||
log.out(`registrationServices.regUser: Checking validity of : ${req.uuid}`, 'info')
|
||||
const res = await auth.checkRequest(req.uuid)
|
||||
log.out(`registrationServices.regUser: checkRequest returned: ${JSON.stringify(res)}`, "info")
|
||||
if (res.result) {
|
||||
const uuid = await auth.generateKey()
|
||||
const apiKey = await db.addUser(uuid, res.domain)
|
||||
if (apiKey) {
|
||||
db.delRegReq(req.uuid)
|
||||
return {status: 201, message: "User added", api_key: uuid}
|
||||
}
|
||||
log.out(`registrationServices.regUser: checkRequest returned: ${JSON.stringify(res)}`, 'info')
|
||||
if (res.result) {
|
||||
const uuid = await auth.generateKey()
|
||||
const apiKey = await db.addUser(uuid, res.domain)
|
||||
if (apiKey) {
|
||||
db.delRegReq(req.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]}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
regUser,
|
||||
createRegKey
|
||||
regUser,
|
||||
createRegKey
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
const htmlShrink = require('html-minifier').minify
|
||||
|
||||
module.exports = async function minify(input) { // Do I need to name this function?
|
||||
// Minify HTML input, including inline styles.
|
||||
module.exports = async function minifyMail(input) {
|
||||
// Minify HTML input, including inline styles.
|
||||
//let inline = cssInliner(input) ??
|
||||
return htmlShrink(input)
|
||||
}
|
Loading…
Reference in New Issue
Block a user