[Lambda-cvs] lambda/classes lambdaClient.class.php,1.6,1.7 lambdaMySQLi.class.php,1.7,1.8 lambdaSess
Status: Pre-Alpha
Brought to you by:
ariejan
From: Ariejan de V. <ar...@us...> - 2004-07-08 09:52:19
|
Update of /cvsroot/lambda/lambda/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14548/classes Modified Files: lambdaClient.class.php lambdaMySQLi.class.php lambdaSession.class.php Log Message: * Added *very* basic GUI * Added client/admin login and logout functionality * Updated stylesheet Index: lambdaSession.class.php =================================================================== RCS file: /cvsroot/lambda/lambda/classes/lambdaSession.class.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** lambdaSession.class.php 7 Jul 2004 14:46:14 -0000 1.2 --- lambdaSession.class.php 8 Jul 2004 09:52:04 -0000 1.3 *************** *** 34,37 **** --- 34,39 ---- **/ function start() { + global $client; + // Start the session if it is not yet active if(!session_id()) { *************** *** 39,42 **** --- 41,49 ---- } $this->handler->debug("Session started", 2); + + /* Load any logged in client data */ + if(isset($_SESSION['client_id'])) { + $client = new lambdaClient($_SESSION['client_id']); + } } *************** *** 68,72 **** **/ function login() { ! if(isset($_SESSION['client_id']) || isset($_SESSION['admin_id'])) { return true; } else { --- 75,79 ---- **/ function login() { ! if(isset($_SESSION['client_id'])) { return true; } else { *************** *** 76,84 **** /** * Destroy the current session **/ ! function destory() { session_destroy(); $this->handler->debug("Session destroyed", 2); } } --- 83,108 ---- /** + * Register a client as logged in + * + * @param object Client object + **/ + function register_client($client) { + $_SESSION['client_id'] = $client->client_id; + } + + /** * Destroy the current session **/ ! function destroy() { session_destroy(); $this->handler->debug("Session destroyed", 2); } + + /** + * Logout a logged in client + **/ + function logout() { + $this->unregister('client_id'); + $this->destroy(); + } } Index: lambdaMySQLi.class.php =================================================================== RCS file: /cvsroot/lambda/lambda/classes/lambdaMySQLi.class.php,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** lambdaMySQLi.class.php 7 Jul 2004 13:10:39 -0000 1.7 --- lambdaMySQLi.class.php 8 Jul 2004 09:52:04 -0000 1.8 *************** *** 52,56 **** // Set default zero-values ! $this->link = null; $this->query_count = 0; $this->query_history = array(); --- 52,56 ---- // Set default zero-values ! $this->link = false; $this->query_count = 0; $this->query_history = array(); *************** *** 77,81 **** $mylink = @mysql_connect($host, $this->config['username'], $this->config['password'], true); ! // Select the proper database and check for errors if(!@mysql_select_db($this->config['dbname'], $mylink)) { --- 77,81 ---- $mylink = @mysql_connect($host, $this->config['username'], $this->config['password'], true); ! // Select the proper database and check for errors if(!@mysql_select_db($this->config['dbname'], $mylink)) { *************** *** 87,91 **** } } ! /** * Perform a query --- 87,91 ---- } } ! /** * Perform a query *************** *** 98,102 **** function query($sql) { // Make sure we have a valid connection ! if(!$this->link || !@$this->connect()) { return false; } --- 98,102 ---- function query($sql) { // Make sure we have a valid connection ! if(!$this->link && !$this->connect()) { return false; } *************** *** 128,130 **** --- 128,140 ---- return @mysql_num_rows($res); } + + /** + * Fetch the next result row as an associative array + * + * @param object Valid MySQL result resource + * @return array The next result row as an associative array + **/ + function fetch_array($res) { + return @mysql_fetch_assoc($res); + } } \ No newline at end of file Index: lambdaClient.class.php =================================================================== RCS file: /cvsroot/lambda/lambda/classes/lambdaClient.class.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** lambdaClient.class.php 7 Jul 2004 13:10:39 -0000 1.6 --- lambdaClient.class.php 8 Jul 2004 09:52:04 -0000 1.7 *************** *** 48,52 **** * in $data. * ! * @param int Client ID or 0 for new client **/ function lambdaClient($client_id = 0) { --- 48,52 ---- * in $data. * ! * @param int Client ID or 0 for new client or login client **/ function lambdaClient($client_id = 0) { *************** *** 94,98 **** /* Verify return results */ ! if(!$result || $result->num_rows != 1) { /* Show a non-fatal error message */ $this->handler->error("Client data for ID ". $this->client_id ." not found!", false); --- 94,98 ---- /* Verify return results */ ! if(!$result || $this->mysqli->num_rows($result) != 1) { /* Show a non-fatal error message */ $this->handler->error("Client data for ID ". $this->client_id ." not found!", false); *************** *** 104,111 **** /* Data ok, now put it into the private data array */ ! $this->data = $result->fetch_assoc(); ! ! /* Free the result */ ! $result->free(); return true; --- 104,108 ---- /* Data ok, now put it into the private data array */ ! $this->data = $this->mysqli->fetch_array($result); return true; *************** *** 211,213 **** --- 208,258 ---- } } + + /** + * Authenticate a client + * + * Receive a loginname and an MD5 encrypted password and verify it against the + * client database. If the client is authenticated, the client data is loaded + * automatically. + * + * @param string login name + * @param string MD5 encrypted password for login name + * @return boolean True when valid client, otherwise false + **/ + function authenticate($loginname, $password) { + /* Prepare and execute SQL query */ + $sql = "SELECT `id` FROM `client` WHERE `login`='".$loginname."' AND `password`='".$password."'"; + $result = $this->mysqli->query($sql); + + if($result && $this->mysqli->num_rows($result) == 1) { + /* Valid client + * Load client data now + */ + $row = $this->mysqli->fetch_array($result); + $this->client_id = $row['id']; + $this->load(); + return true; + } else { + return false; + } + } + + /** + * Check if this client is an admin + * + * @return bool true if admin, otherwise false + **/ + function is_admin() { + return ($this->data['adminflag'] == 'A'); + } + + /** + * Check if this client is an client (non-admin) + * + * @return bool true if client, otherwise false + **/ + function is_client() { + return ($this->data['adminflag'] == 'C'); + } + } |