Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
class ChatUserManager extends TModule implements IUserManager
4
{
5
	/**
6
	 * @return string name for a guest user.
7
	 */
8
	public function getGuestName()
9
	{
10
		return 'Guest';
11
	}
12
 
13
	/**
14
	 * Returns a user instance given the user name.
15
	 * @param string user name, null if it is a guest.
16
	 * @return TUser the user instance
17
	 */
18
	public function getUser($username=null)
19
	{
20
		$user=new TUser($this);
21
		$user->setIsGuest(true);
22
		if($username !== null)
23
		{
24
			$user->setIsGuest(false);
25
			$user->setName($username);
26
			$user->setRoles(array('normal'));
27
		}
28
		return $user;
29
	}
30
 
31
	/**
32
	 * Add a new user to the database.
33
	 * @param string username.
34
	 */
35
	public function addNewUser($username)
36
	{
37
		$user = new ChatUserRecord();
38
		$user->username = $username;
39
		$user->save();
40
	}
41
 
42
	/**
43
	 * @return boolean true if username already exists, false otherwise.
44
	 */
45
	public function usernameExists($username)
46
	{
47
		return ChatUserRecord::finder()->findByUsername($username) instanceof ChatUserRecord;
48
	}
49
 
50
	/**
51
	 * Validates if the username exists.
52
	 * @param string user name
53
	 * @param string password
54
	 * @return boolean true if validation is successful, false otherwise.
55
	 */
56
	public function validateUser($username,$password)
57
	{
58
		return $this->usernameExists($username);
59
	}
60
 
61
	/**
62
	 * Saves user auth data into a cookie.
63
	 * @param THttpCookie the cookie to receive the user auth data.
64
	 * @since 3.1.1
65
	 */
66
	public function saveUserToCookie($cookie)
67
	{
68
		// do nothing since we don't support cookie-based auth in this example
69
	}
70
 
71
	/**
72
	 * Returns a user instance according to auth data stored in a cookie.
73
	 * @param THttpCookie the cookie storing user authentication information
74
	 * @return TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
75
	 * @since 3.1.1
76
	 */
77
	public function getUserFromCookie($cookie)
78
	{
79
		// do nothing since we don't support cookie-based auth in this example
80
		return null;
81
	}
82
}
83
 
84
 
85
?>