subscribe for newsletter, opt in email and confirmation
This commit is contained in:
parent
e71ecf8586
commit
50f672b207
@ -6,7 +6,8 @@ class api_democracy extends \SYSTEM\API\api_system {
|
||||
|
||||
$mail = new PHPMailer;
|
||||
|
||||
$mail->CharSet = 'utf-8';
|
||||
$mail->CharSet = 'utf-8';
|
||||
$mail->Encoding = 'base64';
|
||||
|
||||
$mail->Host = 'atmanspacher.eu';
|
||||
$mail->Port = 465;
|
||||
@ -31,4 +32,66 @@ class api_democracy extends \SYSTEM\API\api_system {
|
||||
throw new \SYSTEM\LOG\ERROR("Mailer Error: " . $mail->ErrorInfo);}
|
||||
return \SYSTEM\LOG\JsonResult::ok();
|
||||
}
|
||||
|
||||
public static function call_send_subscribe($data){
|
||||
$beta = $data['beta'] == 'true' ? 1 : 0;
|
||||
$android = $data['android'] == 'true' ? 1 : 0;
|
||||
$ios = $data['ios'] == 'true' ? 1 : 0;
|
||||
\SQL\SUBSCRIBE_ADD::Q1(array($data['email'],$beta,$android,$ios,$beta,$android,$ios));
|
||||
|
||||
$sub = \SQL\SUBSCRIBE_GET::Q1(array($data['email']));
|
||||
if(!$sub['confirmed']){
|
||||
self::send_subscribe_mail($data['email']);}
|
||||
|
||||
return \SYSTEM\LOG\JsonResult::ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see http://www.jwz.org/doc/mid.html
|
||||
*/
|
||||
public static function generateMessageID()
|
||||
{
|
||||
return sprintf(
|
||||
"<%s.%s@%s>",
|
||||
base_convert(microtime(), 10, 36),
|
||||
base_convert(bin2hex(openssl_random_pseudo_bytes(8)), 16, 36),
|
||||
"democracy-deutschland.de"
|
||||
);
|
||||
}
|
||||
|
||||
private static function send_subscribe_mail($email){
|
||||
require((new \SYSTEM\PROOT('PHPMailer-master/PHPMailerAutoload.php'))->SERVERPATH());
|
||||
date_default_timezone_set('Europe/Berlin');
|
||||
|
||||
$mail = new PHPMailer;
|
||||
|
||||
$mail->CharSet = 'utf-8';
|
||||
|
||||
$mail->Host = 'atmanspacher.eu';
|
||||
$mail->Port = 465;
|
||||
$mail->SMTPSecure = 'tls';
|
||||
$mail->SMTPAuth = true;
|
||||
|
||||
$mail->setFrom( 'contact@democracy-deutschland.de', 'DEMOCRACY Deutschland e.V.');
|
||||
$mail->addReplyTo( 'contact@democracy-deutschland.de', 'DEMOCRACY Deutschland e.V.');
|
||||
$mail->addAddress( $email);
|
||||
|
||||
$mail->addCustomHeader('Return-Path', 'contact@democracy-deutschland.de');
|
||||
$mail->addCustomHeader('Message-ID', self::generateMessageID());
|
||||
$mail->addCustomHeader('Date', date('r', time()));
|
||||
|
||||
$token = \SYSTEM\TOKEN\token::request('token_confirm_subscribe', array('email' => $email));
|
||||
|
||||
$html = \SYSTEM\PAGE\replace::replaceFile((new PAPI('tpl/send_mail_subscribe.tpl'))->SERVERPATH(), array('token' => $token));
|
||||
|
||||
$mail->Subject = '📱 DEMOCRACY: Bitte bestätige Deine Newsletter-Anmeldung';
|
||||
$mail->Body = $html;
|
||||
$mail->IsHTML(true);
|
||||
|
||||
//send the message, check for errors
|
||||
if(!$mail->send()){
|
||||
throw new \SYSTEM\LOG\ERROR("Mailer Error: " . $mail->ErrorInfo);}
|
||||
|
||||
\SQL\SUBSCRIBE_EMAIL_COUNT::Q1(array($email));
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,5 @@
|
||||
<?php
|
||||
SYSTEM\autoload::registerFolder(dirname(__FILE__),'');
|
||||
//SYSTEM\autoload::registerFolder(dirname(__FILE__).'/elements','');
|
||||
SYSTEM\autoload::registerFolder(dirname(__FILE__));
|
||||
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/sql/','SQL');
|
||||
|
||||
\SYSTEM\TOKEN\token::register('token_confirm_subscribe');
|
||||
10
democracy/api/sql/SUBSCRIBE_ADD.php
Normal file
10
democracy/api/sql/SUBSCRIBE_ADD.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace SQL;
|
||||
|
||||
class SUBSCRIBE_ADD extends \SYSTEM\DB\QP {
|
||||
public static function get_class(){return \get_class();}
|
||||
public static function mysql(){return
|
||||
'INSERT INTO subscribe (`email`, `beta`, `android`, `ios`) VALUES (?, ?, ?, ?)'.
|
||||
' ON DUPLICATE KEY UPDATE beta=?, android=?, ios=?;';
|
||||
}
|
||||
}
|
||||
9
democracy/api/sql/SUBSCRIBE_CONFIRM_EMAIL.php
Normal file
9
democracy/api/sql/SUBSCRIBE_CONFIRM_EMAIL.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace SQL;
|
||||
|
||||
class SUBSCRIBE_CONFIRM_EMAIL extends \SYSTEM\DB\QP {
|
||||
public static function get_class(){return \get_class();}
|
||||
public static function mysql(){return
|
||||
'UPDATE subscribe SET confirmed = 1 WHERE email = ?';
|
||||
}
|
||||
}
|
||||
9
democracy/api/sql/SUBSCRIBE_EMAIL_COUNT.php
Normal file
9
democracy/api/sql/SUBSCRIBE_EMAIL_COUNT.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace SQL;
|
||||
|
||||
class SUBSCRIBE_EMAIL_COUNT extends \SYSTEM\DB\QP {
|
||||
public static function get_class(){return \get_class();}
|
||||
public static function mysql(){return
|
||||
'UPDATE subscribe SET emails_sent = emails_sent+1 WHERE email = ?';
|
||||
}
|
||||
}
|
||||
9
democracy/api/sql/SUBSCRIBE_GET.php
Normal file
9
democracy/api/sql/SUBSCRIBE_GET.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace SQL;
|
||||
|
||||
class SUBSCRIBE_GET extends \SYSTEM\DB\QP {
|
||||
public static function get_class(){return \get_class();}
|
||||
public static function mysql(){return
|
||||
'SELECT * FROM subscribe WHERE `email` = ?;';
|
||||
}
|
||||
}
|
||||
48
democracy/api/token_confirm_subscribe.php
Normal file
48
democracy/api/token_confirm_subscribe.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
class token_confirm_subscribe implements \SYSTEM\TOKEN\token_handler{
|
||||
/**
|
||||
* Generate the Token
|
||||
*
|
||||
* @return string Returns token string.
|
||||
*/
|
||||
public static function token(){
|
||||
return sha1(time().rand(0, 1000));}
|
||||
|
||||
/**
|
||||
* Expiredate when the Token expires (3d)
|
||||
*
|
||||
* @return int Returns unixtimestamp when the token expires.
|
||||
*/
|
||||
public static function expire(){
|
||||
return time() + (60 * 60 * 24 * 3);}
|
||||
|
||||
/**
|
||||
* Token confirm processing for the token_handler.
|
||||
* Confirms Email of a subscription if successful
|
||||
*
|
||||
* @param array Token data from db
|
||||
* @return bool Returns true or false.
|
||||
*/
|
||||
public static function confirm($token_data){
|
||||
$data = \json_decode($token_data['data'],true);
|
||||
return \SQL\SUBSCRIBE_CONFIRM_EMAIL::QI(array($data['email'])) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback text_fail on fail
|
||||
*
|
||||
* @param array $token_data Token Data
|
||||
* @return string Returns token fail string.
|
||||
*/
|
||||
public static function text_fail($token_data) {
|
||||
return 'Could NOT confirm your EMail Address. Token is expired or invalid.';}
|
||||
|
||||
/**
|
||||
* Callback text_success on success
|
||||
*
|
||||
* @param array $token_data Token Data
|
||||
* @return string Returns token success string.
|
||||
*/
|
||||
public static function text_success($token_data) {
|
||||
return 'Confirmed your EMail Address.';}
|
||||
}
|
||||
7
democracy/api/tpl/send_mail_subscribe.tpl
Normal file
7
democracy/api/tpl/send_mail_subscribe.tpl
Normal file
@ -0,0 +1,7 @@
|
||||
Hallo liebe/r Interessierte/r,<br>
|
||||
<br>
|
||||
Bitte bestätige den Erhalt von unserem Newsletter indem du folgenden Link klickst:<br>
|
||||
<br><a href="https://test.democracy-deutschland.de/api.php?call=account&action=confirm&token=${token}">https://test.democracy-deutschland.de/api.php?call=account&action=confirm&token=${token}</a>
|
||||
<br>
|
||||
Herzliche Grüße<br>
|
||||
Team DEMOCRACY
|
||||
@ -831,7 +831,7 @@ i.fa.fa-quote-right {
|
||||
}
|
||||
|
||||
.agileinfo-social-grids {
|
||||
margin:1em 0 0 -10px;
|
||||
margin:1em 0 0 -7px;
|
||||
}
|
||||
|
||||
.agileinfo-social-grids ul {
|
||||
|
||||
@ -18,4 +18,64 @@ $(document).ready(function() {
|
||||
$('.navbar-nav>li>a').on('click', function(){
|
||||
$('.navbar-collapse').collapse('hide');
|
||||
});
|
||||
});
|
||||
|
||||
$('#beta').change(function(){
|
||||
$('#plattform').toggle();
|
||||
});
|
||||
|
||||
$('#subscribe').click(function(){
|
||||
var ok = true;
|
||||
var email = $('#email').val();
|
||||
var beta = $('#beta').is(':checked');
|
||||
var android = $('#android').is(':checked');
|
||||
var ios = $('#ios').is(':checked');
|
||||
|
||||
if(!validateEmail(email)){
|
||||
$('#email').addClass("blink-class");
|
||||
ok = false;
|
||||
} else {
|
||||
$('#email').removeClass("blink-class");
|
||||
}
|
||||
|
||||
if(beta && (!android && !ios)){
|
||||
$('#android').addClass("blink-class");
|
||||
$('#ios').addClass("blink-class");
|
||||
ok = false;
|
||||
} else {
|
||||
$('#android').removeClass("blink-class");
|
||||
$('#ios').removeClass("blink-class");
|
||||
}
|
||||
|
||||
if(ok){
|
||||
$.ajax({
|
||||
async: true,
|
||||
url: './api.php',
|
||||
type: 'GET',
|
||||
dataType: 'JSON',
|
||||
data: {
|
||||
call: 'send_subscribe',
|
||||
data: { email: email,
|
||||
beta: beta,
|
||||
android:android,
|
||||
ios: ios}
|
||||
},
|
||||
success: function(data){
|
||||
if(!data.status){
|
||||
alert("Das Eintragen in den Newsletter hat leider nicht funktioniert. Bitte versuche es später noch einmal. Danke.");
|
||||
} else {
|
||||
$('#confirm').show();
|
||||
$('#formular').hide();
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
alert("Das Eintragen in den Newsletter hat leider nicht funktioniert. Bitte versuche es später noch einmal. Danke.");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function validateEmail(email) {
|
||||
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
return re.test(String(email).toLowerCase());
|
||||
}
|
||||
@ -138,6 +138,48 @@
|
||||
<li><a href="https://discord.gg/Pdu3ZEV" target="_blank"><i id="discord_" class="insta_ fa fa-weixin"></i></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<br>
|
||||
<style>
|
||||
.mailjet-subscribe:hover {
|
||||
cursor: pointer;
|
||||
background: #96c346;
|
||||
}
|
||||
.mailjet-subscribe {
|
||||
padding: 7px 10px 7px 10px;
|
||||
font-size: 15px;
|
||||
line-height: normal;
|
||||
background: #a0ce4e;
|
||||
margin-top: 3px;
|
||||
color: #fff;
|
||||
border: none;
|
||||
outline: 0;
|
||||
font-family: "Source Sans Pro", Arial, Helvetica, sans-serif;
|
||||
}
|
||||
.blink-class { outline: 1px solid #ee1b1b !important;}
|
||||
</style>
|
||||
<div style="width:230px;">
|
||||
<div id="formular">
|
||||
<input id="email" name="email" type="text" placeholder="News an deine@email.com" style="width: 100%; margin-bottom: 5px;">
|
||||
<div style="height: 50px;">
|
||||
<input id="subscribe" name="submit" type="submit" class="mailjet-subscribe" value="EINTRAGEN" style="float: left;">
|
||||
<span style="color: white; float: right; padding-top: 7px; padding-right: 15px;">
|
||||
<!--<input type="checkbox" name="newsletter" checked disabled> Newsletter<br>-->
|
||||
<input type="checkbox" name="beta" id="beta"> Beta-Test
|
||||
<div style="color: white; padding-left: 13px; display: none;" id="plattform">
|
||||
<input type="checkbox" name="android" id="android"> Android<br>
|
||||
<input type="checkbox" name="ios" id="ios"> iOS
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div style="color:white; display: none;" id="confirm">
|
||||
Bestätigungsmail für die<br>
|
||||
Anmeldung wurde gesendet.<br>
|
||||
Bitte überprüfen Sie Ihren<br>
|
||||
Posteingang und bestätigen<br>
|
||||
Sie die Anmeldung.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3 agileinfo_footer_grid">
|
||||
|
||||
@ -3,7 +3,8 @@ namespace SQL;
|
||||
class DATA_DEMOCRACY extends \SYSTEM\DB\QI {
|
||||
public static function get_class(){return \get_class();}
|
||||
public static function files_mysql(){
|
||||
return array( (new \PSQL('/mysql/system_page.sql'))->SERVERPATH(),
|
||||
return array( (new \PSQL('/mysql/schema_subscribe.sql'))->SERVERPATH(),
|
||||
(new \PSQL('/mysql/system_page.sql'))->SERVERPATH(),
|
||||
(new \PSQL('/mysql/system_text.sql'))->SERVERPATH(),
|
||||
(new \PSQL('/mysql/system_api.sql'))->SERVERPATH());
|
||||
}
|
||||
|
||||
9
democracy/sql/mysql/schema_subscribe.sql
Normal file
9
democracy/sql/mysql/schema_subscribe.sql
Normal file
@ -0,0 +1,9 @@
|
||||
CREATE TABLE `subscribe` (
|
||||
`email` VARCHAR(255) NOT NULL ,
|
||||
`beta` INT NULL DEFAULT NULL ,
|
||||
`android` INT NULL DEFAULT NULL ,
|
||||
`ios` INT NULL DEFAULT NULL ,
|
||||
`confirmed` INT NULL DEFAULT NULL ,
|
||||
`emails_sent` INT UNSIGNED NOT NULL DEFAULT '0' ,
|
||||
PRIMARY KEY (`email`)
|
||||
) ENGINE = InnoDB;
|
||||
@ -1 +1,2 @@
|
||||
REPLACE INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (100, 0, 2, 10, 'send_mail_faq', 'data', 'JSON');
|
||||
REPLACE INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (100, 0, 2, 10, 'send_mail_faq', 'data', 'JSON');
|
||||
REPLACE INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (110, 0, 2, 10, 'send_subscribe', 'data', 'JSON');
|
||||
Reference in New Issue
Block a user