From c787833e7cbd2c33257a963e4bc99a3f7dc97cd7 Mon Sep 17 00:00:00 2001 From: neoraider Date: Sat, 11 Mar 2006 23:49:00 +0000 Subject: Benutzerverwaltung implementiert. --- code/pages.inc.php | 10 ++++++-- code/user.inc.php | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 76 insertions(+), 7 deletions(-) (limited to 'code') diff --git a/code/pages.inc.php b/code/pages.inc.php index d57bb17..e1bfd9b 100644 --- a/code/pages.inc.php +++ b/code/pages.inc.php @@ -93,6 +93,8 @@ array(substr($string, 0, -1), $page, $type)); else $GLOBALS['db']->Execute('UPDATE pages SET data = ? WHERE id = ?', array(substr($string, 0, -1), $page)); + + return ($GLOBALS['db']->Affected_Rows() > 0); } function Rename($page, $new_name, $type = null) { @@ -106,16 +108,18 @@ $GLOBALS['db']->Execute('UPDATE pages SET name = ? WHERE id = ?', array($new_name, $page)); } + + return ($GLOBALS['db']->Affected_Rows() > 0); } function Copy($page, $new_name, $type = null) { if($type) { - if($this->Exists($new_name, $type)) return; + if($this->Exists($new_name, $type)) return 0; $res = $GLOBALS['db']->Execute('SELECT * FROM pages WHERE name = ? AND type = ?', array($page, $type)); } else { - if($this->Exists($new_name, $this->GetType($type))) return; + if($this->Exists($new_name, $this->GetType($type))) return 0; $res = $GLOBALS['db']->Execute('SELECT handler, data, type FROM pages WHERE id = ?', $page); } @@ -129,6 +133,8 @@ function Delete($page, $type = null) { if($type) $GLOBALS['db']->Execute('DELETE FROM pages WHERE name = ? AND type = ?', array($page, $type)); else $GLOBALS['db']->Execute('DELETE FROM pages WHERE id = ?', $page); + + return ($GLOBALS['db']->Affected_Rows() > 0); } } diff --git a/code/user.inc.php b/code/user.inc.php index 7459e33..f945245 100644 --- a/code/user.inc.php +++ b/code/user.inc.php @@ -4,16 +4,18 @@ class User { var $uid = 0, $gid = 0; var $login_key = '', $login_type = ''; + var $name = ''; function User() { if($_COOKIE['login']) { - $res = $GLOBALS['db']->Execute('SELECT id, gid, sid FROM users WHERE id = ? AND sid = ?', + $res = $GLOBALS['db']->Execute('SELECT id, gid, sid, user FROM users WHERE id = ? AND sid = ?', array(substr($_COOKIE['login'], 32), substr($_COOKIE['login'], 0, 32))); if($res->RecordCount() && $res->fields[2]) { $this->uid = $res->fields[0]; $this->gid = $res->fields[1]; + $this->name = $res->fields[3]; $this->type = 'cookie'; $this->login_key = $_COOKIE['login']; @@ -21,13 +23,14 @@ } if($this->uid == 0 && $_GET['login']) { - $res = $GLOBALS['db']->Execute('SELECT id, gid, sid FROM users WHERE id = ? AND sid = ?', + $res = $GLOBALS['db']->Execute('SELECT id, gid, sid, user FROM users WHERE id = ? AND sid = ?', array(substr($_GET['login'], 32), substr($_GET['login'], 0, 32))); if($res->RecordCount() && $res->fields[2]) { $this->uid = $res->fields[0]; $this->gid = $res->fields[1]; + $this->name = $res->fields[3]; $this->login_type = 'url'; $this->login_key = $_GET['login']; @@ -36,7 +39,7 @@ } function Login($name, $pass) { - $res = $GLOBALS['db']->Execute('SELECT id, gid FROM users WHERE user = ? AND password = ?', array($name, $pass)); + $res = $GLOBALS['db']->Execute('SELECT id, gid, user FROM users WHERE user = ? AND password = ?', array($name, $pass)); if($res->RecordCount()) { $id = $res->fields[0]; @@ -46,6 +49,7 @@ $this->uid = $id; $this->gid = $res->fields[1]; + $this->name = $res->fields[2]; $this->login_type = 'url'; $this->login_key = $sid . $id; @@ -70,8 +74,67 @@ setcookie('login'); } - function IsAdmin() { - return ($this->uid != 0 && $this->gid == 0); + function IsAdmin($id = -1) { + if($id < 0) return ($this->uid != 0 && $this->gid == 0); + + return ($id != 0 && $this->GetGid($id) == 0); + } + + function GetGid($id = -1) { + if($id < 0) return $this->gid; + + $res = $GLOBALS['db']->Execute('SELECT gid FROM users WHERE id = ?', $id); + + return $res->fields[0]; + } + + function GetName($id = -1) { + if($id < 0) return $this->name; + + $res = $GLOBALS['db']->Execute('SELECT user FROM users WHERE id = ?', $id); + + return $res->fields[0]; + } + + function Exists($name) { + $res = $GLOBALS['db']->Execute('SELECT id FROM users WHERE user = ?', $name); + + return ($res->RecordCount() > 0); + } + + function Add($name, $gid, $pass) { + if($this->Exists($name)) return 0; + + $GLOBALS['db']->Execute('INSERT INTO users (user, gid, password) VALUES (?, ?, ?)', + array($name, $gid, $pass)); + + return $GLOBALS['db']->Insert_ID(); + } + + function ChangePassword($id = -1, $new_pass) { + if($id < 0) $id = $this->uid; + + $GLOBALS['db']->Execute('UPDATE users SET password = ? WHERE id = ?', array($new_pass, $id)); + + return ($GLOBALS['db']->Affected_Rows() > 0); + } + + function ChangeGroup($id, $gid) { + $GLOBALS['db']->Execute('UPDATE users SET gid = ? WHERE id = ?', array($gid, $id)); + + return ($GLOBALS['db']->Affected_Rows() > 0); + } + + function Rename($id, $new_name) { + $GLOBALS['db']->Execute('UPDATE users SET user = ? WHERE id = ?', array($new_name, $id)); + + return ($GLOBALS['db']->Affected_Rows() > 0); + } + + function Delete($id) { + $GLOBALS['db']->Execute('DELETE FROM users WHERE id = ?', $id); + + return ($GLOBALS['db']->Affected_Rows() > 0); } } -- cgit v1.2.3