From e830661cbc1cf087a44ec961692b5f850dcc0d7b Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 19 Jun 2013 03:25:02 +0200 Subject: [PATCH] Registration system and small fixes --- public_html/includes/base.php | 18 ++++++++ public_html/modules/register.php | 72 ++++++++++++++++++++++++++++++ public_html/rewrite.php | 3 ++ public_html/static/style.css | 19 ++++++++ public_html/templates/layout.tpl | 19 +++++--- public_html/templates/register.tpl | 28 ++++++++++++ 6 files changed, 152 insertions(+), 7 deletions(-) create mode 100644 public_html/modules/register.php create mode 100644 public_html/templates/register.tpl diff --git a/public_html/includes/base.php b/public_html/includes/base.php index 7d9b596..d6902f6 100644 --- a/public_html/includes/base.php +++ b/public_html/includes/base.php @@ -20,6 +20,24 @@ require("cphp/base.php"); require("lib/Markdown.php"); require("lib/MarkdownExtra.php"); +if(!empty($_SESSION['user_id'])) +{ + try + { + $sCurrentUser = new User($_SESSION['user_id']); + NewTemplater::SetGlobalVariable("logged-in", true); + } + catch (NotFoundException $e) + { + NewTemplater::SetGlobalVariable("logged-in", false); + /* Pass */ + } +} +else +{ + NewTemplater::SetGlobalVariable("logged-in", false); +} + NewTemplater::RegisterVariableHook("errors", "get_errors"); NewTemplater::RegisterVariableHook("notices", "get_notices"); diff --git a/public_html/modules/register.php b/public_html/modules/register.php new file mode 100644 index 0000000..4b39b99 --- /dev/null +++ b/public_html/modules/register.php @@ -0,0 +1,72 @@ +uMethod == "post") +{ + if(empty($_POST['username'])) + { + flash_error("You did not enter a username."); + } + elseif(User::CheckIfUsernameExists($_POST['username']) === true) + { + flash_error("That username is already in use."); + } + + if(empty($_POST['email'])) + { + flash_error("You did not enter an e-mail address."); + } + elseif(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) + { + flash_error("The e-mail address you entered is invalid."); + } + elseif(User::CheckIfEmailAddressExists($_POST['email']) === true) + { + flash_error("That e-mail address is already in use."); + } + + if(empty($_POST['password'])) + { + flash_error("You did not enter a password."); + } + elseif(empty($_POST['password2'])) + { + flash_error("You did not enter a password confirmation."); + } + elseif($_POST['password'] != $_POST['password2']) + { + flash_error("The passwords you entered do not match."); + } + + if(count(get_errors(false)) == 0) + { + $sUser = new User(); + $sUser->uUsername = $_POST['username']; + $sUser->uPassword = $_POST['password']; + $sUser->uEmailAddress = $_POST['email']; + $sUser->uRegistrationDate = time(); + $sUser->uIsAdmin = false; + $sUser->uIsBanned = false; + $sUser->GenerateSalt(); + $sUser->GenerateHash(); + $sUser->InsertIntoDatabase(); + $sUser->Authenticate(); + redirect("/"); + } +} + +$sPageTitle = "Register a new account"; +$sPageHeader = "Register"; +$sPageContents = NewTemplater::Render("register", $locale->strings, array()); diff --git a/public_html/rewrite.php b/public_html/rewrite.php index 9164fd9..192ec63 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -16,6 +16,7 @@ require("includes/base.php"); $sPageTitle = ""; $sPageContents = ""; +$sPageHeader = ""; $router = new CPHPRouter(); @@ -29,6 +30,7 @@ $router->routes = array( "target" => "modules/login.php", "methods" => "post" ), + "^/register$" => "modules/register.php", "^/(.*)$" => "modules/page.php" ) ); @@ -45,5 +47,6 @@ catch (RouterException $e) echo(NewTemplater::Render("layout", $locale->strings, array( "title" => $sPageTitle, + "header" => $sPageHeader, "contents" => $sPageContents ))); diff --git a/public_html/static/style.css b/public_html/static/style.css index eb90e65..06f1a1f 100644 --- a/public_html/static/style.css +++ b/public_html/static/style.css @@ -205,3 +205,22 @@ div.error p padding: 2px 6px; border-radius: 2px; } + +.pure-skin-cryto .pure-form input[type="text"], +.pure-skin-cryto .pure-form input[type="password"], +.pure-skin-cryto .pure-form input[type="email"], +.pure-skin-cryto .pure-form input[type="url"], +.pure-skin-cryto .pure-form input[type="date"], +.pure-skin-cryto .pure-form input[type="month"], +.pure-skin-cryto .pure-form input[type="time"], +.pure-skin-cryto .pure-form input[type="datetime"], +.pure-skin-cryto .pure-form input[type="datetime-local"], +.pure-skin-cryto .pure-form input[type="week"], +.pure-skin-cryto .pure-form input[type="number"], +.pure-skin-cryto .pure-form input[type="search"], +.pure-skin-cryto .pure-form input[type="tel"], +.pure-skin-cryto .pure-form input[type="color"], +.pure-skin-cryto .pure-form select, +.pure-skin-cryto .pure-form textarea { + border: 1px solid #DADADA; +} diff --git a/public_html/templates/layout.tpl b/public_html/templates/layout.tpl index 9ecd877..8b24d82 100644 --- a/public_html/templates/layout.tpl +++ b/public_html/templates/layout.tpl @@ -3,21 +3,26 @@ Cryto Coding Collective :: {%?title} + - +

Cryto Coding Collective

-

Home

+

{%?header}