diff --git a/public_html/authenticators/change.php b/public_html/authenticators/change.php new file mode 100644 index 0000000..c8c0cf7 --- /dev/null +++ b/public_html/authenticators/change.php @@ -0,0 +1,40 @@ +uParameters[2]); +} +catch (NotFoundException $e) +{ + throw new RouterException("No such change request exists."); +} + +if($sChangeRequest->sSubscription->uEmailAddress != $router->uParameters[1]) +{ + throw new RouterException("The given e-mail address does not match the e-mail address for this change request."); +} + +if($sChangeRequest->uKey != $router->uParameters[3]) +{ + throw new RouterException("The given key does not match the key for this change request."); +} + +if($sChangeRequest->sIsConfirmed === true) +{ + throw new RouterException("The change request was already fulfilled."); +} + +$sRouterAuthenticated = true; diff --git a/public_html/classes/changerequest.php b/public_html/classes/changerequest.php new file mode 100644 index 0000000..625528b --- /dev/null +++ b/public_html/classes/changerequest.php @@ -0,0 +1,72 @@ + array( + 'OldCurrency' => "OldCurrency", + 'NewCurrency' => "NewCurrency", + 'Key' => "Key" + ), + 'numeric' => array( + 'SubscriptionId' => "SubscriptionId", + 'CampaignId' => "CampaignId", + 'OldAmount' => "OldAmount", + 'NewAmount' => "NewAmount" + ), + 'boolean' => array( + 'IsConfirmed' => "Confirmed" + ), + 'timestamp' => array( + 'Date' => "Date" + ), + 'campaign' => array( + 'Campaign' => "CampaignId" + ), + 'subscription' => array( + 'Subscription' => "SubscriptionId" + ) + ); + + public function GenerateEmail() + { + global $locale; + + $sText = NewTemplater::Render("email/change.txt", $locale->strings, array( + "campaign-name" => $this->sCampaign->sName, + "confirmation-url" => "http://redonate.net/change/{$this->sSubscription->sEmailAddress}/{$this->sId}/{$this->sKey}", + "unsubscribe-url" => "http://redonate.com/manage/{$this->sSubscription->sEmailAddress}/{$this->sSubscription->sSettingsKey}", + "old" => Currency::Format($this->sOldCurrency, $this->sOldAmount), + "new" => Currency::Format($this->sNewCurrency, $this->sNewAmount) + )); + + $sHtml = NewTemplater::Render("email/layout.html", $locale->strings, array( + "contents" => NewTemplater::Render("email/change.html", $locale->strings, array( + "campaign-name" => $this->sCampaign->sName, + "confirmation-url" => "http://redonate.net/change/{$this->sSubscription->sEmailAddress}/{$this->sId}/{$this->sKey}", + "unsubscribe-url" => "http://redonate.com/manage/{$this->sSubscription->sEmailAddress}/{$this->sSubscription->sSettingsKey}", + "old" => Currency::Format($this->sOldCurrency, $this->sOldAmount), + "new" => Currency::Format($this->sNewCurrency, $this->sNewAmount) + )) + )); + + return array("text" => $sText, "html" => $sHtml); + } +} diff --git a/public_html/modules/change.php b/public_html/modules/change.php new file mode 100644 index 0000000..5d89bb2 --- /dev/null +++ b/public_html/modules/change.php @@ -0,0 +1,24 @@ +sSubscription->uCurrency = $sChangeRequest->uNewCurrency; +$sChangeRequest->sSubscription->uAmount = $sChangeRequest->uNewAmount; +$sChangeRequest->sSubscription->InsertIntoDatabase(); + +$sChangeRequest->uIsConfirmed = true; +$sChangeRequest->InsertIntoDatabase(); + +flash_notice("The change was successfully applied."); +redirect("/manage/{$sChangeRequest->sSubscription->sEmailAddress}/{$sChangeRequest->sSubscription->sSettingsKey}"); diff --git a/public_html/modules/error/nosuchchange.php b/public_html/modules/error/nosuchchange.php new file mode 100644 index 0000000..b095822 --- /dev/null +++ b/public_html/modules/error/nosuchchange.php @@ -0,0 +1,16 @@ +sCampaignId == $sCampaign->sId && $sSubscription->sIsActive == true) { $exists = true; + $sExistingSubscription = $sSubscription; } } @@ -65,7 +66,23 @@ catch (NotFoundException $e) if($exists) { $sPageContents = NewTemplater::Render("subscription/change", $locale->strings, array()); - /* TODO: Change request */ + + $sChangeRequest = new ChangeRequest(0); + $sChangeRequest->uKey = random_string(16); + $sChangeRequest->uOldCurrency = $sExistingSubscription->sCurrency; + $sChangeRequest->uOldAmount = $sExistingSubscription->sAmount; + $sChangeRequest->uNewCurrency = $_POST['currency']; + $sChangeRequest->uNewAmount = str_replace(",", ".", $_POST['amount']); + $sChangeRequest->uSubscriptionId = $sExistingSubscription->sId; + $sChangeRequest->uCampaignId = $sExistingSubscription->sCampaign->sId; + $sChangeRequest->uIsConfirmed = false; + $sChangeRequest->uDate = time(); + $sChangeRequest->InsertIntoDatabase(); + + $sEmail = $sChangeRequest->GenerateEmail(); + + send_mail($sExistingSubscription->sEmailAddress, "Changes to your pledge to {$sExistingSubscription->sCampaign->sName}", $sEmail['text'], $sEmail['html']); + return; } diff --git a/public_html/rewrite.php b/public_html/rewrite.php index 063b342..3918e26 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -78,6 +78,11 @@ $router->routes = array( 'authenticator' => "authenticators/payment.php", 'auth_error' => "modules/error/nosuchpayment.php" ), + "^/change/(.+)/([0-9]+)/([a-zA-Z0-9]+)$" => array( + 'target' => "modules/change.php", + 'authenticator' => "authenticators/change.php", + 'auth_error' => "modules/error/nosuchchange.php" + ), "^/manage/(.+?)/([a-zA-Z0-9]+)/change-amount$" => array( 'target' => "modules/subscription/change_amount.php", 'authenticator' => "authenticators/subscription.php", diff --git a/public_html/templates/email/change.html.tpl b/public_html/templates/email/change.html.tpl new file mode 100644 index 0000000..9bd5115 --- /dev/null +++ b/public_html/templates/email/change.html.tpl @@ -0,0 +1,44 @@ +

+ Hi there, +

+ +

+ You entered your e-mail address for a campaign that you already + subscribed to in the past. If you meant to change your settings, please + click the confirmation link, and we'll update your settings. +

+ +

+ If you didn't mean to change your settings and want to keep things as + they were before, you can simply ignore this e-mail. If you have any + further questions, don't hesitate to reply to this e-mail! +

+ +

+ Campaign: {%?campaign-name} +

+ +

+ Previous monthly amount: {%?old} +

+ +

+ New monthly amount: {%?new} +

+ +

+ Click this link to confirm the change: + {%?confirmation-url} +

+ +

+ - Sven Slootweg, ReDonate +

+ +
+ +

+ If you want to cancel your donation pledge or change your settings, please visit + {%?unsubscribe-url}. +

+ diff --git a/public_html/templates/email/change.txt.tpl b/public_html/templates/email/change.txt.tpl new file mode 100644 index 0000000..32d75a0 --- /dev/null +++ b/public_html/templates/email/change.txt.tpl @@ -0,0 +1,25 @@ +Hi there, + +You entered your e-mail address for a campaign that you already +subscribed to in the past. If you meant to change your settings, please +click the confirmation link, and we'll update your settings. + +If you didn't mean to change your settings and want to keep things as +they were before, you can simply ignore this e-mail. If you have any +further questions, don't hesitate to reply to this e-mail! + +Campaign: {%?campaign-name} + +Previous monthly amount: {%?old} + +New monthly amount: {%?new} + +Click this link to confirm the change: {%?confirmation-url} + +- Sven Slootweg, ReDonate + +----- + +If you want to cancel your donation pledge or change other settings, +please visit {%?unsubscribe-url}. +