Actual code for processing subscriptions
parent
45a715fad8
commit
74d01a3021
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* ReDonate is more free software. It is licensed under the WTFPL, which
|
||||
* allows you to do pretty much anything with it, without having to
|
||||
* ask permission. Commercial use is allowed, and no attribution is
|
||||
* required. We do politely request that you share your modifications
|
||||
* to benefit other developers, but you are under no enforced
|
||||
* obligation to do so :)
|
||||
*
|
||||
* Please read the accompanying LICENSE document for the full WTFPL
|
||||
* licensing text.
|
||||
*/
|
||||
|
||||
if(!isset($_APP)) { die("Unauthorized."); }
|
||||
|
||||
class LogEntry extends CPHPDatabaseRecordClass
|
||||
{
|
||||
public $table_name = "log_entries";
|
||||
public $fill_query = "SELECT * FROM log_entries WHERE `Id` = :Id";
|
||||
public $verify_query = "SELECT * FROM log_entries WHERE `Id` = :Id";
|
||||
|
||||
public $prototype = array(
|
||||
'string' => array(
|
||||
'Ip' => "Ip",
|
||||
'SessionId' => "SessionId",
|
||||
'Data' => "Data"
|
||||
),
|
||||
'numeric' => array(
|
||||
'Type' => "Type",
|
||||
'CampaignId' => "CampaignId"
|
||||
),
|
||||
'timestamp' => array(
|
||||
'Date' => "Date"
|
||||
),
|
||||
'campaign' => array(
|
||||
'Campaign' => "Campaign"
|
||||
)
|
||||
);
|
||||
|
||||
const PAGELOAD = 1;
|
||||
const SUBSCRIPTION = 2;
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/*
|
||||
* ReDonate is more free software. It is licensed under the WTFPL, which
|
||||
* allows you to do pretty much anything with it, without having to
|
||||
* ask permission. Commercial use is allowed, and no attribution is
|
||||
* required. We do politely request that you share your modifications
|
||||
* to benefit other developers, but you are under no enforced
|
||||
* obligation to do so :)
|
||||
*
|
||||
* Please read the accompanying LICENSE document for the full WTFPL
|
||||
* licensing text.
|
||||
*/
|
||||
|
||||
if(!isset($_APP)) { die("Unauthorized."); }
|
||||
|
||||
class Subscription extends CPHPDatabaseRecordClass
|
||||
{
|
||||
public $table_name = "subscriptions";
|
||||
public $fill_query = "SELECT * FROM subscriptions WHERE `Id` = :Id";
|
||||
public $verify_query = "SELECT * FROM subscriptions WHERE `Id` = :Id";
|
||||
|
||||
public $prototype = array(
|
||||
'string' => array(
|
||||
'EmailAddress' => "EmailAddress",
|
||||
'ConfirmationKey' => "ConfirmationKey",
|
||||
'SettingsKey' => "SettingsKey",
|
||||
'Currency' => "Currency"
|
||||
),
|
||||
'numeric' => array(
|
||||
'CampaignId' => "CampaignId",
|
||||
'Amount' => "Amount"
|
||||
),
|
||||
'timestamp' => array(
|
||||
'SubscriptionDate' => "SubscriptionDate",
|
||||
'UnsubscriptionDate' => "UnsubscriptionDate",
|
||||
'LastEmailDate' => "LastEmail"
|
||||
),
|
||||
'boolean' => array(
|
||||
'IsConfirmed' => "Confirmed"
|
||||
),
|
||||
'campaign' => array(
|
||||
'Campaign' => "Campaign"
|
||||
)
|
||||
);
|
||||
|
||||
public static function FindByEmail($email)
|
||||
{
|
||||
return self::CreateFromQuery("SELECT * FROM subscriptions WHERE `EmailAddress` = :EmailAddress", array(':EmailAddress' => $email), 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/*
|
||||
* ReDonate is more free software. It is licensed under the WTFPL, which
|
||||
* allows you to do pretty much anything with it, without having to
|
||||
* ask permission. Commercial use is allowed, and no attribution is
|
||||
* required. We do politely request that you share your modifications
|
||||
* to benefit other developers, but you are under no enforced
|
||||
* obligation to do so :)
|
||||
*
|
||||
* Please read the accompanying LICENSE document for the full WTFPL
|
||||
* licensing text.
|
||||
*/
|
||||
|
||||
if(!isset($_APP)) { die("Unauthorized."); }
|
||||
|
||||
try
|
||||
{
|
||||
$sCampaign = Campaign::FindByUrlName($router->uParameters[1]);
|
||||
}
|
||||
catch (NotFoundException $e)
|
||||
{
|
||||
$sPageContents = NewTemplater::Render("404", $locale->strings, array());
|
||||
return;
|
||||
}
|
||||
|
||||
if(empty($_POST['email']) || User::CheckIfEmailValid($_POST['email']) == false)
|
||||
{
|
||||
$sError = "Please enter a valid e-mail address.";
|
||||
require("modules/landing.php");
|
||||
return;
|
||||
}
|
||||
|
||||
if(empty($_POST['currency']))
|
||||
{
|
||||
$sError = "Please pick a valid currency.";
|
||||
require("modules/landing.php");
|
||||
return;
|
||||
}
|
||||
|
||||
if(empty($_POST['amount']) || preg_match("([0-9]*[.,][0-9]+|[0-9]+)", $_POST['amount']) == false)
|
||||
{
|
||||
$sError = "Please enter a valid amount.";
|
||||
require("modules/landing.php");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Subscription::FindByEmail($_POST['email']);
|
||||
$exists = true;
|
||||
}
|
||||
catch (NotFoundException $e)
|
||||
{
|
||||
$exists = false;
|
||||
}
|
||||
|
||||
if($exists)
|
||||
{
|
||||
$sPageContents = NewTemplater::Render("subscription/change", $locale->strings, array());
|
||||
/* TODO: Change request */
|
||||
return;
|
||||
}
|
||||
|
||||
$sLogEntry = new LogEntry(0);
|
||||
$sLogEntry->uType = LogEntry::SUBSCRIPTION;
|
||||
$sLogEntry->uIp = $_SERVER['REMOTE_ADDR'];
|
||||
$sLogEntry->uData = json_encode(array("email" => $_POST['email']));
|
||||
$sLogEntry->uCampaignId = $sCampaign->sId;
|
||||
$sLogEntry->uDate = time();
|
||||
$sLogEntry->uSessionId = session_id();
|
||||
$sLogEntry->InsertIntoDatabase();
|
||||
|
||||
$sSubscription = new Subscription(0);
|
||||
$sSubscription->uEmailAddress = $_POST['email'];
|
||||
$sSubscription->uConfirmationKey = random_string(25);
|
||||
$sSubscription->uSettingsKey = random_string(25);
|
||||
$sSubscription->uCurrency = $_POST['currency'];
|
||||
$sSubscription->uAmount = str_replace(",", ".", $_POST['amount']);
|
||||
$sSubscription->uSubscriptionDate = time();
|
||||
$sSubscription->uConfirmed = False;
|
||||
$sSubscription->uCampaignId = $sCampaign->sId;
|
||||
$sSubscription->InsertIntoDatabase();
|
||||
|
||||
$sPageContents = NewTemplater::Render("subscription/success", $locale->strings, array());
|
@ -0,0 +1,11 @@
|
||||
<h2>Hi. We've met before!</h2>
|
||||
<p>
|
||||
You have subscribed to this campaign in the past.
|
||||
</p>
|
||||
<p>
|
||||
<strong>If your intention was to change your settings,</strong> please check the e-mail we just sent you.
|
||||
It contains a verification link that will make the changes you requested, straight away.
|
||||
</p>
|
||||
<p>
|
||||
Thanks for using ReDonate!
|
||||
</p>
|
@ -0,0 +1,9 @@
|
||||
<h2>Great! Only one more step...</h2>
|
||||
<p>
|
||||
We've sent you an e-mail to verify that you really wanted to subscribe - after all, it would
|
||||
be a bad thing if someone else could subscribe you without your consent.
|
||||
</p>
|
||||
<p>
|
||||
Please check the e-mail we've sent you, and click the verification link... and then you're
|
||||
done!
|
||||
</p>
|
Loading…
Reference in New Issue