Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
// Include TDbUserManager.php file which defines TDbUser
4
Prado::using('System.Security.TDbUserManager');
5
 
6
/**
7
 * BlogUser Class.
8
 * BlogUser represents the user data that needs to be kept in session.
9
 * Default implementation keeps username and role information.
10
 */
11
class BlogUser extends TDbUser
12
{
13
	/**
14
	 * Creates a BlogUser object based on the specified username.
15
	 * This method is required by TDbUser. It checks the database
16
	 * to see if the specified username is there. If so, a BlogUser
17
	 * object is created and initialized.
18
	 * @param string the specified username
19
	 * @return BlogUser the user object, null if username is invalid.
20
	 */
21
	public function createUser($username)
22
	{
23
		// use UserRecord Active Record to look for the specified username
24
		$userRecord=UserRecord::finder()->findByPk($username);
25
		if($userRecord instanceof UserRecord) // if found
26
		{
27
			$user=new BlogUser($this->Manager);
28
			$user->Name=$username;  // set username
29
			$user->Roles=($userRecord->role==1?'admin':'user'); // set role
30
			$user->IsGuest=false;   // the user is not a guest
31
			return $user;
32
		}
33
		else
34
			return null;
35
	}
36
 
37
	/**
38
	 * Checks if the specified (username, password) is valid.
39
	 * This method is required by TDbUser.
40
	 * @param string username
41
	 * @param string password
42
	 * @return boolean whether the username and password are valid.
43
	 */
44
	public function validateUser($username,$password)
45
	{
46
		// use UserRecord Active Record to look for the (username, password) pair.
47
		return UserRecord::finder()->findBy_username_AND_password($username,$password)!==null;
48
	}
49
 
50
	/**
51
	 * @return boolean whether this user is an administrator.
52
	 */
53
	public function getIsAdmin()
54
	{
55
		return $this->isInRole('admin');
56
	}
57
}
58
 
59
?>