diff options
author | xue <> | 2007-06-29 17:41:20 +0000 |
---|---|---|
committer | xue <> | 2007-06-29 17:41:20 +0000 |
commit | 4a9dd5c8513ed96d1e0cf43e370b170dc38fb502 (patch) | |
tree | f41bbf25ac5bbc8d0b656c3e7c087e40b09b38b1 /demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php | |
parent | 2d266a7994c57e9a13cccecacf8940e11263614f (diff) |
finished blog-tutorial.
Diffstat (limited to 'demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php')
-rw-r--r-- | demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php new file mode 100644 index 00000000..a0955490 --- /dev/null +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php @@ -0,0 +1,37 @@ +<?php
+
+class LoginUser extends TPage
+{
+ /**
+ * Validates whether the username and password are correct.
+ * This method responds to the TCustomValidator's OnServerValidate event.
+ * @param mixed event sender
+ * @param mixed event parameter
+ */
+ public function validateUser($sender,$param)
+ {
+ $authManager=$this->Application->getModule('auth');
+ if(!$authManager->login($this->Username->Text,$this->Password->Text))
+ $param->IsValid=false; // tell the validator that validation fails
+ }
+
+ /**
+ * Redirects the user's browser to appropriate URL if login succeeds.
+ * This method responds to the login button's OnClick event.
+ * @param mixed event sender
+ * @param mixed event parameter
+ */
+ public function loginButtonClicked($sender,$param)
+ {
+ if($this->Page->IsValid) // all validations succeed
+ {
+ // obtain the URL of the privileged page that the user wanted to visit originally
+ $url=$this->Application->getModule('auth')->ReturnUrl;
+ if(empty($url)) // the user accesses the login page directly
+ $url=$this->Service->DefaultPageUrl;
+ $this->Response->redirect($url);
+ }
+ }
+}
+
+?>
\ No newline at end of file |