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:
parent
cedc38917a
commit
29987e8640
8 changed files with 87 additions and 18 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# OS generated files #
|
||||||
|
######################
|
||||||
|
.DS_Store
|
||||||
|
.DS_Store?
|
16
classes/AnonymousModule.php
Normal file
16
classes/AnonymousModule.php
Normal 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
16
classes/UserModule.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class UserModule extends CustomModule
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
if (!User::isAuthenticated())
|
||||||
|
{
|
||||||
|
Browser::redirect('/login');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -3,6 +3,19 @@
|
||||||
class User extends RedisModel
|
class User extends RedisModel
|
||||||
{
|
{
|
||||||
protected $prefix = 'user';
|
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
8
modules/join.php
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class join extends AnonymousModule
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
8
modules/login.php
Normal file
8
modules/login.php
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class login extends AnonymousModule
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -1,23 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class user_create extends CustomModule
|
class user_create extends AnonymousModule
|
||||||
{
|
{
|
||||||
// protected $ajax = true;
|
protected $ajax = true;
|
||||||
// protected $method = 'POST';
|
protected $method = 'POST';
|
||||||
// protected $validate = array(
|
protected $validate = array(
|
||||||
// 'email' => array(
|
'email' => array(
|
||||||
// 'length:>:100' => 'Email addresses may not be more than 100 characters.',
|
'length:>:100' => 'Email addresses may not be more than 100 characters.',
|
||||||
// 'filter:email' => 'Your email address is invalid.',
|
'filter:email' => 'Your email address is invalid.',
|
||||||
// ),
|
),
|
||||||
// 'username' => array(
|
'username' => array(
|
||||||
// 'length:<:4' => 'Usernames may not be less than 4 characters.',
|
'length:<:4' => 'Usernames may not be less than 4 characters.',
|
||||||
// 'length:>:30' => 'Usernames may not be more than 50 characters.',
|
'length:>:30' => 'Usernames may not be more than 50 characters.',
|
||||||
// 'regex:is:/[^a-z0-9]+/i' => 'Usernames may only contain letters and numbers.',
|
'regex:is:/[^a-z0-9]+/i' => 'Usernames may only contain letters and numbers.',
|
||||||
// ),
|
),
|
||||||
// 'password' => array(
|
'password' => array(
|
||||||
// 'length:<:8' => 'Passwords may not be less than 8 characters.',
|
'length:<:8' => 'Passwords may not be less than 8 characters.',
|
||||||
// ),
|
),
|
||||||
// );
|
);
|
||||||
|
|
||||||
public function __default()
|
public function __default()
|
||||||
{
|
{
|
||||||
|
@ -53,7 +53,7 @@ class user_create extends CustomModule
|
||||||
$user->setMapping('email', $_POST['email'], $uid);
|
$user->setMapping('email', $_POST['email'], $uid);
|
||||||
|
|
||||||
// Sets a cookie with the UID and auth token
|
// 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' => '/');
|
return array('status' => 'success', 'url' => '/');
|
||||||
}
|
}
|
||||||
|
|
4
private/logs/.gitignore
vendored
Normal file
4
private/logs/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# Ignore everything in this directory
|
||||||
|
*
|
||||||
|
# Except this file
|
||||||
|
!.gitignore
|
Loading…
Add table
Add a link
Reference in a new issue