2012-02-05 18:37:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
2012-02-06 00:09:21 +01:00
|
|
|
class Page_TasksUsers
|
|
|
|
extends AuthenticatedPage
|
2012-02-05 18:37:25 +01:00
|
|
|
{
|
2012-02-06 00:09:21 +01:00
|
|
|
public function __construct( )
|
2012-02-05 18:37:25 +01:00
|
|
|
{
|
2012-02-06 00:09:21 +01:00
|
|
|
parent::__construct( array(
|
|
|
|
'' => 'users_list' ,
|
|
|
|
'add' => 'users_add_form' ,
|
|
|
|
) );
|
|
|
|
$this->setTitle( 'Users' );
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
2012-02-06 00:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Ctrl_UsersList
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
$dao = Loader::DAO( 'users' );
|
|
|
|
return Loader::View( 'box' , null , Loader::View( 'users_list' , $dao->getUsers( ) ) )
|
|
|
|
->setClass( 'list' )
|
|
|
|
->addButton( BoxButton::create( 'Add user' , 'users/add' )
|
|
|
|
->setClass( 'list-add' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Ctrl_UsersAddForm
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
return Loader::Create( 'Form' , 'Create user' , 'user-add' )
|
|
|
|
->addField( Loader::Create( 'Field' , 'email' , 'text' )
|
|
|
|
->setDescription( 'E-mail address:' )
|
|
|
|
->setValidator( Loader::Create( 'Validator_Email' , 'Invalid address.' ) ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'pass' , 'password' )
|
|
|
|
->setDescription( 'Password:' )
|
|
|
|
->setValidator( Loader::Create( 'Validator_StringLength' , 'This password' , 8 ) ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'pass2' , 'password' )
|
|
|
|
->setDescription( 'Confirm password:' ) )
|
|
|
|
->setURL( 'users' )
|
|
|
|
->addController( Loader::Ctrl( 'users_add' ) )
|
|
|
|
->controller( );
|
|
|
|
}
|
|
|
|
}
|
2012-02-05 18:37:25 +01:00
|
|
|
|
|
|
|
|
2012-02-06 00:09:21 +01:00
|
|
|
class Ctrl_UsersAdd
|
|
|
|
extends Controller
|
|
|
|
implements FormAware
|
|
|
|
{
|
|
|
|
private $form;
|
|
|
|
|
|
|
|
public function setForm( Form $form )
|
2012-02-05 18:37:25 +01:00
|
|
|
{
|
2012-02-06 00:09:21 +01:00
|
|
|
$this->form = $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
$p1 = $this->form->field( 'pass' );
|
|
|
|
$p2 = $this->form->field( 'pass2' );
|
|
|
|
if ( $p1->value( ) != $p2->value( ) ) {
|
|
|
|
$p1->putError( 'Passwords did not match.' );
|
2012-02-05 18:37:25 +01:00
|
|
|
return null;
|
|
|
|
}
|
2012-02-06 00:09:21 +01:00
|
|
|
|
|
|
|
$email = $this->form->field( 'email' );
|
|
|
|
$error = Loader::DAO( 'users' )->addUser( $email->value( ) ,
|
|
|
|
$p1->value( ) );
|
|
|
|
|
|
|
|
switch ( $error ) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
$email->putError( 'This e-mail address is already in use.' );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$email->putError( 'Some unknown error has occurred (' . $error . ')' );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return null;
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
|
|
|
|
2012-02-06 00:09:21 +01:00
|
|
|
}
|
|
|
|
|
2012-02-05 18:37:25 +01:00
|
|
|
|
2012-02-06 00:09:21 +01:00
|
|
|
|
|
|
|
class View_UsersList
|
|
|
|
extends BaseURLAwareView
|
|
|
|
{
|
|
|
|
private $users;
|
|
|
|
|
|
|
|
public function __construct( $users )
|
2012-02-05 18:37:25 +01:00
|
|
|
{
|
2012-02-06 00:09:21 +01:00
|
|
|
$this->users = $users;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render( )
|
|
|
|
{
|
|
|
|
$table = HTML::make( 'table' )
|
|
|
|
->appendElement( HTML::make( 'tr' )
|
|
|
|
->setAttribute( 'class' , 'header' )
|
|
|
|
->appendElement( HTML::make( 'th' )
|
|
|
|
->appendText( 'E-mail address' ) ) );
|
|
|
|
|
|
|
|
foreach ( $this->users as $user ) {
|
|
|
|
$table->appendElement( HTML::make( 'tr' )
|
|
|
|
->appendElement( HTML::make( 'td' )
|
|
|
|
->appendText( $user->user_email ) ) );
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
2012-02-06 00:09:21 +01:00
|
|
|
|
|
|
|
return $table;
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
|
|
|
}
|