Mercurial > owls
comparison 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 |
comparison
equal
deleted
inserted
replaced
12:682b4a24469c | 13:3e3fa7725abb |
---|---|
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 { | |
9 | |
10 /// Consts | |
11 | |
12 /** | |
13 * time in seconds till the session expires | |
14 */ | |
15 const TIME_SESSION_EXPIRES = 1800; | |
16 | |
17 | |
18 | |
19 /// Constructors | |
20 | |
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 } | |
29 | |
30 | |
31 | |
32 | |
33 /// Methods | |
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 */ | |
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 } | |
50 | |
51 | |
52 /** | |
53 * logs the user out | |
54 */ | |
55 public function logout() { // logout ------------------------------------------------------------ | |
56 unset($_SESSION[login]); | |
57 } | |
58 | |
59 | |
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()-self::TIME_SESSION_EXPIRES); | |
67 } | |
68 | |
69 | |
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 } | |
79 | |
80 | |
81 | |
82 /// Getter and Setter | |
83 | |
84 | |
85 /** | |
86 * @return user id | |
87 */ | |
88 public function getUserId() { | |
89 return $_SESSION[login][id]; | |
90 } | |
91 | |
92 /** | |
93 * @return user name | |
94 */ | |
95 public function getLoginname() { | |
96 return $_SESSION[login][loginname]; | |
97 } | |
98 | |
99 } | |
100 | |
101 | |
102 ?> |