summaryrefslogtreecommitdiff
path: root/demos/chat/protected/pages/Login.php
blob: 4a86dc905efecc686d27e59d50984708a831e8a9 (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
<?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);
		}
	}
}