diff --git a/public_html/classes/logentry.php b/public_html/classes/logentry.php new file mode 100644 index 0000000..9ac2d1e --- /dev/null +++ b/public_html/classes/logentry.php @@ -0,0 +1,42 @@ + 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; +} diff --git a/public_html/classes/subscription.php b/public_html/classes/subscription.php new file mode 100644 index 0000000..bee81eb --- /dev/null +++ b/public_html/classes/subscription.php @@ -0,0 +1,50 @@ + 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); + } +} diff --git a/public_html/modules/landing.php b/public_html/modules/landing.php index 7559b53..d4eaf30 100644 --- a/public_html/modules/landing.php +++ b/public_html/modules/landing.php @@ -16,11 +16,26 @@ if(!isset($_APP)) { die("Unauthorized."); } try { $sCampaign = Campaign::FindByUrlName($router->uParameters[1]); - - $sPageTitle = "Contribute to {$sCampaign->sName}"; - $sPageContents = NewTemplater::Render("landing", $locale->strings, array("can-donate-once" => true, "project-name" => $sCampaign->sName)); } catch (NotFoundException $e) { $sPageContents = NewTemplater::Render("404", $locale->strings, array()); + return; } + +$sLogEntry = new LogEntry(0); +$sLogEntry->uType = LogEntry::PAGELOAD; +$sLogEntry->uIp = $_SERVER['REMOTE_ADDR']; +$sLogEntry->uData = json_encode(array()); +$sLogEntry->uCampaignId = $sCampaign->sId; +$sLogEntry->uDate = time(); +$sLogEntry->uSessionId = session_id(); +$sLogEntry->InsertIntoDatabase(); + +$sPageTitle = "Contribute to {$sCampaign->sName}"; +$sPageContents = NewTemplater::Render("landing", $locale->strings, array( + "can-donate-once" => true, + "project-name" => $sCampaign->sName, + "urlname" => $sCampaign->sUrlName, + "error" => $sError +)); diff --git a/public_html/modules/subscribe.php b/public_html/modules/subscribe.php new file mode 100644 index 0000000..0c711ec --- /dev/null +++ b/public_html/modules/subscribe.php @@ -0,0 +1,84 @@ +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()); diff --git a/public_html/rewrite.php b/public_html/rewrite.php index a2e8f62..3403272 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -26,6 +26,7 @@ function __autoload($class_name) $sPageTitle = ""; $sPageContents = ""; +$sError = ""; $router = new CPHPRouter(); $router->allow_slash = true; @@ -34,10 +35,10 @@ $router->ignore_query = true; $router->routes = array( 0 => array( "^/$" => "modules/index.php", - "^/register/$" => "modules/register.php", - "^/login/$" => "modules/login.php", - "^/campaign/([a-zA-Z0-9-]+)" => "modules/landing.php", - "^/campaign/([a-zA-Z0-9-]+)/subscribe" => "modules/subscribe.php", + "^/register$" => "modules/register.php", + "^/login$" => "modules/login.php", + "^/campaign/([a-zA-Z0-9-]+)$" => "modules/landing.php", + "^/campaign/([a-zA-Z0-9-]+)/subscribe$" => "modules/subscribe.php", ) ); diff --git a/public_html/static/css/style.css b/public_html/static/css/style.css index bc96242..6a8752d 100644 --- a/public_html/static/css/style.css +++ b/public_html/static/css/style.css @@ -170,6 +170,12 @@ body font-size: 18px; } +p.error +{ + font-weight: bold; + color: #C50003; +} + /* Form */ #field_currency diff --git a/public_html/templates/landing.tpl b/public_html/templates/landing.tpl index 5779787..e65b06b 100644 --- a/public_html/templates/landing.tpl +++ b/public_html/templates/landing.tpl @@ -28,23 +28,30 @@
- My e-mail address is... - -
-- ... and I'd like to pledge - - - a month. -
- + {%if isempty|error == false} ++ {%?error} +
+ {%/if} + {%if can-donate-once == true}+ You have subscribed to this campaign in the past. +
++ If your intention was to change your settings, please check the e-mail we just sent you. + It contains a verification link that will make the changes you requested, straight away. +
++ Thanks for using ReDonate! +
diff --git a/public_html/templates/subscription/success.tpl b/public_html/templates/subscription/success.tpl new file mode 100644 index 0000000..cceb96c --- /dev/null +++ b/public_html/templates/subscription/success.tpl @@ -0,0 +1,9 @@ ++ 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. +
++ Please check the e-mail we've sent you, and click the verification link... and then you're + done! +