summaryrefslogtreecommitdiff
path: root/demos/chat/protected/App_Code/ChatUserManager.php
diff options
context:
space:
mode:
authorwei <>2007-01-04 11:23:26 +0000
committerwei <>2007-01-04 11:23:26 +0000
commitdd028bec3822d1d9c28c35d599d687e038c7705f (patch)
treef3d2fb7f95073ea481a4dec86f0f0d30c7fe3588 /demos/chat/protected/App_Code/ChatUserManager.php
parentcac90ea6547fe194ab6ab101dfe11a0b751823ca (diff)
Add chat demo and tutorial.
Diffstat (limited to 'demos/chat/protected/App_Code/ChatUserManager.php')
-rw-r--r--demos/chat/protected/App_Code/ChatUserManager.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/demos/chat/protected/App_Code/ChatUserManager.php b/demos/chat/protected/App_Code/ChatUserManager.php
new file mode 100644
index 00000000..f8fe09cc
--- /dev/null
+++ b/demos/chat/protected/App_Code/ChatUserManager.php
@@ -0,0 +1,63 @@
+<?php
+
+class ChatUserManager extends TModule implements IUserManager
+{
+ /**
+ * @return string name for a guest user.
+ */
+ public function getGuestName()
+ {
+ return 'Guest';
+ }
+
+ /**
+ * Returns a user instance given the user name.
+ * @param string user name, null if it is a guest.
+ * @return TUser the user instance
+ */
+ public function getUser($username=null)
+ {
+ $user=new TUser($this);
+ $user->setIsGuest(true);
+ if($username !== null)
+ {
+ $user->setIsGuest(false);
+ $user->setName($username);
+ $user->setRoles(array('normal'));
+ }
+ return $user;
+ }
+
+ /**
+ * Add a new user to the database.
+ * @param string username.
+ */
+ public function addNewUser($username)
+ {
+ $user = new ChatUserRecord();
+ $user->username = $username;
+ $user->save();
+ }
+
+ /**
+ * @return boolean true if username already exists, false otherwise.
+ */
+ public function usernameExists($username)
+ {
+ return ChatUserRecord::finder()->findByUsername($username) instanceof ChatUserRecord;
+ }
+
+ /**
+ * Validates if the username exists.
+ * @param string user name
+ * @param string password
+ * @return boolean true if validation is successful, false otherwise.
+ */
+ public function validateUser($username,$password)
+ {
+ return $this->usernameExists($username);
+ }
+}
+
+
+?> \ No newline at end of file