fix email

This commit is contained in:
lefuturiste 2020-07-31 13:07:31 +00:00
parent d41551c806
commit bac5347c65
3 changed files with 12 additions and 10 deletions

View file

@ -4,6 +4,8 @@ import fs from 'fs'
import twig from 'twig' import twig from 'twig'
export default class EmailService { export default class EmailService {
static transporter: any = null
static init() { static init() {
if (this.isMocked()) { if (this.isMocked()) {
console.warn('> EmailService: WARNING: EMAIL IS MOCKED!') console.warn('> EmailService: WARNING: EMAIL IS MOCKED!')
@ -25,7 +27,7 @@ export default class EmailService {
pass: process.env.SMTP_PASSWORD, pass: process.env.SMTP_PASSWORD,
} }
} }
//console.log(config) console.log('> EmailService: Transport created ', config)
return nodemailer.createTransport(config) return nodemailer.createTransport(config)
} }
@ -43,7 +45,10 @@ export default class EmailService {
// text: params.text, // text: params.text,
// html: params.html // html: params.html
// }) // })
return this.getTransporter().sendMail(params) if (EmailService.transporter === null) {
EmailService.transporter = EmailService.getTransporter()
}
return EmailService.transporter.sendMail(params)
} }
static send(to: string, subject: string, templateName: string, templateParams: any): Promise<any> { static send(to: string, subject: string, templateName: string, templateParams: any): Promise<any> {
@ -72,10 +77,10 @@ export default class EmailService {
resolve() resolve()
} else { } else {
this.nativeSend(config).then(res => { this.nativeSend(config).then(res => {
console.log('> A "' + templateName + '" email was sent') console.log('> A "' + templateName + '" email was sent to ' + to)
resolve(res) resolve(res)
}).catch(err => { }).catch(err => {
console.log('> A "' + templateName + '" email failed to be sent') console.log('> A "' + templateName + '" email failed to be sent to ' + to)
console.error(err) console.error(err)
reject() reject()
}) })

View file

@ -72,7 +72,7 @@ export default class AdminOrganizationController {
} }
static storeUniversal(adminName: string, email: string, validationState: string): Promise<any> { static storeUniversal(adminName: string, email: string, validationState: string): Promise<any> {
console.log(adminName, email, validationState) console.log('> AdminOrganizationController: STORE:', adminName, email, validationState)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (validationState == null) { if (validationState == null) {
validationState = 'unaware' validationState = 'unaware'
@ -111,7 +111,7 @@ export default class AdminOrganizationController {
} }
} }
Organization.create(body).then(data => { Organization.create(body).then(data => {
//AdminOrganizationController.sendEmailTokenUniversal(data) AdminOrganizationController.sendEmailTokenUniversal(data)
resolve({ data, body }) resolve({ data, body })
}).catch(err => reject(err)) }).catch(err => reject(err))
}) })

View file

@ -29,10 +29,7 @@ class AllowedString extends mongoose.SchemaType {
const email = { const email = {
type: String, type: String,
validate: { validate: {
validator: function(v: string) { validator: (v: string) => /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(v),
console.log(v)
return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(v);
},
message: "Invalid email" message: "Invalid email"
} }
} }