| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* UserManager class file.
|
|
|
4 |
*
|
|
|
5 |
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2006 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: UserManager.php 2289 2007-10-01 01:04:10Z xue $
|
|
|
10 |
* @package Demos
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* User manager module class for time tracker application.
|
|
|
15 |
*
|
|
|
16 |
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
|
|
|
17 |
* @version $Id: UserManager.php 2289 2007-10-01 01:04:10Z xue $
|
|
|
18 |
* @package Demos
|
|
|
19 |
* @since 3.1
|
|
|
20 |
*/
|
|
|
21 |
class UserManager extends TModule implements IUserManager
|
|
|
22 |
{
|
|
|
23 |
/**
|
|
|
24 |
* @return string name for a guest user.
|
|
|
25 |
*/
|
|
|
26 |
public function getGuestName()
|
|
|
27 |
{
|
|
|
28 |
return 'Guest';
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Returns a user instance given the user name.
|
|
|
33 |
* @param string user name, null if it is a guest.
|
|
|
34 |
* @return TUser the user instance, null if the specified username is not in the user database.
|
|
|
35 |
*/
|
|
|
36 |
public function getUser($username=null)
|
|
|
37 |
{
|
|
|
38 |
if($username===null)
|
|
|
39 |
{
|
|
|
40 |
$user=new TUser($this);
|
|
|
41 |
$user->setIsGuest(true);
|
|
|
42 |
return $user;
|
|
|
43 |
}
|
|
|
44 |
else
|
|
|
45 |
{
|
|
|
46 |
$daos = $this->getApplication()->getModule('daos');
|
|
|
47 |
$userDao = $daos->getDao('UserDao');
|
|
|
48 |
$user = $userDao->getUserByName($username);
|
|
|
49 |
$user->setIsGuest(false);
|
|
|
50 |
return $user;
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Validates if the username and password are correct.
|
|
|
56 |
* @param string user name
|
|
|
57 |
* @param string password
|
|
|
58 |
* @return boolean true if validation is successful, false otherwise.
|
|
|
59 |
*/
|
|
|
60 |
public function validateUser($username,$password)
|
|
|
61 |
{
|
|
|
62 |
$daos = $this->getApplication()->getModule('daos');
|
|
|
63 |
$userDao = $daos->getDao('UserDao');
|
|
|
64 |
return $userDao->validateUser($username, $password);
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Saves user auth data into a cookie.
|
|
|
69 |
* @param THttpCookie the cookie to receive the user auth data.
|
|
|
70 |
* @since 3.1.1
|
|
|
71 |
*/
|
|
|
72 |
public function saveUserToCookie($cookie)
|
|
|
73 |
{
|
|
|
74 |
// do nothing since we don't support cookie-based auth in this example
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Returns a user instance according to auth data stored in a cookie.
|
|
|
79 |
* @param THttpCookie the cookie storing user authentication information
|
|
|
80 |
* @return TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
|
|
|
81 |
* @since 3.1.1
|
|
|
82 |
*/
|
|
|
83 |
public function getUserFromCookie($cookie)
|
|
|
84 |
{
|
|
|
85 |
// do nothing since we don't support cookie-based auth in this example
|
|
|
86 |
return null;
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
?>
|