Admin user's username made selectable from installer.
Signed-off-by: Mehmet Durgel <md@legrud.net>
This commit is contained in:
parent
91e1911308
commit
9e20b7ddec
|
@ -43,8 +43,9 @@ function deleteUser($args, $deleteContent=false)
|
||||||
global $Language;
|
global $Language;
|
||||||
global $Login;
|
global $Login;
|
||||||
|
|
||||||
|
$AdminUsername = $dbUsers->getAdminUser()['username'];
|
||||||
// The user admin cannot be deleted.
|
// The user admin cannot be deleted.
|
||||||
if($args['username']=='admin') {
|
if($args['username']==$AdminUsername) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ function deleteUser($args, $deleteContent=false)
|
||||||
$dbPosts->deletePostsByUser($args['username']);
|
$dbPosts->deletePostsByUser($args['username']);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$dbPosts->linkPostsToUser($args['username'], 'admin');
|
$dbPosts->linkPostsToUser($args['username'], $AdminUsername);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $dbUsers->delete($args['username']) ) {
|
if( $dbUsers->delete($args['username']) ) {
|
||||||
|
|
|
@ -521,6 +521,8 @@ class dbPages extends dbJSON
|
||||||
|
|
||||||
public function regenerateCli()
|
public function regenerateCli()
|
||||||
{
|
{
|
||||||
|
global $dbUsers;
|
||||||
|
$AdminUsername = $dbUsers->getAdminUser()['username'];
|
||||||
$db = $this->db;
|
$db = $this->db;
|
||||||
$newPaths = array();
|
$newPaths = array();
|
||||||
$fields = array();
|
$fields = array();
|
||||||
|
@ -564,7 +566,7 @@ class dbPages extends dbJSON
|
||||||
// Default values for the new pages.
|
// Default values for the new pages.
|
||||||
$fields['status'] = CLI_STATUS;
|
$fields['status'] = CLI_STATUS;
|
||||||
$fields['date'] = Date::current(DB_DATE_FORMAT);
|
$fields['date'] = Date::current(DB_DATE_FORMAT);
|
||||||
$fields['username'] = 'admin';
|
$fields['username'] = $AdminUsername;
|
||||||
|
|
||||||
// Create the entry for the new page.
|
// Create the entry for the new page.
|
||||||
$this->db[$key] = $fields;
|
$this->db[$key] = $fields;
|
||||||
|
|
|
@ -72,6 +72,18 @@ class dbUsers extends dbJSON
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return first the username associated with the role 'admin', if a user with 'admin' role not found return FALSE.
|
||||||
|
public function getAdminUser()
|
||||||
|
{
|
||||||
|
foreach($this->db as $username=>$values) {
|
||||||
|
if($values['role']=='admin') {
|
||||||
|
return $username;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Return TRUE if the user exists, FALSE otherwise.
|
// Return TRUE if the user exists, FALSE otherwise.
|
||||||
public function userExists($username)
|
public function userExists($username)
|
||||||
{
|
{
|
||||||
|
|
21
install.php
21
install.php
|
@ -237,7 +237,7 @@ function checkSystem()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finish with the installation.
|
// Finish with the installation.
|
||||||
function install($adminPassword, $email, $timezone)
|
function install($adminUsername, $adminPassword, $email, $timezone)
|
||||||
{
|
{
|
||||||
global $Language;
|
global $Language;
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ function install($adminPassword, $email, $timezone)
|
||||||
$data = array(
|
$data = array(
|
||||||
'error'=>array(
|
'error'=>array(
|
||||||
'description'=>'Error page',
|
'description'=>'Error page',
|
||||||
'username'=>'admin',
|
'username'=>$adminUsername,
|
||||||
'tags'=>array(),
|
'tags'=>array(),
|
||||||
'status'=>'published',
|
'status'=>'published',
|
||||||
'date'=>$currentDate,
|
'date'=>$currentDate,
|
||||||
|
@ -339,7 +339,7 @@ function install($adminPassword, $email, $timezone)
|
||||||
),
|
),
|
||||||
'about'=>array(
|
'about'=>array(
|
||||||
'description'=>$Language->get('About your site or yourself'),
|
'description'=>$Language->get('About your site or yourself'),
|
||||||
'username'=>'admin',
|
'username'=>$adminUsername,
|
||||||
'tags'=>array(),
|
'tags'=>array(),
|
||||||
'status'=>'published',
|
'status'=>'published',
|
||||||
'date'=>$currentDate,
|
'date'=>$currentDate,
|
||||||
|
@ -357,7 +357,7 @@ function install($adminPassword, $email, $timezone)
|
||||||
$data = array(
|
$data = array(
|
||||||
$firstPostSlug=>array(
|
$firstPostSlug=>array(
|
||||||
'description'=>$Language->get('Welcome to Bludit'),
|
'description'=>$Language->get('Welcome to Bludit'),
|
||||||
'username'=>'admin',
|
'username'=>$adminUsername,
|
||||||
'status'=>'published',
|
'status'=>'published',
|
||||||
'tags'=>array('bludit'=>'Bludit','cms'=>'CMS','flat-files'=>'Flat files'),
|
'tags'=>array('bludit'=>'Bludit','cms'=>'CMS','flat-files'=>'Flat files'),
|
||||||
'allowComments'=>'false',
|
'allowComments'=>'false',
|
||||||
|
@ -399,7 +399,7 @@ function install($adminPassword, $email, $timezone)
|
||||||
$passwordHash = sha1($adminPassword.$salt);
|
$passwordHash = sha1($adminPassword.$salt);
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'admin'=>array(
|
$adminUsername=>array(
|
||||||
'firstName'=>$Language->get('Administrator'),
|
'firstName'=>$Language->get('Administrator'),
|
||||||
'lastName'=>'',
|
'lastName'=>'',
|
||||||
'role'=>'admin',
|
'role'=>'admin',
|
||||||
|
@ -551,6 +551,11 @@ function checkPOST($args)
|
||||||
{
|
{
|
||||||
global $Language;
|
global $Language;
|
||||||
|
|
||||||
|
// Check empty username
|
||||||
|
if( strlen($args['username']) < 6 )
|
||||||
|
{
|
||||||
|
return '<div>'.$Language->g('Username must be at least 6 characters long').'</div>';
|
||||||
|
}
|
||||||
// Check empty password
|
// Check empty password
|
||||||
if( strlen($args['password']) < 6 )
|
if( strlen($args['password']) < 6 )
|
||||||
{
|
{
|
||||||
|
@ -567,7 +572,7 @@ function checkPOST($args)
|
||||||
$email = sanitize::email($args['email']);
|
$email = sanitize::email($args['email']);
|
||||||
|
|
||||||
// Install Bludit
|
// Install Bludit
|
||||||
install($args['password'], $email, $args['timezone']);
|
install($args['username'], $args['password'], $email, $args['timezone']);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -665,7 +670,7 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
|
||||||
<input type="hidden" name="timezone" id="jstimezone" value="0">
|
<input type="hidden" name="timezone" id="jstimezone" value="0">
|
||||||
|
|
||||||
<div class="uk-form-row">
|
<div class="uk-form-row">
|
||||||
<input type="text" value="admin" class="uk-width-1-1 uk-form-large" disabled>
|
<input name="username" id="jsusername" type="text" class="uk-width-1-1 uk-form-large" value="<?php echo isset($_POST['username'])?$_POST['username']:'' ?>" placeholder="<?php echo $Language->get('Username') ?>">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="uk-form-row">
|
<div class="uk-form-row">
|
||||||
|
@ -747,4 +752,4 @@ $(document).ready(function()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue