summaryrefslogtreecommitdiff
path: root/demos/blog-tutorial/samples/day3/blog/protected/pages/users/LoginUser.php
blob: eed7744a1553a1321c9a2d036638cf76d181caa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?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);
		}
	}
}