owls

view 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
line source
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 {
10 /// Consts
12 /**
13 * time in seconds till the session expires
14 */
15 define('TIME_SESSION_EXPIRES', 1800);
19 /// Constructors
21 /**
22 * starts the session
23 * and puts an activity timestamp in it
24 */
25 public function __construct() {
26 session_start();
27 $this->heartbeat();
28 }
33 /// Methods
36 /**
37 * trys to log in with the given login data
38 *
39 * @param $loginname username
40 * @param $password_md5 md5 password hash
41 */
42 public function login($loginname, $password_md5) { // login ------------------------------------
43 $rowuser = mysql_fetch_array(mysql_query("select * from ". DB_PREFIX ."User where loginname='$loginname' and password='$password_md5' "));
44 if (mysql_affected_rows() == 1) { // valid login
45 $_SESSION[login][id] = $rowuser[id];
46 $_SESSION[login][loginname] = $loginname;
47 $_SESSION[login][logintime] = time();
48 }
49 }
52 /**
53 * logs the user out
54 */
55 public function logout() { // logout ------------------------------------------------------------
56 unset($_SESSION[login]);
57 }
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 */
65 public function loggedIn() { // return login-status ---------------------------------------------
66 return (isset($_SESSION[login][id]) && $_SESSION[login][logintime] > time()-TIME_SESSION_EXPIRES);
67 }
70 /**
71 * writes the current timestamp into the session
72 * this is relevant for the time of inactivity
73 */
74 public function heartbeat() {
75 if ($this->loggedIn()) {
76 $_SESSION[login][logintime] = time();
77 }
78 }
82 /// Getter and Setter
85 /**
86 * @return user id
87 */
88 public function getUserId() {
89 return $_SESSION[login][id];
90 }
92 /**
93 * @return user name
94 */
95 public function getLoginname() {
96 return $_SESSION[login][loginname];
97 }
99 }
102 ?>