forked from projects/fipamo
removed preview temporarily, got mailer api working again
This commit is contained in:
parent
9a14d6cf5c
commit
5227b1faa1
8 changed files with 50 additions and 38 deletions
|
@ -1,11 +1,13 @@
|
|||
import Settings, { SETTINGS_FILE } from '../../data/Settings';
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var nodemailer = require('nodemailer');
|
||||
var mg = require('nodemailer-mailgun-transport');
|
||||
const fs = require('fs-extra');
|
||||
const pug = require('pug');
|
||||
const settings = new Settings();
|
||||
router.post('/', function (req, res) {
|
||||
fs.readJson('config/site-settings.json')
|
||||
settings
|
||||
.load(SETTINGS_FILE)
|
||||
.then(settings => {
|
||||
let transport = '';
|
||||
var auth = '';
|
||||
|
@ -17,8 +19,8 @@ router.post('/', function(req, res) {
|
|||
secure: false,
|
||||
auth: {
|
||||
type: 'login',
|
||||
email: settings.email.smtp,
|
||||
password: settings.email.smtp.password
|
||||
user: settings.email.smtp,
|
||||
pass: settings.email.smtp.password
|
||||
}
|
||||
};
|
||||
transport = nodemailer.createTransport(auth);
|
||||
|
@ -26,24 +28,24 @@ router.post('/', function(req, res) {
|
|||
case 'option-mg':
|
||||
auth = {
|
||||
auth: {
|
||||
api_key: settings.email.mailgun['api-key'],
|
||||
api_key: settings.email.mailgun.key,
|
||||
domain: settings.email.mailgun.domain
|
||||
}
|
||||
};
|
||||
transport = nodemailer.createTransport(mg(auth));
|
||||
break;
|
||||
}
|
||||
let render = pug.compileFile('themes/dash/email/base.pug');
|
||||
let render = pug.compileFile('brain/views/email/base.pug');
|
||||
let html = render({
|
||||
title: settings.title,
|
||||
header: 'a note from ' + settings.title,
|
||||
title: settings.global.title,
|
||||
header: 'a note from ' + settings.global.title,
|
||||
content: req.body.content,
|
||||
footer: 'powered by fipamo'
|
||||
});
|
||||
transport.sendMail(
|
||||
{
|
||||
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',
|
||||
//You can use "html:" to send HTML email content. It's magic!
|
||||
html: html
|
||||
|
@ -52,7 +54,6 @@ router.post('/', function(req, res) {
|
|||
},
|
||||
function (err, info) {
|
||||
if (err) {
|
||||
//console.log(err);
|
||||
res.json({
|
||||
message: 'MAIL ERROR',
|
||||
desc: err
|
|
@ -48,20 +48,19 @@ var nav = require('./routes/dash/nav');
|
|||
//api
|
||||
var pages = require('./api/v1/pages');
|
||||
var setting = require('./api/v1/settings');
|
||||
//var mailer = require('./api/mail/mailer');
|
||||
var mailer = require('./api/v1/mailer');
|
||||
var auth = require('./api/v1/auth');
|
||||
// API PATHS
|
||||
|
||||
app.use('/api/v1/page', pages);
|
||||
app.use('/api/v1/settings', setting);
|
||||
//app.use('/api/mail', mailer);
|
||||
app.use('/api/v1/auth', auth);
|
||||
app.use('/api/v1/mailer', mailer);
|
||||
// PAGES
|
||||
app.use('/@/dashboard', dash);
|
||||
app.use('/@/dashboard/page', page);
|
||||
app.use('/@/dashboard/settings', settings);
|
||||
app.use('/@/dashboard/navigation', nav);
|
||||
//app.use('/mailer', mailer);
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function (req, res, next) {
|
||||
var err = new Error('Not Found');
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
input(type='text', name='smtp-pass' id='smtp-pass', placeholder='password', value=settings.email.smtp.password , autofocus)
|
||||
#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-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")
|
||||
#mail-smtp(data-enabled='false')
|
||||
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)
|
||||
#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-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
|
||||
#mail-smtp(data-enabled='false')
|
||||
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)
|
||||
#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-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)
|
|
@ -8,6 +8,6 @@
|
|||
button#option-published.option-inactive.post-option-btn(data-active= status[2])
|
||||
svg#option-published-icon(viewBox="0 0 20 20" class="icons")
|
||||
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")
|
||||
use#option-preview-icon(xlink:href='/assets/images/global/sprite.svg#entypo-eye')
|
|
@ -1,33 +1,26 @@
|
|||
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../../../src/com/utils/DataUtils';
|
||||
import * as DataEvent from '../../../src/com/events/DataEvent';
|
||||
import FipamoAdminAPI from '../../libraries/FipamoAdminAPI';
|
||||
import Notficaton from '../ui/Notifications';
|
||||
const admin = new FipamoAdminAPI();
|
||||
const notify = new Notficaton();
|
||||
export default class Mailer {
|
||||
//--------------------------
|
||||
// constructor
|
||||
//--------------------------
|
||||
constructor() {
|
||||
this.dataUtils = new DataUtils();
|
||||
}
|
||||
constructor() {}
|
||||
//--------------------------
|
||||
// methods
|
||||
//--------------------------
|
||||
sendMail() {
|
||||
var self = this;
|
||||
let mailData = {
|
||||
content: 'This is a test email'
|
||||
};
|
||||
self.dataUtils
|
||||
.request(
|
||||
'/api/mail',
|
||||
DataEvent.SETTINGS_UPDATED,
|
||||
REQUEST_TYPE_POST,
|
||||
CONTENT_TYPE_JSON,
|
||||
mailData
|
||||
)
|
||||
.then(() => {
|
||||
//console.log(response);
|
||||
admin
|
||||
.sendMail(mailData)
|
||||
.then(result => {
|
||||
notify.alert(result.message, true);
|
||||
})
|
||||
.catch(() => {
|
||||
//console.log(err);
|
||||
.catch(err => {
|
||||
notify.alert(err.message, false);
|
||||
});
|
||||
}
|
||||
//--------------------------
|
||||
|
|
|
@ -32,6 +32,7 @@ export const API_RENDER_PAGES = 'renderPages';
|
|||
export const API_INIT = 'blogInit';
|
||||
export const API_INIT_GOOD = 'blogInitGood';
|
||||
export const API_INIT_LAME = 'blogInitLame';
|
||||
export const SEND_MAIL = 'sendMail';
|
||||
class DataEvent {
|
||||
//--------------------------
|
||||
// methods
|
||||
|
|
|
@ -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_PUBLISH_PAGES = '/api/v1/settings/publish-pages';
|
||||
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';
|
||||
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
|
||||
//--------------------------
|
||||
|
|
|
@ -193,7 +193,7 @@
|
|||
border-radius 0 3px 3px 0
|
||||
|
||||
button
|
||||
width 25%
|
||||
width 33.3%
|
||||
height 39px
|
||||
object-transitions(0.3s)
|
||||
margin 0
|
||||
|
|
Loading…
Reference in a new issue