Skip to content

Commit a34e3f4

Browse files
committed
Added namespaces, iproved user class
1 parent 886873a commit a34e3f4

File tree

7 files changed

+52
-15
lines changed

7 files changed

+52
-15
lines changed

core/basic.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function setReporting()
3232
function callHook()
3333
{
3434
global $url; // defined in public/index.php
35-
$user = new User;
35+
$user = new Core\User;
3636

3737
if ($url == "") {
3838
global $routing_default;
@@ -54,10 +54,13 @@ function callHook()
5454
$controllerName = ucwords($controller) . 'Controller';
5555
$dispatch = new $controllerName($controller, $action);
5656

57-
if ($dispatch->requireUser == true && $user->isLoggedIn == false) {
57+
if ($dispatch->requireUser == true && $user->isLoggedIn() == false) {
5858
// deny access for requested action
5959
global $routing_user;
6060

61+
// disable rendering of requested page
62+
$dispatch->renderPage = false;
63+
6164
$controller = $routing_user['controller'];
6265
$action = $routing_user['action'];
6366
$queryString = $routing_user['query'];

core/controller.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
namespace Core;
4+
25
/**
36
* Abstract controller
47
*

core/inflection.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
namespace Core;
4+
25
/**
36
* This class has been taken from
47
* http://kuwamoto.org/2007/12/17/improved-pluralizing-in-php-actionscript-and-ror

core/model.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
3+
namespace Core;
24
/**
35
* Abstract model
46
*
57
* Abstraction class for models used in aplication
68
*/
7-
abstract class Model extends SQLQuery
9+
abstract class Model extends Core\SQLQuery
810
{
911
/** @var string Stores model name */
1012
protected $_model;

core/sqlquery.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
namespace Core;
34
/**
45
* Database abstraction layer
56
*

core/template.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
namespace Core;
24
/**
35
* Templating engine
46
*

core/user.class.php

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?php
22

3+
namespace Core;
34
/**
45
* User management class
56
*
67
* Manages handling of user information through session
78
*/
89
class User
910
{
10-
/** @var bool True if user is loged in */
11-
public $isLogedIn;
11+
/** @var bool False if user is not loged in */
12+
private $_loggedIn;
1213

1314
/** @var array Stores custom fields */
1415
private $_variables;
@@ -21,31 +22,53 @@ class User
2122
*/
2223
function __construct()
2324
{
25+
$this->_variables = array();
26+
2427
if (isset($_SESSION['_user']['logged_in']) == true) {
25-
$this->isLogedIn = $_SESSION['_user']['logged_in'];
28+
$this->_loggedIn = $_SESSION['_user']['logged_in'];
2629
} else {
27-
$this->isLogedIn = false;
30+
$this->_loggedIn = false;
2831
}
2932

30-
if ($this->isLogedIn == true) {
33+
if ($this->_loggedIn == true) {
3134
$this->_variables = $_SESSION['_user']['variables'];
3235
}
3336
}
3437

3538
/**
36-
* Destructor function for User class
39+
* Mark user as logged in or out
3740
*
38-
* Handles data storage into session
41+
* @param bool $status true if user is logged in
3942
*/
40-
function __destruct()
43+
function setLogedIn($status)
4144
{
42-
$_SESSION['_user']['logged_in'] = $this->isLogedIn;
45+
if ($status == false) {
46+
$this->_loggedIn = false;
47+
$this->_variables = array();
48+
49+
$_SESSION['_user']['logged_in'] = false;
50+
$_SESSION['_user']['variables'] = array();
51+
} else {
52+
$this->_loggedIn = $status;
4353

44-
if ($this->isLogedIn == true) {
45-
$_SESSION['_user']['variables'] = $this->_variables;
54+
$_SESSION['_user']['logged_in'] = $status;
4655
}
56+
4757
}
4858

59+
/**
60+
* User login status
61+
*
62+
* @return bool False if user is not logged in
63+
*/
64+
function isLoggedIn()
65+
{
66+
if ($this->_loggedIn == false) {
67+
return false;
68+
} else {
69+
return $this->_loggedIn;
70+
}
71+
}
4972
/**
5073
* Handles custom variable storage
5174
*
@@ -65,7 +88,7 @@ function set($name, $value)
6588
*/
6689
function get($name)
6790
{
68-
if (array_key_exists($name) == true) {
91+
if (array_key_exists($name, $this->_variables) == true) {
6992
$value = $this->_variables[$name];
7093
} else {
7194
$value = false;

0 commit comments

Comments
 (0)