| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
class NewUser extends TPage
|
|
|
4 |
{
|
|
|
5 |
/**
|
|
|
6 |
* Checks whether the username exists in the database.
|
|
|
7 |
* This method responds to the OnServerValidate event of username's custom validator.
|
|
|
8 |
* @param mixed event sender
|
|
|
9 |
* @param mixed event parameter
|
|
|
10 |
*/
|
|
|
11 |
public function checkUsername($sender,$param)
|
|
|
12 |
{
|
|
|
13 |
// valid if the username is not found in the database
|
|
|
14 |
$param->IsValid=UserRecord::finder()->findByPk($this->Username->Text)===null;
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Creates a new user account if all inputs are valid.
|
|
|
19 |
* This method responds to the OnClick event of the "create" button.
|
|
|
20 |
* @param mixed event sender
|
|
|
21 |
* @param mixed event parameter
|
|
|
22 |
*/
|
|
|
23 |
public function createButtonClicked($sender,$param)
|
|
|
24 |
{
|
|
|
25 |
if($this->IsValid) // when all validations succeed
|
|
|
26 |
{
|
|
|
27 |
// populates a UserRecord object with user inputs
|
|
|
28 |
$userRecord=new UserRecord;
|
|
|
29 |
$userRecord->username=$this->Username->Text;
|
|
|
30 |
$userRecord->password=$this->Password->Text;
|
|
|
31 |
$userRecord->email=$this->Email->Text;
|
|
|
32 |
$userRecord->role=(int)$this->Role->SelectedValue;
|
|
|
33 |
$userRecord->first_name=$this->FirstName->Text;
|
|
|
34 |
$userRecord->last_name=$this->LastName->Text;
|
|
|
35 |
|
|
|
36 |
// saves to the database via Active Record mechanism
|
|
|
37 |
$userRecord->save();
|
|
|
38 |
|
|
|
39 |
// redirects the browser to the homepage
|
|
|
40 |
$this->Response->redirect($this->Service->DefaultPageUrl);
|
|
|
41 |
}
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
?>
|