Finished user creation step

Added new modules to handle routing if the user is logged in or not. Closes #2
This commit is contained in:
Josh Sherman 2013-12-16 17:19:44 -05:00
parent cedc38917a
commit 29987e8640
8 changed files with 87 additions and 18 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
# OS generated files #
######################
.DS_Store
.DS_Store?

View file

@ -0,0 +1,16 @@
<?php
class AnonymousModule extends CustomModule
{
public function __construct()
{
parent::__construct();
if (User::isAuthenticated())
{
Browser::goHome();
}
}
}
?>

16
classes/UserModule.php Normal file
View file

@ -0,0 +1,16 @@
<?php
class UserModule extends CustomModule
{
public function __construct()
{
parent::__construct();
if (!User::isAuthenticated())
{
Browser::redirect('/login');
}
}
}
?>

View file

@ -3,6 +3,19 @@
class User extends RedisModel
{
protected $prefix = 'user';
public static function isAuthenticated()
{
if (isset($_COOKIE['__auth']))
{
list($uid, $auth_token) = explode('|', base64_decode($_COOKIE['__auth']));
$user = new self();
$user_token = $user->getAuth($uid);
return $user_token === $auth_token;
}
}
}
?>

8
modules/join.php Normal file
View file

@ -0,0 +1,8 @@
<?php
class join extends AnonymousModule
{
}
?>

8
modules/login.php Normal file
View file

@ -0,0 +1,8 @@
<?php
class login extends AnonymousModule
{
}
?>

View file

@ -1,23 +1,23 @@
<?php
class user_create extends CustomModule
class user_create extends AnonymousModule
{
// protected $ajax = true;
// protected $method = 'POST';
// protected $validate = array(
// 'email' => array(
// 'length:>:100' => 'Email addresses may not be more than 100 characters.',
// 'filter:email' => 'Your email address is invalid.',
// ),
// 'username' => array(
// 'length:<:4' => 'Usernames may not be less than 4 characters.',
// 'length:>:30' => 'Usernames may not be more than 50 characters.',
// 'regex:is:/[^a-z0-9]+/i' => 'Usernames may only contain letters and numbers.',
// ),
// 'password' => array(
// 'length:<:8' => 'Passwords may not be less than 8 characters.',
// ),
// );
protected $ajax = true;
protected $method = 'POST';
protected $validate = array(
'email' => array(
'length:>:100' => 'Email addresses may not be more than 100 characters.',
'filter:email' => 'Your email address is invalid.',
),
'username' => array(
'length:<:4' => 'Usernames may not be less than 4 characters.',
'length:>:30' => 'Usernames may not be more than 50 characters.',
'regex:is:/[^a-z0-9]+/i' => 'Usernames may only contain letters and numbers.',
),
'password' => array(
'length:<:8' => 'Passwords may not be less than 8 characters.',
),
);
public function __default()
{
@ -53,7 +53,7 @@ class user_create extends CustomModule
$user->setMapping('email', $_POST['email'], $uid);
// Sets a cookie with the UID and auth token
setcookie('auth', $uid . '|' . $auth_token, Time::YEAR);
setcookie('__auth', base64_encode($uid . '|' . $auth_token), time() + Time::YEAR, '/');
return array('status' => 'success', 'url' => '/');
}

4
private/logs/.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore