Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * UserCreate page class file.
4
 *
5
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6
 * @link http://www.pradosoft.com/
7
 * @copyright Copyright &copy; 2005-2006 PradoSoft
8
 * @license http://www.pradosoft.com/license/
9
 * @version $Id: UserCreate.php 1400 2006-09-09 03:13:44Z wei $
10
 * @package Demos
11
 */
12
 
13
/**
14
 * Create new user wizard page class. Validate that the usernames are unique and
15
 * set the new user credentials as the current application credentials.
16
 *
17
 * If logged in as admin, the user role can be change during creation.
18
 *
19
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
20
 * @version $Id: UserCreate.php 1400 2006-09-09 03:13:44Z wei $
21
 * @package Demos
22
 * @since 3.1
23
 */
24
class UserCreate extends TPage
25
{
26
	/**
27
	 * Sets the default new user roles, default role is set in config.xml
28
	 */
29
	public function onLoad($param)
30
	{
31
		if(!$this->IsPostBack)
32
		{
33
			$this->role->SelectedValue =
34
				$this->Application->Parameters['NewUserRoles'];
35
		}
36
	}
37
 
38
	/**
39
	 * Verify that the username is not taken.
40
	 * @param TControl custom validator that created the event.
41
	 * @param TServerValidateEventParameter validation parameters.
42
	 */
43
	public function checkUsername($sender, $param)
44
	{
45
		$userDao = $this->Application->Modules['daos']->getDao('UserDao');
46
		if($userDao->usernameExists($this->username->Text))
47
		{
48
			$param->IsValid = false;
49
			$sender->ErrorMessage =
50
				"The user name is already taken, try '{$this->username->Text}01'";
51
		}
52
	}
53
 
54
	/**
55
	 * Skip the role assignment step if not admin.
56
	 */
57
	public function userWizardNextStep($sender, $param)
58
	{
59
		if($param->CurrentStepIndex == 0)
60
		{
61
			//create user with admin credentials
62
			if(!$this->User->isInRole('admin'))
63
			{
64
				$this->createNewUser($sender, $param);
65
				$param->NextStepIndex = 2;
66
			}
67
		}
68
	}
69
 
70
	/**
71
	 * Create a new user if all data entered are valid.
72
	 * The default user roles are obtained from "config.xml". The new user
73
	 * details is saved to the database and the new credentials are used as the
74
	 * application user. The user is redirected to the requested page.
75
	 * @param TControl button control that created the event.
76
	 * @param TEventParameter event parameters.
77
	 */
78
	public function createNewUser($sender, $param)
79
	{
80
		if($this->IsValid)
81
		{
82
			$newUser = new TimeTrackerUser($this->User->Manager);
83
			$newUser->EmailAddress = $this->email->Text;
84
			$newUser->Name = $this->username->Text;
85
			$newUser->IsGuest = false;
86
			$newUser->Roles = $this->role->SelectedValue;
87
 
88
			//save the user
89
			$userDao = $this->Application->Modules['daos']->getDao('UserDao');
90
			$userDao->addNewUser($newUser, $this->password->Text);
91
 
92
			//update the user credentials if not admin
93
			if(!$this->User->isInRole('admin'))
94
			{
95
				$auth = $this->Application->getModule('auth');
96
				$auth->updateCredential($newUser);
97
			}
98
		}
99
	}
100
 
101
	/**
102
	 * Continue with requested page.
103
	 */
104
	public function wizardCompleted($sender, $param)
105
	{
106
		//return to requested page
107
		$auth = $this->Application->getModule('auth');
108
		$this->Response->redirect($auth->getReturnUrl());
109
	}
110
}
111
 
112
?>