diff options
author | xue <> | 2007-06-26 15:59:16 +0000 |
---|---|---|
committer | xue <> | 2007-06-26 15:59:16 +0000 |
commit | f92ca63a225d43e7ecca4ebe528c2a1e206a40f1 (patch) | |
tree | 0fb92aafab5fedc866c6cafd49433d72bf719114 /demos/blog-tutorial/samples/day4/blog/protected/BlogUser.php | |
parent | c31e5ab3ebd4ae1561cbdaeaa504d1095dcbbb0a (diff) |
Completed day 4 for blog tutorial.
Diffstat (limited to 'demos/blog-tutorial/samples/day4/blog/protected/BlogUser.php')
-rw-r--r-- | demos/blog-tutorial/samples/day4/blog/protected/BlogUser.php | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/demos/blog-tutorial/samples/day4/blog/protected/BlogUser.php b/demos/blog-tutorial/samples/day4/blog/protected/BlogUser.php new file mode 100644 index 00000000..6b9e0a23 --- /dev/null +++ b/demos/blog-tutorial/samples/day4/blog/protected/BlogUser.php @@ -0,0 +1,59 @@ +<?php
+
+// Include TDbUserManager.php file which defines TDbUser
+Prado::using('System.Security.TDbUserManager');
+
+/**
+ * BlogUser Class.
+ * BlogUser represents the user data that needs to be kept in session.
+ * Default implementation keeps username and role information.
+ */
+class BlogUser extends TDbUser
+{
+ /**
+ * Creates a BlogUser object based on the specified username.
+ * This method is required by TDbUser. It checks the database
+ * to see if the specified username is there. If so, a BlogUser
+ * object is created and initialized.
+ * @param string the specified username
+ * @return BlogUser the user object, null if username is invalid.
+ */
+ public function createUser($username)
+ {
+ // use UserRecord Active Record to look for the specified username
+ $userRecord=UserRecord::finder()->findByPk($username);
+ if($userRecord instanceof UserRecord) // if found
+ {
+ $user=new BlogUser($this->Manager);
+ $user->Name=$username; // set username
+ $user->Roles=($userRecord->role==1?'admin':'user'); // set role
+ $user->IsGuest=false; // the user is not a guest
+ return $user;
+ }
+ else
+ return null;
+ }
+
+ /**
+ * Checks if the specified (username, password) is valid.
+ * This method is required by TDbUser.
+ * @param string username
+ * @param string password
+ * @return boolean whether the username and password are valid.
+ */
+ public function validateUser($username,$password)
+ {
+ // use UserRecord Active Record to look for the (username, password) pair.
+ return UserRecord::finder()->findBy_username_AND_password($username,$password)!==null;
+ }
+
+ /**
+ * @return boolean whether this user is an administrator.
+ */
+ public function getIsAdmin()
+ {
+ return $this->isInRole('admin');
+ }
+}
+
+?>
\ No newline at end of file |