"Installer" added
A very basic installer will appear when accessing the home page if there are no users in the database. It allows the initial user to be created.
This commit is contained in:
parent
071577168a
commit
1271afd1d8
6 changed files with 60 additions and 7 deletions
2
arse
2
arse
|
@ -1 +1 @@
|
||||||
Subproject commit f80d739f5d7b6241c154e2e38e0b1d5b6325142b
|
Subproject commit 62a4d0a39166df5bcb9c9a89431b32ec6fab8acb
|
|
@ -10,8 +10,10 @@ class Ctrl_HomePage
|
||||||
session_start( );
|
session_start( );
|
||||||
if ( array_key_exists( 'uid' , $_SESSION ) ) {
|
if ( array_key_exists( 'uid' , $_SESSION ) ) {
|
||||||
return 'items';
|
return 'items';
|
||||||
} else {
|
} elseif ( Loader::DAO( 'users' )->hasUsers( ) ) {
|
||||||
return 'login';
|
return 'login';
|
||||||
|
} else {
|
||||||
|
return 'install';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,3 +121,17 @@ class Ctrl_LoggedOut
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Ctrl_Install
|
||||||
|
extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
public function handle( Page $page )
|
||||||
|
{
|
||||||
|
if ( Loader::DAO( 'users' )->hasUsers( ) ) {
|
||||||
|
return 'login';
|
||||||
|
}
|
||||||
|
return Loader::Ctrl( 'users_add_form' , true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -74,6 +74,6 @@ class Dao_Users
|
||||||
public function hasUsers( )
|
public function hasUsers( )
|
||||||
{
|
{
|
||||||
$result = $this->query( 'SELECT COUNT(*) AS n_users FROM users' )->execute( );
|
$result = $this->query( 'SELECT COUNT(*) AS n_users FROM users' )->execute( );
|
||||||
return $result[0]->n_users;
|
return $result[0]->n_users > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ $package[ 'extras' ][] = 'AuthenticatedPage';
|
||||||
|
|
||||||
$package[ 'ctrls' ][] = 'check_session';
|
$package[ 'ctrls' ][] = 'check_session';
|
||||||
$package[ 'ctrls' ][] = 'home_page';
|
$package[ 'ctrls' ][] = 'home_page';
|
||||||
|
$package[ 'ctrls' ][] = 'install';
|
||||||
$package[ 'ctrls' ][] = 'log_in';
|
$package[ 'ctrls' ][] = 'log_in';
|
||||||
$package[ 'ctrls' ][] = 'log_in_form';
|
$package[ 'ctrls' ][] = 'log_in_form';
|
||||||
$package[ 'ctrls' ][] = 'logged_out';
|
$package[ 'ctrls' ][] = 'logged_out';
|
||||||
|
@ -19,5 +20,6 @@ $package[ 'ctrls' ][] = 'logout';
|
||||||
$package[ 'pages' ][] = 'tasks_home';
|
$package[ 'pages' ][] = 'tasks_home';
|
||||||
$package[ 'pages' ][] = 'tasks_login';
|
$package[ 'pages' ][] = 'tasks_login';
|
||||||
$package[ 'pages' ][] = 'tasks_logout';
|
$package[ 'pages' ][] = 'tasks_logout';
|
||||||
|
$package[ 'pages' ][] = 'tasks_install';
|
||||||
|
|
||||||
$package[ 'daos' ][] = 'users';
|
$package[ 'daos' ][] = 'users';
|
||||||
|
|
|
@ -66,3 +66,14 @@ class Page_TasksLogout
|
||||||
$this->addController( Loader::Ctrl( 'logout' ) );
|
$this->addController( Loader::Ctrl( 'logout' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Page_TasksInstall
|
||||||
|
extends Page_Basic
|
||||||
|
{
|
||||||
|
public function __construct( )
|
||||||
|
{
|
||||||
|
parent::__construct( );
|
||||||
|
$this->addController( Loader::Ctrl( 'install' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -34,9 +34,16 @@ class Ctrl_UsersList
|
||||||
class Ctrl_UsersAddForm
|
class Ctrl_UsersAddForm
|
||||||
extends Controller
|
extends Controller
|
||||||
{
|
{
|
||||||
|
private $initial;
|
||||||
|
|
||||||
|
public function __construct( $initial = false )
|
||||||
|
{
|
||||||
|
$this->initial = $initial;
|
||||||
|
}
|
||||||
|
|
||||||
public function handle( Page $page )
|
public function handle( Page $page )
|
||||||
{
|
{
|
||||||
return Loader::Create( 'Form' , 'Create user' , 'user-add' )
|
$form = Loader::Create( 'Form' , 'Create user' , 'user-add' )
|
||||||
->addField( Loader::Create( 'Field' , 'email' , 'text' )
|
->addField( Loader::Create( 'Field' , 'email' , 'text' )
|
||||||
->setDescription( 'E-mail address:' )
|
->setDescription( 'E-mail address:' )
|
||||||
->setValidator( Loader::Create( 'Validator_Email' , 'Invalid address.' ) ) )
|
->setValidator( Loader::Create( 'Validator_Email' , 'Invalid address.' ) ) )
|
||||||
|
@ -45,9 +52,16 @@ class Ctrl_UsersAddForm
|
||||||
->setValidator( Loader::Create( 'Validator_StringLength' , 'This password' , 8 ) ) )
|
->setValidator( Loader::Create( 'Validator_StringLength' , 'This password' , 8 ) ) )
|
||||||
->addField( Loader::Create( 'Field' , 'pass2' , 'password' )
|
->addField( Loader::Create( 'Field' , 'pass2' , 'password' )
|
||||||
->setDescription( 'Confirm password:' ) )
|
->setDescription( 'Confirm password:' ) )
|
||||||
->setURL( 'users' )
|
->addController( Loader::Ctrl( 'users_add' , $this->initial ) );
|
||||||
->addController( Loader::Ctrl( 'users_add' ) )
|
|
||||||
->controller( );
|
if ( $this->initial ) {
|
||||||
|
$form->setSuccessURL( 'home' );
|
||||||
|
$page->setTitle( 'Initial user' );
|
||||||
|
} else {
|
||||||
|
$form->setURL( 'users' );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $form->controller( );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +71,12 @@ class Ctrl_UsersAdd
|
||||||
implements FormAware
|
implements FormAware
|
||||||
{
|
{
|
||||||
private $form;
|
private $form;
|
||||||
|
private $initial;
|
||||||
|
|
||||||
|
public function __construct( $initial )
|
||||||
|
{
|
||||||
|
$this->initial = $initial;
|
||||||
|
}
|
||||||
|
|
||||||
public function setForm( Form $form )
|
public function setForm( Form $form )
|
||||||
{
|
{
|
||||||
|
@ -80,6 +100,10 @@ class Ctrl_UsersAdd
|
||||||
switch ( $error ) {
|
switch ( $error ) {
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
|
if ( $this->initial ) {
|
||||||
|
session_start( );
|
||||||
|
$_SESSION[ 'uid' ] = Loader::DAO( 'users' )->getUser( $email->value( ) )->user_id;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
|
Loading…
Reference in a new issue