check user is logged

This commit is contained in:
Diego Najar 2018-06-24 13:37:45 +02:00
parent 02464b637b
commit 3635084bec
16 changed files with 157 additions and 111 deletions

View File

@ -1,8 +1,9 @@
<!-- Alert -->
<script>
function showAlert(text) {
console.log("[INFO] Function showAlert() called.");
$("#alert").html(text);
$("#alert").slideDown().delay(3500).slideUp();
$("#alert").slideDown().delay(<?php echo $GLOBALS['ALERT_DISSAPEAR_IN']*1000 ?>).slideUp();
}
<?php if (Alert::defined()): ?>

View File

@ -28,7 +28,7 @@
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'categories' ?>"><?php $L->p('Categories') ?></a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'Users' ?>"><?php $L->p('Users') ?></a>
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'users' ?>"><?php $L->p('Users') ?></a>
</li>
<li class="nav-item mt-3">

View File

@ -0,0 +1,8 @@
<!-- Check if the user is logged -->
<script>
setInterval(
function() {
var ajax = new bluditAjax();
ajax.userLogged(showAlert);
}, 15000);
</script>

View File

@ -75,6 +75,10 @@
</div>
</div>
<!-- Check user logged and Internet connection -->
<?php include('html/user-logged.php'); ?>
<!-- Plugins -->
<?php Theme::plugins('adminBodyEnd') ?>

View File

@ -1,6 +1,6 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
echo Bootstrap::pageTitle(array('title'=>$L->g('Categories'), 'icon'=>'grid-three-up'));
echo Bootstrap::pageTitle(array('title'=>$L->g('Categories'), 'icon'=>'tags'));
echo Bootstrap::link(array(
'title'=>'Add a new category',

View File

@ -1,6 +1,6 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
echo Bootstrap::pageTitle(array('title'=>$L->g('Edit Category'), 'icon'=>'grid-three-up'));
echo Bootstrap::pageTitle(array('title'=>$L->g('Edit Category'), 'icon'=>'tags'));
echo Bootstrap::formOpen(array());

View File

@ -113,7 +113,7 @@
echo Bootstrap::formInputText(array(
'name'=>'tags',
'label'=>'Tags',
'placeholder'=>'Tags separeted by comma'
'placeholder'=>'Write the tags separeted by comma'
));
// Description

View File

@ -254,6 +254,15 @@ echo Bootstrap::pageTitle(array('title'=>$L->g('Settings'), 'icon'=>'cog'));
'tip'=>''
));
echo Bootstrap::formInputText(array(
'name'=>'gitlab',
'label'=>'Gitlab',
'value'=>$Site->gitlab(),
'class'=>'',
'placeholder'=>'',
'tip'=>''
));
echo Bootstrap::formInputText(array(
'name'=>'github',
'label'=>'Github',

View File

@ -0,0 +1,24 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
header('Content-Type: application/json');
/*
*
* This script check if the user is logged
*
*/
// Check UUID
if ($Login->isLogged()) {
exit (json_encode(array(
'status'=>1,
'message'=>'The user is logged.'
)));
}
exit (json_encode(array(
'status'=>0,
'message'=>'The user is NOT logged.'
)));
?>

View File

@ -33,10 +33,11 @@ if ($layout['slug']==='ajax') {
include(PATH_RULES.'99.security.php');
// Load the ajax file
if( Sanitize::pathFile(PATH_AJAX, $layout['parameters'].'.php') ) {
if (Sanitize::pathFile(PATH_AJAX, $layout['parameters'].'.php')) {
include(PATH_AJAX.$layout['parameters'].'.php');
}
}
header('HTTP/1.1 401 User not logged.');
exit(0);
}
// --- ADMIN AREA ---

View File

@ -114,3 +114,6 @@ $GLOBALS['THUMBNAILS_QUALITY'] = 100;
// Autosave
$GLOBALS['AUTOSAVE_TIME'] = 2; // Minutes
// Alert
$GLOBALS['ALERT_DISSAPEAR_IN'] = 3; // Seconds

View File

@ -30,6 +30,7 @@ class dbSite extends dbJSON
'googlePlus'=> array('inFile'=>false, 'value'=>''),
'instagram'=> array('inFile'=>false, 'value'=>''),
'github'=> array('inFile'=>false, 'value'=>''),
'gitlab'=> array('inFile'=>false, 'value'=>''),
'linkedin'=> array('inFile'=>false, 'value'=>''),
'orderBy'=> array('inFile'=>false, 'value'=>'date'), // date or position
'extremeFriendly'=> array('inFile'=>false, 'value'=>true)
@ -131,6 +132,11 @@ class dbSite extends dbJSON
return $this->getField('github');
}
public function gitlab()
{
return $this->getField('gitlab');
}
public function googlePlus()
{
return $this->getField('googlePlus');

View File

@ -1,7 +1,7 @@
class bluditAjax {
// Autosave works only when the content has more than 100 characters
// callBack function need to be showAlert() is the function to display an alert defined in alert.php
// callBack function need to be showAlert(), this function is for display alerts to the user, defined in alert.php
autosave(uuid, title, content, callBack) {
var ajaxRequest;
if (ajaxRequest) {
@ -38,6 +38,40 @@ class bluditAjax {
});
}
// Alert the user when the user is not logged
userLogged(callBack) {
var ajaxRequest;
if (ajaxRequest) {
ajaxRequest.abort();
}
console.log("[INFO] Bludit AJAX: userLogged(): running");
ajaxRequest = $.ajax({
type: "POST",
data: {
tokenCSRF: tokenCSRF // token from env variables
},
url: "<?php echo HTML_PATH_ADMIN_ROOT ?>ajax/user-logged"
});
ajaxRequest.done(function (response, textStatus, jqXHR) {
console.log("[INFO] Bludit AJAX: userLogged(): done handler");
});
ajaxRequest.fail(function (jqXHR, textStatus, errorThrown) {
// The fail is produced by admin.php when the user is not logged the ajax request is not possible and returns 401
console.log("[INFO] Bludit AJAX: userLogged(): fail handler");
if (jqXHR.status==401) {
callBack("Your are not more logged, Bludit can't save your settings and content.");
}
});
ajaxRequest.always(function () {
console.log("[INFO] Bludit AJAX: userLogged(): always handler");
});
}
generateSlug(text, parentKey, currentKey, callBack) {
var ajaxRequest;
if (ajaxRequest) {

View File

@ -1,7 +1,7 @@
<script>
// DEPRECATED
// ALL THIS FUNCTIONS IS DEPREACTED
// ALL THIS FUNCTIONS ARE DEPREACTED
var ajaxRequest;

View File

@ -4,6 +4,8 @@ class pluginUpdater extends Plugin {
// Define if the extension zip is loaded
private $zip = false;
private $urlLatestVersionFile = 'https://';
private $localLatestVersionFile = '';
public function init()
{
@ -12,6 +14,15 @@ class pluginUpdater extends Plugin {
// Check for zip extension installed
$this->zip = extension_loaded('zip');
// Local full path of the file of the latest version of Bludit
$this->localLatestVersionFile = $this->workspace().DS.'bludit-latest.zip';
}
// Redefine workspace
public function workspace()
{
return PATH_CONTENT.'updater'.DS;
}
// Install the plugin and create the workspace directory
@ -30,27 +41,21 @@ class pluginUpdater extends Plugin {
return Filesystem::deleteRecursive($workspace);
}
// Redefine workspace
public function workspace()
{
return PATH_CONTENT.'updater'.DS;
}
// Check if the root directory is writable
private function isWritable()
public function isWritable()
{
return is_writable(PATH_ROOT);
}
// Create a copy of all the system and compress it
// Returns the name of the backup directory
private function makeFullBackup()
public function makeFullBackup()
{
$currentDate = Date::current(BACKUP_DATE_FORMAT);
$backupDirectory = $this->workspace().$currentDate;
// Copy all the files to a backup directory formed by date
Filesystem::copyRecursive(PATH_CONTENT, $backupDirectory, $backupDirectory);
// Copy all files from PATH_ROOT to $backupDirectory, also omit the directory $backupDirectory
Filesystem::copyRecursive(PATH_ROOT, $backupDirectory, $backupDirectory);
// Compress the backup directory
if (Filesystem::zip($backupDirectory, $backupDirectory.'.zip')) {
@ -61,19 +66,37 @@ class pluginUpdater extends Plugin {
}
// Download the latest version of Bludit
private function downloadLatestVersion()
public function downloadLatestVersion()
{
TCP::download('https://bludit-latest.zip', $this->workspace().DS.'bludit-latest.zip');
return TCP::download($this->urlLatestVersionFile, $this->localLatestVersionFile);
}
public function validChecksum()
{
// IMPLEMENT !!!
return true;
}
// Unzip the latest version and replace the old files
public function upgradeFiles()
{
return Filesystem::unzip($this->localLatestVersionFile, PATH_ROOT);
}
public function post()
{
if (isset($_POST['createBackup'])) {
return $this->createBackup();
} elseif (isset($_POST['restoreBackup'])) {
return $this->restoreBackup($_POST['restoreBackup']);
} elseif (isset($_POST['deleteBackup'])) {
return $this->deleteBackup($_POST['deleteBackup']);
if (isset($_POST['updateNow'])) {
echo 'Making a backup';
$this->makeFullBackup();
echo 'Downloading the latest version of Bludit';
$this->downloadLatestVersion();
echo 'Validating checksum';
if ($this->validChecksum()) {
echo 'Updating files';
return $this->upgradeFiles();
}
}
return false;
@ -83,86 +106,15 @@ class pluginUpdater extends Plugin {
{
global $Language;
$backups = Filesystem::listDirectories($this->workspace(), '*', true);
if ($this->zip) {
$backups = Filesystem::listFiles($this->workspace(), '*', 'zip', true);
if ($this->zip===false) {
//return '<div class="alert alert-success">The extension zip file is not installed, to use this plugin you need install the extension first.</div>';
}
$html = '<div>';
$html .= '<button name="createBackup" value="true" class="left small blue" type="submit"><i class="uk-icon-plus"></i> '.$Language->get('create-backup').'</button>';
$html .= '<button name="updateNow" value="true" class="btn btn-primary" type="submit">'.$Language->get('Update Now').'</button>';
$html .= '</div>';
$html .= '<hr>';
foreach ($backups as $backup) {
$filename = pathinfo($backup,PATHINFO_FILENAME);
$basename = pathinfo($backup,PATHINFO_BASENAME);
$html .= '<div>';
$html .= '<h3>'.Date::format($filename, BACKUP_DATE_FORMAT, 'F j, Y, g:i a').'</h3>';
// Allow download if a zip file
if ($this->zip) {
$html .= '<a class="uk-button small left blue" href="'.DOMAIN_CONTENT.'backup/'.$filename.'.zip"><i class="uk-icon-download"></i> '.$Language->get('download').'</a>';
}
$html .= '<button name="restoreBackup" value="'.$filename.'" class="uk-button small left" type="submit"><i class="uk-icon-clock-o"></i> '.$Language->get('restore-backup').'</button>';
$html .= '<button name="deleteBackup" value="'.$filename.'" class="uk-button small left" type="submit"><i class="uk-icon-trash-o"></i> '.$Language->get('delete-backup').'</button>';
$html .= '</div>';
$html .= '<hr>';
}
return $html;
}
public function createBackup()
{
// Current backup directory
$currentDate = Date::current(BACKUP_DATE_FORMAT);
$backupDir = $this->workspace().$currentDate;
// Copy directories to backup directory
// $directoriesToBackup is a private variable of this class
foreach ($this->directoriesToBackup as $dir) {
$destination = $backupDir.DS.basename($dir);
Filesystem::copyRecursive($dir, $destination);
}
// Compress backup directory
if ($this->zip) {
if (Filesystem::zip($backupDir, $backupDir.'.zip')) {
Filesystem::deleteRecursive($backupDir);
}
}
return true;
}
public function restoreBackup($filename)
{
// Remove current files
foreach ($this->directoriesToBackup as $dir) {
Filesystem::deleteRecursive($dir);
}
// Recover backuped files
// Zip format
if ($this->zip) {
$tmp = $this->workspace().$filename.'.zip';
return Filesystem::unzip($tmp, PATH_CONTENT);
}
// Directory format
$tmp = $this->workspace().$filename;
return Filesystem::copyRecursive($tmp, PATH_CONTENT);
}
public function deleteBackup($filename)
{
// Zip format
if ($this->zip) {
$tmp = $this->workspace().$filename.'.zip';
return Filesystem::rmfile($tmp);
}
// Directory format
$tmp = $this->workspace().$filename;
return Filesystem::deleteRecursive($tmp);
}
}

View File

@ -422,7 +422,7 @@ function install($adminPassword, $email='', $timezone)
'locale'=>$Language->locale(),
'timezone'=>$timezone,
'theme'=>'alternative',
'adminTheme'=>'default',
'adminTheme'=>'booty',
'homepage'=>'',
'pageNotFound'=>'',
'uriPage'=>'/',
@ -438,7 +438,11 @@ function install($adminPassword, $email='', $timezone)
'codepen'=>'',
'googlePlus'=>'https://plus.google.com/+Bluditcms',
'github'=> 'https://github.com/bludit',
'dateFormat'=>'F j, Y'
'instagram'=>'',
'gitlab'=>'',
'linkedin'=>'',
'dateFormat'=>'F j, Y',
'extremeFriendly'=>true
);
file_put_contents(PATH_DATABASES.'site.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);