owls
annotate Includes/Loginsys.class.php @ 7:a3a651f0cac6
added doxygen-comments to Loginsys.class.php
author | Meillo r e t u r n s <meillo@marmaro.de> |
---|---|
date | Wed, 13 Dec 2006 22:16:59 +0100 |
parents | 3021ce32ee14 |
children | eb5bff360deb |
rev | line source |
---|---|
meillo@0 | 1 <?php |
meillo@7 | 2 /** |
meillo@7 | 3 * simple loginsystem for owls |
meillo@7 | 4 * |
meillo@7 | 5 * @brief simple loginsystem for owls |
meillo@7 | 6 * @author Meillo r e t u r n s <meillo@marmaro.de> |
meillo@7 | 7 */ |
meillo@0 | 8 class Loginsys { |
meillo@0 | 9 |
meillo@7 | 10 /// Consts |
meillo@0 | 11 |
meillo@7 | 12 /** |
meillo@7 | 13 * time in seconds till the session expires |
meillo@7 | 14 */ |
meillo@7 | 15 define('TIME_SESSION_EXPIRES', 1800); |
meillo@7 | 16 |
meillo@7 | 17 |
meillo@7 | 18 |
meillo@7 | 19 /// Constructors |
meillo@7 | 20 |
meillo@7 | 21 /** |
meillo@7 | 22 * starts the session |
meillo@7 | 23 * and puts an activity timestamp in it |
meillo@7 | 24 */ |
meillo@0 | 25 public function __construct() { |
meillo@0 | 26 session_start(); |
meillo@0 | 27 $this->heartbeat(); |
meillo@0 | 28 } |
meillo@0 | 29 |
meillo@0 | 30 |
meillo@0 | 31 |
meillo@0 | 32 |
meillo@7 | 33 /// Methods |
meillo@0 | 34 |
meillo@7 | 35 |
meillo@7 | 36 /** |
meillo@7 | 37 * trys to log in with the given login data |
meillo@7 | 38 * |
meillo@7 | 39 * @param $loginname username |
meillo@7 | 40 * @param $password_md5 md5 password hash |
meillo@7 | 41 */ |
meillo@0 | 42 public function login($loginname, $password_md5) { // login ------------------------------------ |
meillo@0 | 43 $rowuser = mysql_fetch_array(mysql_query("select * from ". DB_PREFIX ."User where loginname='$loginname' and password='$password_md5' ")); |
meillo@0 | 44 if (mysql_affected_rows() == 1) { // valid login |
meillo@0 | 45 $_SESSION[login][id] = $rowuser[id]; |
meillo@0 | 46 $_SESSION[login][loginname] = $loginname; |
meillo@0 | 47 $_SESSION[login][logintime] = time(); |
meillo@0 | 48 } |
meillo@0 | 49 } |
meillo@0 | 50 |
meillo@0 | 51 |
meillo@7 | 52 /** |
meillo@7 | 53 * logs the user out |
meillo@7 | 54 */ |
meillo@0 | 55 public function logout() { // logout ------------------------------------------------------------ |
meillo@0 | 56 unset($_SESSION[login]); |
meillo@0 | 57 } |
meillo@0 | 58 |
meillo@0 | 59 |
meillo@7 | 60 /** |
meillo@7 | 61 * proves if the user is logged in and if he wan't to long inactive |
meillo@7 | 62 * |
meillo@7 | 63 * @return bool 'true' if user is logged in, else 'false' |
meillo@7 | 64 */ |
meillo@0 | 65 public function loggedIn() { // return login-status --------------------------------------------- |
meillo@0 | 66 return (isset($_SESSION[login][id]) && $_SESSION[login][logintime] > time()-TIME_SESSION_EXPIRES); |
meillo@0 | 67 } |
meillo@0 | 68 |
meillo@0 | 69 |
meillo@7 | 70 /** |
meillo@7 | 71 * writes the current timestamp into the session |
meillo@7 | 72 * this is relevant for the time of inactivity |
meillo@7 | 73 */ |
meillo@0 | 74 public function heartbeat() { |
meillo@0 | 75 if ($this->loggedIn()) { |
meillo@0 | 76 $_SESSION[login][logintime] = time(); |
meillo@0 | 77 } |
meillo@0 | 78 } |
meillo@0 | 79 |
meillo@0 | 80 |
meillo@0 | 81 |
meillo@7 | 82 /// Getter and Setter |
meillo@0 | 83 |
meillo@7 | 84 |
meillo@7 | 85 /** |
meillo@7 | 86 * @return user id |
meillo@7 | 87 */ |
meillo@0 | 88 public function getUserId() { |
meillo@0 | 89 return $_SESSION[login][id]; |
meillo@0 | 90 } |
meillo@0 | 91 |
meillo@7 | 92 /** |
meillo@7 | 93 * @return user name |
meillo@7 | 94 */ |
meillo@0 | 95 public function getLoginname() { |
meillo@0 | 96 return $_SESSION[login][loginname]; |
meillo@0 | 97 } |
meillo@0 | 98 |
meillo@0 | 99 } |
meillo@0 | 100 |
meillo@0 | 101 |
meillo@0 | 102 ?> |