Compose email from admin panel

This commit is contained in:
Evert Prants 2018-02-13 23:02:07 +02:00
parent e1a66c38da
commit 7c0a94008d
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
4 changed files with 86 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import express from 'express'
import ensureLogin from '../../scripts/ensureLogin'
import wrap from '../../scripts/asyncRoute'
import API from '../api/admin'
import Emailer from '../api/emailer'
import {User} from '../api'
const router = express.Router()
@ -287,6 +288,21 @@ apiRouter.post('/ban', csrfVerify, wrap(async (req, res) => {
res.jsonp(result)
}))
apiRouter.post('/email', csrfVerify, wrap(async (req, res) => {
if (!req.body.email) throw new Error('Email missing')
if (!req.body.title) throw new Error('Title missing')
if (!req.body.content) throw new Error('Content missing')
var message = {
subject: req.body.title,
html: req.body.content
}
let result = await Emailer.sendMail(req.body.email, message)
res.jsonp(result)
}))
apiRouter.use((err, req, res, next) => {
console.error(err)
return res.status(400).jsonp({error: err.message})

View File

@ -0,0 +1,59 @@
<template lang="pug">
modal(:show='show', @close='close')
.modal-header
h3 Send Email
.modal-body.aligned-form
.alert.alert-danger(v-if='error') {{ error }}
.form-group
label(for="email") Email
input.form-control(type="email" id="email" name="email" v-model="email")
.form-group
label(for="title") Title
input.form-control(type="text" id="title" name="title" v-model="title")
.form-group
label(for="content") Content
textarea.form-control(type="text" id="content" name="content" v-model="content")
.modal-footer.text-right
button.btn.btn-primary(@click='submit') Done
button.btn.btn-secondary(@click='close') Cancel
</template>
<script type="text/javascript">
import Modal from './Modal.vue'
const csrfToken = document.querySelector('meta[name="csrf-token"]').content
export default {
props: ['show', 'email'],
data: function () {
return {
error: '',
title: '',
content: ''
}
},
components: {
Modal
},
methods: {
close: function () {
this.$emit('close')
this.error = ''
this.title = ''
this.content = ''
},
submit: function () {
this.$http.post('/admin/api/email', {
email: this.email,
title: this.title,
content: this.content,
csrf: csrfToken
}).then(data => {
this.close()
}).catch(err => {
console.error(err)
if (err.body && err.body.error) this.error = err.body.error
})
}
}
}
</script>

View File

@ -40,6 +40,9 @@
.action(v-on:click='resetPassword')
i.fa.fa-fw.fa-envelope
|&nbsp;Password Email
.action(v-on:click='$parent.$emit("email", email)')
i.fa.fa-fw.fa-envelope
|&nbsp;Compose Email
.separator
.action(v-on:click='$parent.$emit("lock", id)' v-if="id != 1 && nw_privilege < 2")
i.fa.fa-fw.fa-lock

View File

@ -10,6 +10,7 @@
ban-modal(:show='banning' @close='banning = 0' :id='banning')
user-modal(:show='editing' @close='editing = 0' :id='editing')
user-lock-modal(:show='locking' @close='locking = 0' :id='locking')
mailer-modal(:show='emailing' @close='emailing = null' :email='emailing')
</template>
<script>
@ -17,6 +18,7 @@
import User from './User.vue'
import BanModal from './BanModal.vue'
import UserModal from './UserModal.vue'
import MailerModal from './MailerModal.vue'
import UserLockModal from './UserLockModal.vue'
import qs from 'querystring'
@ -36,12 +38,13 @@
banning: 0,
editing: 0,
locking: 0,
emailing: null,
search: '',
error: ''
}
},
components: {
Pagination, User, BanModal, UserModal, UserLockModal
Pagination, User, BanModal, UserModal, UserLockModal, MailerModal
},
methods: {
getUsers: function (page) {
@ -91,6 +94,10 @@
this.locking = id
})
this.$on('email', function (email) {
this.emailing = email
})
this.$root.$on('reload_users', () => {
this.getUsers(this.pagination.page)
})