Move include code to own file, add confirmation page, implement message and notice flashing, and some lorem ipsum for good measure

master
Sven Slootweg 12 years ago
parent bc064a7227
commit a28e42c49c

@ -0,0 +1,115 @@
<?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."); }
$_CPHP = true;
$_CPHP_CONFIG = "../config.json";
require("cphp/base.php");
require_once('lib/swiftmailer/swift_required.php');
NewTemplater::RegisterVariableHook("errors", "get_errors");
NewTemplater::RegisterVariableHook("notices", "get_notices");
function get_errors($fetch)
{
if(isset($_SESSION['errors']))
{
$errors = $_SESSION['errors'];
if($fetch === true)
{
/* We only want to clear out errors if a call to
* actually retrieve the errors was made, not just
* something like an isempty. */
$_SESSION['errors'] = array();
}
return $errors;
}
else
{
return array();
}
}
function get_notices($fetch)
{
if(isset($_SESSION['notices']))
{
$notices = $_SESSION['notices'];
if($fetch === true)
{
$_SESSION['notices'] = array();
}
return $notices;
}
else
{
return array();
}
}
function flash_error($message)
{
$_SESSION['errors'][] = $message;
}
function flash_notice($message)
{
$_SESSION['notices'][] = $message;
}
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("<div style=\"border: 1px solid black; padding: 8px; background-color: white; margin: 8px; margin-bottom: 24px;\">
<div style=\"font-size: 14px;\">
<strong>From:</strong> {$cphp_config->smtp->from}<br>
<strong>To:</strong> {$to}<br>
<strong>Subject:</strong> {$subject}
</div>
<hr>
<pre class=\"debug\">{$text}</pre>
<hr>
<div>
{$html}
</div>
</div>");
//$mail_transport->send($sMessage);
}

@ -0,0 +1,46 @@
<?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
{
$sSubscription = Subscription::CreateFromQuery("SELECT * FROM subscriptions WHERE `EmailAddress` = :EmailAddress AND `ConfirmationKey` = :ConfirmationKey AND `Confirmed` = 0",
array(":EmailAddress" => $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.");
}
}

@ -0,0 +1,17 @@
<?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."); }
$sPageTitle = "Dashboard";
$sPageContents = NewTemplater::Render("dashboard", $locale->strings, array());

@ -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
));

@ -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 <a href=\"/forgot-password\">forget your password</a>?";
flash_error("The password you entered is incorrect. Did you <a href=\"/forgot-password\">forget your password</a>?");
}
}
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";

@ -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 <a href=\"/forgot-password\">forget your password</a>?";
flash_error("The e-mail address you entered is already in use. Did you <a href=\"/forgot-password\">forget your password</a>?");
}
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";

@ -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;
}

@ -0,0 +1,19 @@
<?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."); }
$sNotice = empty($sNotice) ? "" : $sNotice;
$sPageTitle = "Manage your subscriptions";
$sPageContents = NewTemplater::Render("subscription/manage", $locale->strings, array("notice" => $sNotice));

@ -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("<div style=\"border: 1px solid black; padding: 8px; background-color: white; margin: 8px; margin-bottom: 24px;\">
<div style=\"font-size: 14px;\">
<strong>From:</strong> {$cphp_config->smtp->from}<br>
<strong>To:</strong> {$to}<br>
<strong>Subject:</strong> {$subject}
</div>
<hr>
<pre class=\"debug\">{$text}</pre>
<hr>
<div>
{$html}
</div>
</div>");
//$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"
)
);

@ -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 *
**************************************/

@ -0,0 +1,9 @@
{%if isempty|notices == false}
{%foreach notice in notices}
<div class="notices">
{%?notice}
</div>
{%/foreach}
{%/if}
Lorem ipsum indeed.

@ -28,10 +28,12 @@
</div>
<div class="subscribe">
<h3>Subscribe to a recurring donation</h3>
{%if isempty|error == false}
<p class="error">
{%?error}
</p>
{%if isempty|errors == false}
{%foreach error in errors}
<p class="error">
{%?error}
</p>
{%/foreach}
{%/if}
<form method="post" action="/campaign/{%?urlname}/subscribe">
<p>

@ -1,10 +1,12 @@
<div class="formwrapper narrow">
<h2 class="spaced">Login to your account</h2>
{%if isempty|error == false}
<div class="errors">
{%?error}
</div>
{%if isempty|errors == false}
{%foreach error in errors}
<div class="errors">
{%?error}
</div>
{%/foreach}
{%/if}
<form method="post" action="/login" class="narrow">

@ -0,0 +1,9 @@
{%if isempty|notices == false}
{%foreach notice in notices}
<div class="notices">
{%?notice}
</div>
{%/foreach}
{%/if}
Lorem ipsum indeed.
Loading…
Cancel
Save