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