lots of work around newsletter (un)subscription (via double opt-in)
This commit is contained in:
parent
5bdd09aac9
commit
af2be617cd
25
content/php/confirm.php
Normal file
25
content/php/confirm.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/
|
||||
|
||||
function AddMemberToDB($recipientAddress) {
|
||||
/* global $mailingList, $mgClient;
|
||||
$result = $mgClient->post("lists/$mailingList/members", array(
|
||||
'address' => $recipientAddress,
|
||||
'name' => $recipientName,
|
||||
'description' => 'Form Opt In',
|
||||
'subscribed' => true
|
||||
)); */
|
||||
}
|
||||
|
||||
|
||||
require("settings.php");
|
||||
|
||||
$c = isset($_GET['c']) ? SanitizeInputs($_GET['c']) : NULL;
|
||||
$e = isset($_GET['e']) ? SanitizeInputs($_GET['e']) : NULL;
|
||||
|
||||
if (isset($c) && isset($e) && CheckConfirmationHash($e, $c) && AddMemberToDB($e)) {
|
||||
header('Location: /newsletter/confirmed.html');
|
||||
} else {
|
||||
header('Location: /newsletter/confirm-error.html')
|
||||
}
|
||||
?>
|
||||
18
content/php/contact.php
Normal file
18
content/php/contact.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
//source: https://www.unixdude.net/posts/2017/Nov/29/pelican-contact-form/
|
||||
if(isset($_POST['address']) && $_POST['address'] == ''){
|
||||
//The form was submitted
|
||||
$ouremail = 'kontakt@tobias-radloff.de';
|
||||
// Important: if we add any form fields to the HTML,
|
||||
// and want them included in the email, we will need to add them here also
|
||||
$body = "Diese Nachricht wurde soeben durch das Kontaktformular auf t-r.de übermittelt:
|
||||
Name: $_POST[name]
|
||||
Emailadresse: $_POST[email]
|
||||
Nachricht: $_POST[nachricht]";
|
||||
// From:
|
||||
$headers = "From: $_POST[email]";
|
||||
// send the message
|
||||
mail($ouremail, 'Nachricht ueber das Kontaktformular von t-r.de!', $body, $headers );
|
||||
header('Location: /kontakt/danke/');
|
||||
}
|
||||
?>
|
||||
24
content/php/settings.php
Normal file
24
content/php/settings.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
// inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/
|
||||
|
||||
$domain = 'tobias-radloff.de';
|
||||
$fromAddress = 'newsletter@tobias-radloff.de';
|
||||
$siteURL = 'https://tobias-radloff.de';
|
||||
$uniqueKey = '***REMOVED***'; // works like password salt
|
||||
|
||||
function SanitizeInputs($var) {
|
||||
return = htmlspecialchars($var, ENT_QUOTES);
|
||||
}
|
||||
|
||||
function SanitizeEmail ($var) {
|
||||
$sane = htmlspecialchars($var, ENT_QUOTES);
|
||||
$pattern = "/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/";
|
||||
preg_match($pattern, $sane, $res);
|
||||
$r = $res[0] ? $res[0] : false;
|
||||
return $r;
|
||||
}
|
||||
|
||||
function CheckConfirmationHash($confEmail, $confCode) {
|
||||
return (md5($confEmail . $uniqueKey) === $confCode);
|
||||
}
|
||||
?>
|
||||
37
content/php/subscribe.php
Normal file
37
content/php/subscribe.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/
|
||||
|
||||
function MakeConfirmationHash($confEmail, $confCode) {
|
||||
return md5($confEmail . $confCode);
|
||||
}
|
||||
|
||||
function SendConfirmationEmail($recipientAddress) {
|
||||
global $domain, $fromAddress, $siteURL, $uniqueKey;
|
||||
|
||||
$hashedUnique = MakeConfirmationHash($recipientAddress, $uniqueKey);
|
||||
$confirmURL = $siteURL . '/confirm.php?c=' . $hashedUnique . '&e=' . $recipientAddress
|
||||
|
||||
// FIXME
|
||||
// use PHPMailer?
|
||||
$to = $recipientAddress;
|
||||
$subject = 'Newsletter-Anmeldung bestaetigen';
|
||||
$body = '<p>Hallo! Bitte bestätige die Anmeldung für meinen Newsletter, indem du auf <a href="' . $confirmURL . '">diesen Link</a> klickst. Viel Spaß mit dem Gedicht!</p><p>Bis bald und viele Grüße<br>Tobias';
|
||||
$headers = 'From: newsletter@' . $domain;
|
||||
$result = mail($to, $subject, $body, $headers);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
require("settings.php");
|
||||
|
||||
if (isset($_POST['email'])) {
|
||||
$email = SanitizeEmail(trim($_POST['email']));
|
||||
echo $email; //DEBUG
|
||||
$result = SendConfirmationEmail($email);
|
||||
if $result == TRUE ) {
|
||||
header('Location: /newsletter/subscribed.html');
|
||||
} else {
|
||||
header('Location: /newsletter/subscribe-error.html')
|
||||
}
|
||||
}
|
||||
?>
|
||||
18
content/php/unsubscribe.php
Normal file
18
content/php/unsubscribe.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
function RemoveMemberfromDB($subscriberAddress) {
|
||||
//FIXME
|
||||
}
|
||||
|
||||
require("settings.php");
|
||||
|
||||
$email = isset($_GET['email']) ? SanitizeInputs($_GET['email']) : NULL;
|
||||
if (isset($email)) {
|
||||
$r = RemoveMemberfromDB($email);
|
||||
if ($r) {
|
||||
header('Location: /newsletter/unsubscribed.html');
|
||||
} else {
|
||||
header('Location: /newsletter/unsubscribe-error.html')
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -20,15 +20,21 @@ THEME = "theme/"
|
||||
PATH = "content"
|
||||
ARTICLE_PATHS = ["posts"]
|
||||
PAGE_PATHS = ["pages"]
|
||||
STATIC_PATHS = ["images", "favicon"]
|
||||
STATIC_PATHS = ["images", "favicon", "php"]
|
||||
|
||||
DIRECT_TEMPLATES = ['index', 'tags']
|
||||
IGNORE_FILES = ['**/.*', '__pycache__', 'favicon-from-svg.sh', '*.metadata']
|
||||
|
||||
EXTRA_PATH_METADATA = {
|
||||
'favicon/favicon.ico': {'path': 'favicon.ico'},
|
||||
'php/settings.php': {'path': 'settings.php'},
|
||||
'php/subscribe.php': {'path': 'subscribe.php'},
|
||||
'php/confirm.php': {'path': 'confirm.php'},
|
||||
'php/unsubscribes.php': {'path': 'unsubscribe.php'},
|
||||
'php/contact.php': {'path': 'contact.php'}
|
||||
}
|
||||
|
||||
|
||||
PAGE_URL = '{slug}/'
|
||||
PAGE_SAVE_AS = '{slug}/index.html'
|
||||
ARTICLE_SAVE_AS = '{category}/{slug}.html'
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
Oxygen, Ubuntu, Cantarell, Helvetica, Arial, "Helvetica Neue", sans-serif,
|
||||
var(--pico-font-family-emoji);
|
||||
--card-height: 300px;
|
||||
--smallest-width: 350px;
|
||||
}
|
||||
|
||||
/* don't underline links by default */
|
||||
@ -238,6 +239,22 @@ a {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
/* style newsletter subscription form */
|
||||
.newsletter-form {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
}
|
||||
|
||||
.newsletter-email {
|
||||
flex: 1 0 var(--smallest-width);
|
||||
min-width: var(--smallest-width);
|
||||
}
|
||||
|
||||
.newsletter-submit {
|
||||
flex: 0 1 content;
|
||||
}
|
||||
|
||||
|
||||
/* Main content */
|
||||
#main-header h1,
|
||||
#site-footer p {
|
||||
@ -265,8 +282,8 @@ a {
|
||||
}
|
||||
|
||||
p {
|
||||
flex: 0 1 350px;
|
||||
font-size: 2em;
|
||||
flex: 0 1 var(--smallest-width);
|
||||
font-size: 1.5em;
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,7 +365,7 @@ a {
|
||||
|
||||
.klappentext {
|
||||
flex: 0 0 calc(50% - var(--pico-block-spacing-horizontal));
|
||||
min-width: 350px;
|
||||
min-width: var(--smallest-width);
|
||||
}
|
||||
|
||||
.featured-image {
|
||||
@ -358,7 +375,7 @@ a {
|
||||
|
||||
img {
|
||||
max-height: calc(var(--card-height) * 2);
|
||||
min-width: 350px;
|
||||
min-width: var(--smallest-width);
|
||||
max-width: 100%;
|
||||
aspect-ratio: auto;
|
||||
padding: var(--pico-spacing);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{% extends "page.html" %}
|
||||
{% block content_body %}
|
||||
<form id="contact-form" method="post" action="/theme/static/contact.php">
|
||||
<form id="contact-form" method="post" action="{{ SITEURL }}/contact.php">
|
||||
<fieldset>
|
||||
<label>
|
||||
Name
|
||||
|
||||
8
theme/templates/includes/subscribe.html
Normal file
8
theme/templates/includes/subscribe.html
Normal file
@ -0,0 +1,8 @@
|
||||
<hgroup>
|
||||
<h2>Abonniere meinen Newsletter!</h2>
|
||||
<p>Erfahre zuerst von Neuerscheinungen, Lesungen und allem anderen. Mein Dankeschön: ein unveröffentlichtes Gedicht.</p>
|
||||
</hgroup>
|
||||
<form class="newsletter-form" method="post" action="{{ SITEURL }}/subscribe.php">
|
||||
<input class="newsletter-email" type="email" name="email" placeholder="Emailadresse" autocomplete="email" aria-label="Emailadresse" required/>
|
||||
<input class="newsletter-submit" type="submit" value="Abonnieren" />
|
||||
</form>
|
||||
8
theme/templates/includes/unsubscribe.html
Normal file
8
theme/templates/includes/unsubscribe.html
Normal file
@ -0,0 +1,8 @@
|
||||
<hgroup>
|
||||
<h2>Newsletter-Abmeldung</h2>
|
||||
<p>Komm bald wiederm okay?</p>
|
||||
</hgroup>
|
||||
<form class="newsletter-form" method="get" action="{{ SITEURL }}/unsubscribe.php">
|
||||
<input class="newsletter-email" type="email" name="email" placeholder="Emailadresse" autocomplete="email" aria-label="Emailadresse" required/>
|
||||
<input class="newsletter-submit" type="submit" value="Abonnieren" />
|
||||
</form>
|
||||
Loading…
Reference in New Issue
Block a user