Registration system and small fixes

develop
Sven Slootweg 12 years ago
parent 0993d7dad6
commit e830661cbc

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

@ -0,0 +1,72 @@
<?php
/*
* Cryto 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."); }
if($router->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());

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

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

@ -3,21 +3,26 @@
<head>
<title>Cryto Coding Collective :: {%?title}</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.2.0/pure-min.css">
<link rel="stylesheet" type="text/css" href="/static/pure.css">
<link rel="stylesheet" type="text/css" href="/static/style.css">
</head>
<body>
<body class="pure-skin-cryto">
<div class="wrapper">
<div class="header">
<h1>Cryto Coding Collective</h1>
<h2>Home</h2>
<h2>{%?header}</h2>
</div>
<div class="menu">
<div class="login">
<form method="post" action="/login">
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<button type="submit">Login</button>
</form>
{%if logged-in == false}
<form method="post" action="/login">
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<button type="submit">Login</button>
</form>
{%else}
You are already logged in.
{%/if}
</div>
<a href="/">Home</a>
<a href="/projects/">Projects</a>

@ -0,0 +1,28 @@
<h3>Register</h3>
<form method="post" action="/register" class="pure-form pure-form-aligned">
<div class="pure-control-group">
<label>Username</label>
{%input type="text" name="username"}
</div>
<div class="pure-control-group">
<label>E-mail address</label>
{%input type="text" name="email"}
</div>
<div class="pure-control-group">
<label>Password</label>
{%input type="password" name="password"}
</div>
<div class="pure-control-group">
<label>Password (again)</label>
{%input type="password" name="password2"}
</div>
<div class="pure-control-group">
<label></label>
<button type="submit" class="pure-button pure-button-primary">Register</button>
</div>
</form>
Loading…
Cancel
Save