| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* BlogUserManager class file
|
|
|
4 |
*
|
|
|
5 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2006 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: BlogUserManager.php 2289 2007-10-01 01:04:10Z xue $
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
Prado::using('System.Security.IUserManager');
|
|
|
13 |
Prado::using('Application.Common.BlogUser');
|
|
|
14 |
|
|
|
15 |
/**
|
|
|
16 |
* BlogUserManager class
|
|
|
17 |
*
|
|
|
18 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
19 |
* @link http://www.pradosoft.com/
|
|
|
20 |
* @copyright Copyright © 2006 PradoSoft
|
|
|
21 |
* @license http://www.pradosoft.com/license/
|
|
|
22 |
*/
|
|
|
23 |
class BlogUserManager extends TModule implements IUserManager
|
|
|
24 |
{
|
|
|
25 |
public function getGuestName()
|
|
|
26 |
{
|
|
|
27 |
return 'Guest';
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Returns a user instance given the user name.
|
|
|
32 |
* @param string user name, null if it is a guest.
|
|
|
33 |
* @return TUser the user instance, null if the specified username is not in the user database.
|
|
|
34 |
*/
|
|
|
35 |
public function getUser($username=null)
|
|
|
36 |
{
|
|
|
37 |
if($username===null)
|
|
|
38 |
return new BlogUser($this);
|
|
|
39 |
else
|
|
|
40 |
{
|
|
|
41 |
$username=strtolower($username);
|
|
|
42 |
$db=$this->Application->getModule('data');
|
|
|
43 |
if(($userRecord=$db->queryUserByName($username))!==null)
|
|
|
44 |
{
|
|
|
45 |
$user=new BlogUser($this);
|
|
|
46 |
$user->setID($userRecord->ID);
|
|
|
47 |
$user->setName($username);
|
|
|
48 |
$user->setIsGuest(false);
|
|
|
49 |
$user->setRoles($userRecord->Role===UserRecord::ROLE_USER?'user':'admin');
|
|
|
50 |
return $user;
|
|
|
51 |
}
|
|
|
52 |
else
|
|
|
53 |
return null;
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* Validates if the username and password are correct.
|
|
|
59 |
* @param string user name
|
|
|
60 |
* @param string password
|
|
|
61 |
* @return boolean true if validation is successful, false otherwise.
|
|
|
62 |
*/
|
|
|
63 |
public function validateUser($username,$password)
|
|
|
64 |
{
|
|
|
65 |
$db=$this->Application->getModule('data');
|
|
|
66 |
if(($userRecord=$db->queryUserByName($username))!==null)
|
|
|
67 |
return $userRecord->Password===md5($password) && $userRecord->Status===UserRecord::STATUS_NORMAL;
|
|
|
68 |
else
|
|
|
69 |
return false;
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
/**
|
|
|
73 |
* Saves user auth data into a cookie.
|
|
|
74 |
* @param THttpCookie the cookie to receive the user auth data.
|
|
|
75 |
* @since 3.1.1
|
|
|
76 |
*/
|
|
|
77 |
public function saveUserToCookie($cookie)
|
|
|
78 |
{
|
|
|
79 |
// do nothing since we don't support cookie-based auth in this example
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
/**
|
|
|
83 |
* Returns a user instance according to auth data stored in a cookie.
|
|
|
84 |
* @param THttpCookie the cookie storing user authentication information
|
|
|
85 |
* @return TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
|
|
|
86 |
* @since 3.1.1
|
|
|
87 |
*/
|
|
|
88 |
public function getUserFromCookie($cookie)
|
|
|
89 |
{
|
|
|
90 |
// do nothing since we don't support cookie-based auth in this example
|
|
|
91 |
return null;
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
?>
|