summaryrefslogtreecommitdiff
path: root/demos/chat/protected/pages/Login.php
blob: ec39f1f052d273d10d02cabaef9c6820b3f01cf5 (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
37
38
39
40
<?php

class Login extends TPage
{
	/**
	 * Check that the username is not already taken.
	 * @param TControl custom validator that created the event.
	 * @param TServerValidateEventParameter validation parameters. 
	 */
	function checkUsername($sender, $param)
	{
		$manager = $this->Application->Modules['users'];
		if($manager->usernameExists($this->username->Text))
			$param->IsValid = false;
	}

	/**
	 * Create and login a new user, then redirect to the requested page.
	 * @param TControl button control that created the event.
	 * @param TEventParameter event parameters.
	 */
	function createNewUser($sender, $param)
	{
		if($this->Page->IsValid)
		{
			$manager = $this->Application->Modules['users'];
			$manager->addNewUser($this->username->Text);
			
			//do manual login
			$user = $manager->getUser($this->username->Text);
			$auth = $this->Application->Modules['auth'];
			$auth->updateSessionUser($user);
			$this->Application->User = $user;

			$this->Response->redirect($auth->ReturnUrl);
		}
	}
}

?>