removed preview temporarily, got mailer api working again

This commit is contained in:
Ro 2020-07-02 13:34:39 -07:00
parent 9a14d6cf5c
commit 5227b1faa1
8 changed files with 50 additions and 38 deletions

View file

@ -1,11 +1,13 @@
import Settings, { SETTINGS_FILE } from '../../data/Settings';
var express = require('express'); var express = require('express');
var router = express.Router(); var router = express.Router();
var nodemailer = require('nodemailer'); var nodemailer = require('nodemailer');
var mg = require('nodemailer-mailgun-transport'); var mg = require('nodemailer-mailgun-transport');
const fs = require('fs-extra');
const pug = require('pug'); const pug = require('pug');
const settings = new Settings();
router.post('/', function (req, res) { router.post('/', function (req, res) {
fs.readJson('config/site-settings.json') settings
.load(SETTINGS_FILE)
.then(settings => { .then(settings => {
let transport = ''; let transport = '';
var auth = ''; var auth = '';
@ -17,8 +19,8 @@ router.post('/', function(req, res) {
secure: false, secure: false,
auth: { auth: {
type: 'login', type: 'login',
email: settings.email.smtp, user: settings.email.smtp,
password: settings.email.smtp.password pass: settings.email.smtp.password
} }
}; };
transport = nodemailer.createTransport(auth); transport = nodemailer.createTransport(auth);
@ -26,24 +28,24 @@ router.post('/', function(req, res) {
case 'option-mg': case 'option-mg':
auth = { auth = {
auth: { auth: {
api_key: settings.email.mailgun['api-key'], api_key: settings.email.mailgun.key,
domain: settings.email.mailgun.domain domain: settings.email.mailgun.domain
} }
}; };
transport = nodemailer.createTransport(mg(auth)); transport = nodemailer.createTransport(mg(auth));
break; break;
} }
let render = pug.compileFile('themes/dash/email/base.pug'); let render = pug.compileFile('brain/views/email/base.pug');
let html = render({ let html = render({
title: settings.title, title: settings.global.title,
header: 'a note from ' + settings.title, header: 'a note from ' + settings.global.title,
content: req.body.content, content: req.body.content,
footer: 'powered by fipamo' footer: 'powered by fipamo'
}); });
transport.sendMail( transport.sendMail(
{ {
from: 'control@playvico.us', from: 'control@playvico.us',
to: 'are0h@protonmail.com', // An array if you have multiple recipients. to: req.session.user.email, // An array if you have multiple recipients.
subject: 'Hey beautiful', subject: 'Hey beautiful',
//You can use "html:" to send HTML email content. It's magic! //You can use "html:" to send HTML email content. It's magic!
html: html html: html
@ -52,7 +54,6 @@ router.post('/', function(req, res) {
}, },
function (err, info) { function (err, info) {
if (err) { if (err) {
//console.log(err);
res.json({ res.json({
message: 'MAIL ERROR', message: 'MAIL ERROR',
desc: err desc: err

View file

@ -48,20 +48,19 @@ var nav = require('./routes/dash/nav');
//api //api
var pages = require('./api/v1/pages'); var pages = require('./api/v1/pages');
var setting = require('./api/v1/settings'); var setting = require('./api/v1/settings');
//var mailer = require('./api/mail/mailer'); var mailer = require('./api/v1/mailer');
var auth = require('./api/v1/auth'); var auth = require('./api/v1/auth');
// API PATHS // API PATHS
app.use('/api/v1/page', pages); app.use('/api/v1/page', pages);
app.use('/api/v1/settings', setting); app.use('/api/v1/settings', setting);
//app.use('/api/mail', mailer);
app.use('/api/v1/auth', auth); app.use('/api/v1/auth', auth);
app.use('/api/v1/mailer', mailer);
// PAGES // PAGES
app.use('/@/dashboard', dash); app.use('/@/dashboard', dash);
app.use('/@/dashboard/page', page); app.use('/@/dashboard/page', page);
app.use('/@/dashboard/settings', settings); app.use('/@/dashboard/settings', settings);
app.use('/@/dashboard/navigation', nav); app.use('/@/dashboard/navigation', nav);
//app.use('/mailer', mailer);
// catch 404 and forward to error handler // catch 404 and forward to error handler
app.use(function (req, res, next) { app.use(function (req, res, next) {
var err = new Error('Not Found'); var err = new Error('Not Found');

View file

@ -6,7 +6,7 @@
input(type='text', name='smtp-pass' id='smtp-pass', placeholder='password', value=settings.email.smtp.password , autofocus) input(type='text', name='smtp-pass' id='smtp-pass', placeholder='password', value=settings.email.smtp.password , autofocus)
#mail-mg(data-enabled='false') #mail-mg(data-enabled='false')
input(type='text', name='mg-domain' id='mg-domain', placeholder='domain', value=settings.email.mailgun.domain autofocus) input(type='text', name='mg-domain' id='mg-domain', placeholder='domain', value=settings.email.mailgun.domain autofocus)
input(type='text', name='mg-key' id='mg-key', placeholder='api key', value=settings.email.mailgun['api-key'] , autofocus) input(type='text', name='mg-key' id='mg-key', placeholder='api key', value=settings.email.mailgun.key , autofocus)
-else if(settings.email.active == "option-mg") -else if(settings.email.active == "option-mg")
#mail-smtp(data-enabled='false') #mail-smtp(data-enabled='false')
input(type='text', name='smtp-domain' id='smtp-domain', placeholder='domain', value=settings.email.smtp.domain autofocus) input(type='text', name='smtp-domain' id='smtp-domain', placeholder='domain', value=settings.email.smtp.domain autofocus)
@ -14,7 +14,7 @@
input(type='text', name='smtp-pass' id='smtp-pass', placeholder='password', value=settings.email.smtp.password , autofocus) input(type='text', name='smtp-pass' id='smtp-pass', placeholder='password', value=settings.email.smtp.password , autofocus)
#mail-mg(data-enabled='mg') #mail-mg(data-enabled='mg')
input(type='text', name='mg-domain' id='mg-domain', placeholder='domain', value=settings.email.mailgun.domain autofocus) input(type='text', name='mg-domain' id='mg-domain', placeholder='domain', value=settings.email.mailgun.domain autofocus)
input(type='text', name='mg-key' id='mg-key', placeholder='api key', value=settings.email.mailgun['api-key'] , autofocus) input(type='text', name='mg-key' id='mg-key', placeholder='api key', value=settings.email.mailgun.key , autofocus)
-else -else
#mail-smtp(data-enabled='false') #mail-smtp(data-enabled='false')
input(type='text', name='smtp-domain' id='smtp-domain', placeholder='domain', value=settings.email.smtp.domain autofocus) input(type='text', name='smtp-domain' id='smtp-domain', placeholder='domain', value=settings.email.smtp.domain autofocus)
@ -22,4 +22,4 @@
input(type='text', name='smtp-pass' id='smtp-pass', placeholder='password', value=settings.email.smtp.password , autofocus) input(type='text', name='smtp-pass' id='smtp-pass', placeholder='password', value=settings.email.smtp.password , autofocus)
#mail-mg(data-enabled='false') #mail-mg(data-enabled='false')
input(type='text', name='mg-domain' id='mg-domain', placeholder='domain', value=settings.email.mailgun.domain autofocus) input(type='text', name='mg-domain' id='mg-domain', placeholder='domain', value=settings.email.mailgun.domain autofocus)
input(type='text', name='mg-key' id='mg-key', placeholder='api key', value=settings.email.mailgun['api-key'] , autofocus) input(type='text', name='mg-key' id='mg-key', placeholder='api key', value=settings.email.mailgun.key , autofocus)

View file

@ -8,6 +8,6 @@
button#option-published.option-inactive.post-option-btn(data-active= status[2]) button#option-published.option-inactive.post-option-btn(data-active= status[2])
svg#option-published-icon(viewBox="0 0 20 20" class="icons") svg#option-published-icon(viewBox="0 0 20 20" class="icons")
use#option-published-icon(xlink:href='/assets/images/global/sprite.svg#entypo-globe') use#option-published-icon(xlink:href='/assets/images/global/sprite.svg#entypo-globe')
button#option-preview.option-inactive(data-active="false") //button#option-preview.option-inactive(data-active="false")
svg#option-preview-icon(viewBox="0 0 20 20" class="icons") svg#option-preview-icon(viewBox="0 0 20 20" class="icons")
use#option-preview-icon(xlink:href='/assets/images/global/sprite.svg#entypo-eye') use#option-preview-icon(xlink:href='/assets/images/global/sprite.svg#entypo-eye')

View file

@ -1,33 +1,26 @@
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../../../src/com/utils/DataUtils'; import FipamoAdminAPI from '../../libraries/FipamoAdminAPI';
import * as DataEvent from '../../../src/com/events/DataEvent'; import Notficaton from '../ui/Notifications';
const admin = new FipamoAdminAPI();
const notify = new Notficaton();
export default class Mailer { export default class Mailer {
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() { constructor() {}
this.dataUtils = new DataUtils();
}
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
sendMail() { sendMail() {
var self = this;
let mailData = { let mailData = {
content: 'This is a test email' content: 'This is a test email'
}; };
self.dataUtils admin
.request( .sendMail(mailData)
'/api/mail', .then(result => {
DataEvent.SETTINGS_UPDATED, notify.alert(result.message, true);
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
mailData
)
.then(() => {
//console.log(response);
}) })
.catch(() => { .catch(err => {
//console.log(err); notify.alert(err.message, false);
}); });
} }
//-------------------------- //--------------------------

View file

@ -32,6 +32,7 @@ export const API_RENDER_PAGES = 'renderPages';
export const API_INIT = 'blogInit'; export const API_INIT = 'blogInit';
export const API_INIT_GOOD = 'blogInitGood'; export const API_INIT_GOOD = 'blogInitGood';
export const API_INIT_LAME = 'blogInitLame'; export const API_INIT_LAME = 'blogInitLame';
export const SEND_MAIL = 'sendMail';
class DataEvent { class DataEvent {
//-------------------------- //--------------------------
// methods // methods

View file

@ -18,6 +18,7 @@ export const API_UPLOAD_AVATAR = '/api/v1/settings/add-avatar';
export const API_UPLOAD_BACKGROUND = '/api/v1/settings/add-feature-background'; export const API_UPLOAD_BACKGROUND = '/api/v1/settings/add-feature-background';
export const API_PUBLISH_PAGES = '/api/v1/settings/publish-pages'; export const API_PUBLISH_PAGES = '/api/v1/settings/publish-pages';
export const API_NAV_SYNC = '/api/v1/settings/nav-sync'; export const API_NAV_SYNC = '/api/v1/settings/nav-sync';
export const API_SEND_MAIL = '/api/v1/mailer';
import * as DataEvent from '../com/events/DataEvent'; import * as DataEvent from '../com/events/DataEvent';
export default class APIUtils { export default class APIUtils {
//-------------------------- //--------------------------
@ -170,6 +171,23 @@ export default class APIUtils {
}); });
}); });
} }
sendMail(message) {
return new Promise((resolve, reject) => {
this._request(
API_SEND_MAIL,
DataEvent.SEND_MAIL,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
message
)
.then(result => {
resolve(result);
})
.catch(err => {
reject(err);
});
});
}
//-------------------------- //--------------------------
// private // private
//-------------------------- //--------------------------

View file

@ -193,7 +193,7 @@
border-radius 0 3px 3px 0 border-radius 0 3px 3px 0
button button
width 25% width 33.3%
height 39px height 39px
object-transitions(0.3s) object-transitions(0.3s)
margin 0 margin 0