mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 13:24:24 +00:00
newsletter plugin done
This commit is contained in:
@@ -0,0 +1,74 @@
|
|||||||
|
body {
|
||||||
|
font-family: sans-serif;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
background-color: rgb(180, 191, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-symbols-outlined {
|
||||||
|
font-variation-settings:
|
||||||
|
'FILL' 0,
|
||||||
|
'wght' 400,
|
||||||
|
'GRAD' 0,
|
||||||
|
'opsz' 48
|
||||||
|
}
|
||||||
|
|
||||||
|
.mail-app {
|
||||||
|
width: 80%;
|
||||||
|
margin-left: 5%;
|
||||||
|
margin-top: 1%;
|
||||||
|
background-color: rgb(144, 160, 255);
|
||||||
|
border-radius: 50px;
|
||||||
|
padding: 5%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#toolbar, #editor {
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
#top-bar {
|
||||||
|
color: white;
|
||||||
|
background-color: rgb(0, 8, 53);
|
||||||
|
margin-bottom: 0;
|
||||||
|
grid-area: header;
|
||||||
|
height: 10vh;
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
#title {
|
||||||
|
font-size: 120%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#spacer {
|
||||||
|
width: 10%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-toolbar {
|
||||||
|
display: inline-flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
margin-right: 10%;
|
||||||
|
gap: 10%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-buttons {
|
||||||
|
background-color: rgba(0, 0, 0, 0);
|
||||||
|
color: white;
|
||||||
|
border-radius: 5px;
|
||||||
|
border-color: white;
|
||||||
|
border-style: solid;
|
||||||
|
padding: 0.5%;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-buttons:hover {
|
||||||
|
color: blue;
|
||||||
|
border-color: blue;
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
<!-- Include Quill stylesheet -->
|
<!-- Include Quill stylesheet -->
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>New Mail :: Webmail | Language School Hossegor - Admin</title>
|
<title>New Mail :: Webmail | Language School Hossegor - Admin</title>
|
||||||
<link rel="stylesheet" href="/admin/css/webmail-compose.css">
|
<link rel="stylesheet" href="/admin/plugins/newsletter/css/mailCompose.css">
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
|
||||||
<link href="https://cdn.quilljs.com/1.0.0/quill.snow.css" rel="stylesheet" />
|
<link href="https://cdn.quilljs.com/1.0.0/quill.snow.css" rel="stylesheet" />
|
||||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200">
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200">
|
||||||
@@ -12,36 +12,14 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="top-bar">
|
<div id="top-bar">
|
||||||
<div class="top-toolbar">
|
<div class="top-toolbar">
|
||||||
<a href="/admin/panel" title="Back to admin panel" id="back" class="top-buttons"><span class="material-symbols-outlined">arrow_back</span></a>
|
<a href="/admin/plugins" title="Back to admin panel" id="back" class="top-buttons"><span class="material-symbols-outlined">arrow_back</span></a>
|
||||||
<a href="/admin/mail" title="Back to webmail" id="new" class="top-buttons"><span class="material-symbols-outlined">arrow_back_ios_new</span></a>
|
|
||||||
</div>
|
</div>
|
||||||
<p id="title">Webmail - Language School Hossegor</p>
|
<p id="title">Newsletter plugin - libreevent</p>
|
||||||
<p id="spacer"></p>
|
<p id="spacer"></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="mail-app">
|
<div class="mail-app">
|
||||||
<h1>New message</h1>
|
<h1>New newsletter</h1>
|
||||||
<p>All mails written here can get one of four different styles. Please choose your style in the dropdown below. You can preview them by clicking <a href="/admin/mail/preview" target="_blank">here</a></p>
|
|
||||||
<p>If you select "Newsletter", the mail will automatically be sent to everybody that subscribed to the newsletter with the correct styling. Note that you need to create a newsletter in German and English and send them separately</p>
|
|
||||||
<select id="mailTypeSelector" onchange="updateType()" title="Mail template">
|
|
||||||
<option value="default">Default</option>
|
|
||||||
<option value="booking">Booking</option>
|
|
||||||
<option value="newsletter">Newsletter</option>
|
|
||||||
<option value="plain">Plain text</option>
|
|
||||||
</select>
|
|
||||||
<select id="mailLangSelector" title="Language">
|
|
||||||
<option value="de">Deutsch</option>
|
|
||||||
<option value="en">English</option>
|
|
||||||
</select>
|
|
||||||
<!--<button onclick="getContent()">Get html</button>--><br>
|
|
||||||
<table>
|
<table>
|
||||||
<tr id="to">
|
|
||||||
<td>
|
|
||||||
<label for="mail">To: </label>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input type="email" name="mail" id="mail"><br>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<label for="subject">Subject:</label>
|
<label for="subject">Subject:</label>
|
||||||
@@ -104,77 +82,38 @@
|
|||||||
|
|
||||||
<!-- Initialize Quill editor -->
|
<!-- Initialize Quill editor -->
|
||||||
<script>
|
<script>
|
||||||
var editor = new Quill('#editor', {
|
var editor = new Quill( '#editor', {
|
||||||
modules: { toolbar: '#toolbar' },
|
modules: { toolbar: '#toolbar' },
|
||||||
theme: 'snow',
|
theme: 'snow',
|
||||||
});
|
} );
|
||||||
function getContent () {
|
|
||||||
console.log( document.getElementsByClassName( 'ql-editor' )[0].innerHTML );
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout( updateType, 200 );
|
|
||||||
|
|
||||||
function updateType () {
|
|
||||||
if ( document.getElementById( 'mailTypeSelector' ).value === 'newsletter' ) {
|
|
||||||
$( '#to' ).slideUp();
|
|
||||||
$( '#mailLangSelector' ).slideDown();
|
|
||||||
} else {
|
|
||||||
$( '#to' ).slideDown();
|
|
||||||
$( '#mailLangSelector' ).slideUp();
|
|
||||||
};
|
|
||||||
if ( window.location.search.slice( 1, 8 ) === 'replyTo' ) {
|
|
||||||
document.getElementById( 'subject' ).value = 'Re: ' + sessionStorage.getItem( 'mailSubject' );
|
|
||||||
document.getElementById( 'mail' ).value = sessionStorage.getItem( 'mailAddress' );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function sendMail () {
|
function sendMail () {
|
||||||
let ok = false;
|
if ( !document.getElementById( 'subject' ).value ) {
|
||||||
if ( document.getElementById( 'mailTypeSelector' ).value !== 'newsletter' ) {
|
alert( 'An email subject is required!' );
|
||||||
if ( document.getElementById( 'mail' ).value != '' && document.getElementById( 'subject' ).value != '' ) {
|
return;
|
||||||
ok = true;
|
}
|
||||||
} else {
|
let dat = { 'subject': document.getElementById( 'subject' ).value, 'message': document.getElementsByClassName( 'ql-editor' )[0].innerHTML };
|
||||||
alert( 'A mail address and a subject are required!' );
|
let options = {
|
||||||
};
|
method: 'post',
|
||||||
} else {
|
body: JSON.stringify( dat ),
|
||||||
if ( document.getElementById( 'subject' ).value != '' ) {
|
headers: {
|
||||||
if ( confirm( 'Do you really want to send the newsletter?' ) ) {
|
'Content-Type': 'application/json',
|
||||||
ok = true;
|
'charset': 'utf-8'
|
||||||
};
|
},
|
||||||
} else {
|
|
||||||
alert( 'A subject is required!' );
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
if ( ok ) {
|
fetch( '/admin/plugins/newsletter/send', options ).then( res => {
|
||||||
let dat = { 'receiver': document.getElementById( 'mail' ).value, 'subject': document.getElementById( 'subject' ).value, 'mode': document.getElementById( 'mailTypeSelector' ).value, 'lang': document.getElementById( 'mailLangSelector' ).value };
|
if ( res.status === 200 ) {
|
||||||
dat[ 'message' ] = document.getElementsByClassName( 'ql-editor' )[0].innerHTML;
|
alert( 'Newsletter sent successfully' );
|
||||||
if ( window.location.search.slice( 1, 8 ) === 'replyTo' ) {
|
} else if ( res.status === 403 ) {
|
||||||
dat[ 'inReplyTo' ] = sessionStorage.getItem( 'replyTo' );
|
alert( 'It appears that you have been logged out or have logged out somewhere else. Please ensure that you are logged in and try again!' );
|
||||||
sessionStorage.removeItem( 'replyTo' );
|
} else {
|
||||||
sessionStorage.removeItem( 'mailSubject' );
|
alert( 'There was an error sending the mail. Please try again. If the error persists, please contact the developer and tell this status code: ' + res.status );
|
||||||
sessionStorage.removeItem( 'mailAddress' );
|
}
|
||||||
window.location = '/admin/mail/compose';
|
} );
|
||||||
};
|
document.getElementById( 'subject' ).value = '';
|
||||||
let options = {
|
document.getElementById( 'mail' ).value = '';
|
||||||
method: 'post',
|
document.getElementsByClassName( 'ql-editor' )[0].innerHTML = '';
|
||||||
body: JSON.stringify( dat ),
|
};
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'charset': 'utf-8'
|
|
||||||
},
|
|
||||||
};
|
|
||||||
fetch( '/admin/mail/send', options ).then( res => {
|
|
||||||
if ( res.status === 200 ) {
|
|
||||||
alert( 'Mail sent successfully' );
|
|
||||||
} else {
|
|
||||||
alert( 'There was an error sending the mail. Please try again. If the error persists, please contact the developer and tell this status code: ' + res.status );
|
|
||||||
};
|
|
||||||
} );
|
|
||||||
document.getElementById( 'subject' ).value = '';
|
|
||||||
document.getElementById( 'mail' ).value = '';
|
|
||||||
document.getElementsByClassName( 'ql-editor' )[0].innerHTML = '';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -8,11 +8,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const path = require( 'path' );
|
const path = require( 'path' );
|
||||||
const mm = require( '../../../mail/mailSender.js' );
|
const mm = require( './sender.js' );
|
||||||
const sendMail = new mm();
|
const bodyParser = require( 'body-parser' );
|
||||||
|
|
||||||
module.exports = ( app ) => {
|
module.exports = ( app, settings ) => {
|
||||||
app.get( '/admin/mail/compose', ( request, response ) => {
|
const sendMail = new mm( settings );
|
||||||
|
app.get( '/admin/plugins/newsletter', ( request, response ) => {
|
||||||
if ( request.session.loggedInAdmin ) {
|
if ( request.session.loggedInAdmin ) {
|
||||||
response.sendFile( path.join( __dirname + '/html/compose.html' ) );
|
response.sendFile( path.join( __dirname + '/html/compose.html' ) );
|
||||||
} else {
|
} else {
|
||||||
@@ -20,10 +21,14 @@ module.exports = ( app ) => {
|
|||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
app.post( '/admin/mail/send', ( request, response ) => {
|
app.get( '/admin/plugins/newsletter/css/:file', ( req, res ) => {
|
||||||
|
res.sendFile( path.join( __dirname + '/css/' + req.params.file ) );
|
||||||
|
} );
|
||||||
|
|
||||||
|
app.post( '/admin/plugins/newsletter/send', bodyParser.json(), ( request, response ) => {
|
||||||
if ( request.session.loggedInAdmin ) {
|
if ( request.session.loggedInAdmin ) {
|
||||||
response.send( 'ok' );
|
response.send( 'ok' );
|
||||||
sendMail.send( request.body.message, request.body.subject, request.body.mode, request.body.replyTo, request.body.receiver, request.body.lang );
|
sendMail.send( request.body.message, request.body.subject );
|
||||||
} else {
|
} else {
|
||||||
response.status( 403 ).send( 'unauthenticated' );
|
response.status( 403 ).send( 'unauthenticated' );
|
||||||
}
|
}
|
||||||
@@ -34,7 +39,7 @@ module.exports = ( app ) => {
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
app.post( '/mail/unsubscribe/go', ( request, response ) => {
|
app.post( '/mail/unsubscribe/go', ( request, response ) => {
|
||||||
if ( request.body.mail == '' ) {
|
if ( !request.body.mail ) {
|
||||||
response.sendFile( path.join( __dirname + '/html/unsubscribeError.html' ) );
|
response.sendFile( path.join( __dirname + '/html/unsubscribeError.html' ) );
|
||||||
} else {
|
} else {
|
||||||
sendMail.unsubscribe( request.body.mail );
|
sendMail.unsubscribe( request.body.mail );
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* libreevent - sender.js
|
||||||
|
*
|
||||||
|
* Created by Janis Hutz 09/16/2023, Licensed under the GPL V3 License
|
||||||
|
* https://janishutz.com, development@janishutz.com
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
const mm = require( '../../../mail/mailSender.js' );
|
||||||
|
const mailManager = new mm();
|
||||||
|
const db = require( '../../../db/db.js' );
|
||||||
|
|
||||||
|
|
||||||
|
class sendMail {
|
||||||
|
constructor( settings ) {
|
||||||
|
this.settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
send ( message, subject ) {
|
||||||
|
db.getDataSimple( 'users', 'marketing', 'true' ).then( users => {
|
||||||
|
for ( let user in users ) {
|
||||||
|
mailManager.sendMail( users[ user ].email, message, subject, this.settings.mailSender );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
unsubscribe ( mail ) {
|
||||||
|
db.writeDataSimple( 'users', 'email', mail, { 'marketing': false } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = sendMail;
|
||||||
Reference in New Issue
Block a user