[jasmine-commit] SF.net SVN: newsphp: [127] trunk/jasmine/classes/User.class.php
Brought to you by:
christoph_berg,
red-
|
From: <Re...@us...> - 2007-08-13 02:31:22
|
Revision: 127
http://newsphp.svn.sourceforge.net/newsphp/?rev=127&view=rev
Author: Red-
Date: 2007-08-12 19:31:22 -0700 (Sun, 12 Aug 2007)
Log Message:
-----------
Added Permissions. Fixed some small typos.
Modified Paths:
--------------
trunk/jasmine/classes/User.class.php
Modified: trunk/jasmine/classes/User.class.php
===================================================================
--- trunk/jasmine/classes/User.class.php 2007-08-11 02:35:19 UTC (rev 126)
+++ trunk/jasmine/classes/User.class.php 2007-08-13 02:31:22 UTC (rev 127)
@@ -76,9 +76,9 @@
private function Auth($User, $Pass, $Form)
{
// Start Check Query
- $CheckAuth = $this->db->sqlQuery('SELECT * FROM ' . USERS_TABLE . ' WHERE Username = \'' . $User . '\' AND Password = \'' . md5($Pass) . '\'');
+ $CheckAuth = $this->db->query('SELECT * FROM ' . USERS_TABLE . ' WHERE Username = \'' . $User . '\' AND Password = \'' . md5($Pass) . '\'');
- if($this->db->sqlNumrows($CheckAuth) != 0)
+ if($this->db->numRows($CheckAuth) != 0)
{
// Set Auth True
$this->Auth = true;
@@ -99,7 +99,10 @@
}
else
{
- $this->AuthFail('BadLogin');
+ // Set User ID and Group ID to 0 if fail
+ $this->Userdata['Group'] = '0';
+ $this->Userdata['ID'] = '0';
+
// Set Auth False
$this->Auth = false;
}
@@ -113,21 +116,60 @@
private function getUserdata($SQL)
{
$this->Userdata = array();
- while($row = $this->db->sqlFetchrow($SQL))
+ while($row = $this->db->getRows($SQL))
{
$this->Userdata = $row;
}
+
+ return $this->Userdata;
+ }
+
+ /*
+ * Checks the permissions of the User
+ * in corolation to their User ID.
+ *
+ * param $Type is the type of permission
+ * to get. Ie, Group or User. If it's not
+ * set, User is the permissions assigned.
+ *
+ * return true or false
+ */
+ public function isAllowed($Type = NULL)
+ {
+ self::loadPermissions();
- if($this->Userdata['Level'] == 3 && $this->Userdata['Group'] == 1)
+ if($Type == NULL)
{
- Template::getSingleton()->assignVars(array(
- 'ADMIN' => '<A class="Link" href="'.Core::getSingleton()->URL.'Admin">» Admin Panel</A><br>')
- );
+ $Type = 'User';
}
-
- return $this->Userdata;
+
+ return $this->permissions[$Type]['Allowed'];
}
+
+ /**
+ * The actual loader for permissions
+ * from the db. Relays to isAllowed.
+ *
+ */
+ private function loadPermissions()
+ {
+ $this->permissions['Group'] = $this->db->query('SELECT * FROM '.GROUP_PERMISSIONS_TABLE.' WHERE gid = \''. $this->Userdata['Group'] .'\'');
+ $this->permissions['User'] = $this->db->query('SELECT * FROM '.USERS_PERMISSIONS_TABLE.' WHERE uid = \''. $this->Userdata['ID'] .'\'');
+ while(list($Type) = each($this->permissions))
+ {
+ $result = $this->db->getRows($this->permissions[$Type]);
+ if($result['allowed'] = '1')
+ {
+ $this->permissions[$Type]['Allowed'] = true;
+ }
+ else
+ {
+ $this->permissions[$Type]['Allowed'] = false;
+ }
+ }
+ }
+
/**
* If Authentication Fails
* Tell Us Why! I sure as
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|