Mercurial > owls
diff Loginsys.class.php @ 13:3e3fa7725abb
reorganized filesystem strukture
author | meillo@marmaro.de |
---|---|
date | Sun, 27 May 2007 02:37:55 +0200 |
parents | Includes/Loginsys.class.php@144bc36a6c27 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Loginsys.class.php Sun May 27 02:37:55 2007 +0200 @@ -0,0 +1,102 @@ +<?php +/** + * simple loginsystem for owls + * + * @brief simple loginsystem for owls + * @author Meillo r e t u r n s <meillo@marmaro.de> + */ +class Loginsys { + + /// Consts + + /** + * time in seconds till the session expires + */ + const TIME_SESSION_EXPIRES = 1800; + + + + /// Constructors + + /** + * starts the session + * and puts an activity timestamp in it + */ + public function __construct() { + session_start(); + $this->heartbeat(); + } + + + + + /// Methods + + + /** + * trys to log in with the given login data + * + * @param $loginname username + * @param $password_md5 md5 password hash + */ + public function login($loginname, $password_md5) { // login ------------------------------------ + $rowuser = mysql_fetch_array(mysql_query("select * from ". DB_PREFIX ."User where loginname='$loginname' and password='$password_md5' ")); + if (mysql_affected_rows() == 1) { // valid login + $_SESSION[login][id] = $rowuser[id]; + $_SESSION[login][loginname] = $loginname; + $_SESSION[login][logintime] = time(); + } + } + + + /** + * logs the user out + */ + public function logout() { // logout ------------------------------------------------------------ + unset($_SESSION[login]); + } + + + /** + * proves if the user is logged in and if he wan't to long inactive + * + * @return bool 'true' if user is logged in, else 'false' + */ + public function loggedIn() { // return login-status --------------------------------------------- + return (isset($_SESSION[login][id]) && $_SESSION[login][logintime] > time()-self::TIME_SESSION_EXPIRES); + } + + + /** + * writes the current timestamp into the session + * this is relevant for the time of inactivity + */ + public function heartbeat() { + if ($this->loggedIn()) { + $_SESSION[login][logintime] = time(); + } + } + + + + /// Getter and Setter + + + /** + * @return user id + */ + public function getUserId() { + return $_SESSION[login][id]; + } + + /** + * @return user name + */ + public function getLoginname() { + return $_SESSION[login][loginname]; + } + +} + + +?>