diff --git a/public_html/includes/base.php b/public_html/includes/base.php new file mode 100644 index 0000000..21ddc5c --- /dev/null +++ b/public_html/includes/base.php @@ -0,0 +1,115 @@ +setSubject($subject); + $sMessage->setTo($to); + $sMessage->setFrom($cphp_config->smtp->from); + $sMessage->setBody($text); + $sMessage->addPart($html, "text/html"); + + echo("
+
+ From: {$cphp_config->smtp->from}
+ To: {$to}
+ Subject: {$subject} +
+
+
{$text}
+
+
+ {$html} +
+
"); + + //$mail_transport->send($sMessage); +} diff --git a/public_html/modules/confirm.php b/public_html/modules/confirm.php new file mode 100644 index 0000000..92b506e --- /dev/null +++ b/public_html/modules/confirm.php @@ -0,0 +1,46 @@ + $router->uParameters[1], ":ConfirmationKey" => $router->uParameters[2]), 0, true); + $sSubscription->uIsConfirmed = true; + $sSubscription->InsertIntoDatabase(); + + flash_notice("Your subscription was successfully confirmed. Welcome on board!"); + redirect("/manage/{$sSubscription->sEmailAddress}/{$sSubscription->sSettingsKey}"); +} +catch (NotFoundException $e) +{ + try + { + $sUser = User::CreateFromQuery("SELECT * FROM users WHERE `EmailAddress` = :EmailAddress AND `ActivationKey` = :ActivationKey AND `Activated` = 0", + array(":EmailAddress" => $router->uParameters[1], ":ActivationKey" => $router->uParameters[2]), 0, true); + $sUser->uIsActivated = true; + $sUser->InsertIntoDatabase(); + + $sUser->Authenticate(); + + flash_notice("Your account was successfully activated. Welcome on board!"); + redirect("/dashboard"); + } + catch (NotFoundException $e) + { + /* No user or subscription with this e-mail address and verification key exists. Bail out. + * We'll throw a RouterException so that we only have to deal with 404s in one place. */ + throw new RouterException("Confirmation key not found."); + } +} diff --git a/public_html/modules/dashboard.php b/public_html/modules/dashboard.php new file mode 100644 index 0000000..dc330fe --- /dev/null +++ b/public_html/modules/dashboard.php @@ -0,0 +1,17 @@ +strings, array()); diff --git a/public_html/modules/landing.php b/public_html/modules/landing.php index 4dbe66f..2fc7bb9 100644 --- a/public_html/modules/landing.php +++ b/public_html/modules/landing.php @@ -37,6 +37,5 @@ $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 + "urlname" => $sCampaign->sUrlName )); diff --git a/public_html/modules/login.php b/public_html/modules/login.php index 703198b..ded4259 100644 --- a/public_html/modules/login.php +++ b/public_html/modules/login.php @@ -13,17 +13,15 @@ if(!isset($_APP)) { die("Unauthorized."); } -$sError = ""; - if(!empty($_POST['submit'])) { if(empty($_POST['username'])) { - $sError = "You did not enter a username."; + flash_error("You did not enter a username."); } elseif(empty($_POST['password'])) { - $sError = "You did not enter a password."; + flash_error("You did not enter a password."); } else { @@ -38,15 +36,15 @@ if(!empty($_POST['submit'])) } else { - $sError = "The password you entered is incorrect. Did you forget your password?"; + flash_error("The password you entered is incorrect. Did you forget your password?"); } } catch (NotFoundException $e) { - $sError = "That username does not exist."; + flash_error("That username does not exist."); } } } -$sPageContents = NewTemplater::Render("login/form", $locale->strings, array('error' => $sError)); +$sPageContents = NewTemplater::Render("login/form", $locale->strings); $sPageTitle = "Login"; diff --git a/public_html/modules/signup.php b/public_html/modules/signup.php index 2f72246..6c055a9 100644 --- a/public_html/modules/signup.php +++ b/public_html/modules/signup.php @@ -13,43 +13,41 @@ if(!isset($_APP)) { die("Unauthorized."); } -$sErrors = array(); - if(!empty($_POST['submit'])) { if(empty($_POST['username']) || !preg_match("/^[a-zA-Z0-9-.]+$/", $_POST['username'])) { - $sErrors[] = "You did not enter a valid username. Your username can only contain a-z, A-Z, 0-9, dots, and dashes."; + flash_error("You did not enter a valid username. Your username can only contain a-z, A-Z, 0-9, dots, and dashes."); } elseif(User::CheckIfUsernameExists($_POST['username']) || User::CheckIfDisplayNameExists($_POST['username'])) { - $sErrors[] = "The username you entered is already in use. Please pick a different username."; + flash_error("The username you entered is already in use. Please pick a different username."); } if(empty($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { - $sErrors[] = "You did not enter a valid e-mail address."; + flash_error("You did not enter a valid e-mail address."); } elseif(User::CheckIfEmailExists($_POST['email'])) { - $sErrors[] = "The e-mail address you entered is already in use. Did you forget your password?"; + flash_error("The e-mail address you entered is already in use. Did you forget your password?"); } if(empty($_POST['password']) || strlen($_POST['password']) < 8) { - $sErrors[] = "You did not enter a valid password. Your password has to be at least 8 characters."; + flash_error("You did not enter a valid password. Your password has to be at least 8 characters."); } elseif(empty($_POST['password2']) || $_POST['password'] != $_POST['password2']) { - $sErrors[] = "The passwords you entered did not match."; + flash_error("The passwords you entered did not match."); } if(!empty($_POST['displayname']) && User::CheckIfDisplayNameExists($_POST['displayname'])) { - $sErrors[] = "The (display) name you entered is already in use. Please pick a different name. You can also just use your nickname!"; + flash_error("The (display) name you entered is already in use. Please pick a different name. You can also just use your nickname!"); } - if(empty($sErrors)) + if(count(get_errors(false)) == 0) { $sUser = new User(0); $sUser->uUsername = $_POST['username']; @@ -78,5 +76,5 @@ if(!empty($_POST['submit'])) } } -$sPageContents = NewTemplater::Render("signup/form", $locale->strings, array('errors' => $sErrors)); +$sPageContents = NewTemplater::Render("signup/form", $locale->strings, array()); $sPageTitle = "Sign up"; diff --git a/public_html/modules/subscribe.php b/public_html/modules/subscribe.php index 1e98ca3..7fe2de0 100644 --- a/public_html/modules/subscribe.php +++ b/public_html/modules/subscribe.php @@ -25,21 +25,21 @@ catch (NotFoundException $e) if(empty($_POST['email']) || User::CheckIfEmailValid($_POST['email']) == false) { - $sError = "Please enter a valid e-mail address."; + flash_error("Please enter a valid e-mail address."); require("modules/landing.php"); return; } if(empty($_POST['currency'])) { - $sError = "Please pick a valid currency."; + flash_error("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."; + flash_error("Please enter a valid amount."); require("modules/landing.php"); return; } diff --git a/public_html/modules/subscription/manage.php b/public_html/modules/subscription/manage.php new file mode 100644 index 0000000..81b9be5 --- /dev/null +++ b/public_html/modules/subscription/manage.php @@ -0,0 +1,19 @@ +strings, array("notice" => $sNotice)); diff --git a/public_html/rewrite.php b/public_html/rewrite.php index 40b8b81..452a223 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -11,54 +11,8 @@ * licensing text. */ -$_CPHP = true; -$_CPHP_CONFIG = "../config.json"; -require("cphp/base.php"); $_APP = true; - -require_once('lib/swiftmailer/swift_required.php'); - -function autoload_redonate($class_name) -{ - global $_APP; - - $class_name = str_replace("\\", "/", strtolower($class_name)); - - if(file_exists("classes/{$class_name}.php")) - { - require_once("classes/{$class_name}.php"); - } -} - -spl_autoload_register(autoload_redonate); - -function send_mail($to, $subject, $text, $html) -{ - global $mail_transport, $cphp_config; - $sMessage = Swift_Message::newInstance(); - $sMessage->setSubject($subject); - $sMessage->setTo($to); - $sMessage->setFrom($cphp_config->smtp->from); - $sMessage->setBody($text); - $sMessage->addPart($html, "text/html"); - - echo("
-
- From: {$cphp_config->smtp->from}
- To: {$to}
- Subject: {$subject} -
-
-
{$text}
-
-
- {$html} -
-
"); - - //$mail_transport->send($sMessage); -} - +require("includes/base.php"); $sPageTitle = ""; $sPageContents = ""; @@ -76,8 +30,10 @@ $router->routes = array( ), "^/sign-up$" => "modules/signup.php", "^/login$" => "modules/login.php", + "^/confirm/(.+)/([a-zA-Z0-9]+)" => "modules/confirm.php", + "^/dashboard" => "modules/dashboard.php", "^/campaign/([a-zA-Z0-9-]+)$" => "modules/landing.php", - "^/campaign/([a-zA-Z0-9-]+)/subscribe$" => "modules/subscribe.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 bb8f0a3..0a78757 100644 --- a/public_html/static/css/style.css +++ b/public_html/static/css/style.css @@ -269,6 +269,10 @@ form button:active margin-bottom: 13px; } +/************************************** + * NOTIFICATIONS * + **************************************/ + .errors { color: #2F0003; @@ -278,6 +282,15 @@ form button:active background-color: #FFF7F8; } +.notices +{ + color: #002F03; + margin-bottom: 30px; + padding: 12px; + border: 1px solid #116F00; + background-color: #F8FFF7; +} + /************************************** * LANDING * **************************************/ diff --git a/public_html/templates/dashboard.tpl b/public_html/templates/dashboard.tpl new file mode 100644 index 0000000..b8f7cfa --- /dev/null +++ b/public_html/templates/dashboard.tpl @@ -0,0 +1,9 @@ +{%if isempty|notices == false} + {%foreach notice in notices} +
+ {%?notice} +
+ {%/foreach} +{%/if} + +Lorem ipsum indeed. diff --git a/public_html/templates/landing.tpl b/public_html/templates/landing.tpl index e65b06b..b3daacf 100644 --- a/public_html/templates/landing.tpl +++ b/public_html/templates/landing.tpl @@ -28,10 +28,12 @@

Subscribe to a recurring donation

- {%if isempty|error == false} -

- {%?error} -

+ {%if isempty|errors == false} + {%foreach error in errors} +

+ {%?error} +

+ {%/foreach} {%/if}

diff --git a/public_html/templates/login/form.tpl b/public_html/templates/login/form.tpl index 8226773..60fbe9f 100644 --- a/public_html/templates/login/form.tpl +++ b/public_html/templates/login/form.tpl @@ -1,10 +1,12 @@

Login to your account

- {%if isempty|error == false} -
- {%?error} -
+ {%if isempty|errors == false} + {%foreach error in errors} +
+ {%?error} +
+ {%/foreach} {%/if} diff --git a/public_html/templates/signup/confirmed.tpl b/public_html/templates/signup/confirmed.tpl new file mode 100644 index 0000000..d89282f --- /dev/null +++ b/public_html/templates/signup/confirmed.tpl @@ -0,0 +1,2 @@ +

Thanks!

+ diff --git a/public_html/templates/subscription/manage.tpl b/public_html/templates/subscription/manage.tpl new file mode 100644 index 0000000..b8f7cfa --- /dev/null +++ b/public_html/templates/subscription/manage.tpl @@ -0,0 +1,9 @@ +{%if isempty|notices == false} + {%foreach notice in notices} +
+ {%?notice} +
+ {%/foreach} +{%/if} + +Lorem ipsum indeed.