From 3635084bec12504d70db2239c3ff7a56eb2de1b3 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Sun, 24 Jun 2018 13:37:45 +0200 Subject: [PATCH] check user is logged --- bl-kernel/admin/themes/booty/html/alert.php | 5 +- bl-kernel/admin/themes/booty/html/sidebar.php | 4 +- .../admin/themes/booty/html/user-logged.php | 8 + bl-kernel/admin/themes/booty/index.php | 6 +- bl-kernel/admin/views/categories.php | 2 +- bl-kernel/admin/views/edit-category.php | 2 +- bl-kernel/admin/views/new-content.php | 2 +- bl-kernel/admin/views/settings.php | 11 +- bl-kernel/ajax/user-logged.php | 24 +++ bl-kernel/boot/admin.php | 5 +- bl-kernel/boot/variables.php | 5 +- bl-kernel/dbsite.class.php | 8 +- bl-kernel/js/bludit-ajax.php | 36 ++++- bl-kernel/js/functions.php | 2 +- bl-plugins/updater/plugin.php | 138 ++++++------------ install.php | 10 +- 16 files changed, 157 insertions(+), 111 deletions(-) create mode 100644 bl-kernel/admin/themes/booty/html/user-logged.php create mode 100644 bl-kernel/ajax/user-logged.php diff --git a/bl-kernel/admin/themes/booty/html/alert.php b/bl-kernel/admin/themes/booty/html/alert.php index ee30000a..c9f11ea5 100644 --- a/bl-kernel/admin/themes/booty/html/alert.php +++ b/bl-kernel/admin/themes/booty/html/alert.php @@ -1,8 +1,9 @@ -
\ No newline at end of file +
diff --git a/bl-kernel/admin/themes/booty/html/sidebar.php b/bl-kernel/admin/themes/booty/html/sidebar.php index 11b53e06..ce20527b 100644 --- a/bl-kernel/admin/themes/booty/html/sidebar.php +++ b/bl-kernel/admin/themes/booty/html/sidebar.php @@ -28,7 +28,7 @@ p('Categories') ?> - \ No newline at end of file + diff --git a/bl-kernel/admin/themes/booty/html/user-logged.php b/bl-kernel/admin/themes/booty/html/user-logged.php new file mode 100644 index 00000000..efd815f7 --- /dev/null +++ b/bl-kernel/admin/themes/booty/html/user-logged.php @@ -0,0 +1,8 @@ + + diff --git a/bl-kernel/admin/themes/booty/index.php b/bl-kernel/admin/themes/booty/index.php index 3d830f58..1534b4c2 100644 --- a/bl-kernel/admin/themes/booty/index.php +++ b/bl-kernel/admin/themes/booty/index.php @@ -75,8 +75,12 @@ + + + + - \ No newline at end of file + diff --git a/bl-kernel/admin/views/categories.php b/bl-kernel/admin/views/categories.php index 3c85278a..caf14e6c 100644 --- a/bl-kernel/admin/views/categories.php +++ b/bl-kernel/admin/views/categories.php @@ -1,6 +1,6 @@ $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', diff --git a/bl-kernel/admin/views/edit-category.php b/bl-kernel/admin/views/edit-category.php index 94cdf292..03725c91 100644 --- a/bl-kernel/admin/views/edit-category.php +++ b/bl-kernel/admin/views/edit-category.php @@ -1,6 +1,6 @@ $L->g('Edit Category'), 'icon'=>'grid-three-up')); +echo Bootstrap::pageTitle(array('title'=>$L->g('Edit Category'), 'icon'=>'tags')); echo Bootstrap::formOpen(array()); diff --git a/bl-kernel/admin/views/new-content.php b/bl-kernel/admin/views/new-content.php index e1dff256..2e911a69 100644 --- a/bl-kernel/admin/views/new-content.php +++ b/bl-kernel/admin/views/new-content.php @@ -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 diff --git a/bl-kernel/admin/views/settings.php b/bl-kernel/admin/views/settings.php index 7be07bb6..27ced189 100644 --- a/bl-kernel/admin/views/settings.php +++ b/bl-kernel/admin/views/settings.php @@ -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', @@ -376,4 +385,4 @@ $(document).ready(function() { }); }); - \ No newline at end of file + diff --git a/bl-kernel/ajax/user-logged.php b/bl-kernel/ajax/user-logged.php new file mode 100644 index 00000000..3c28a0cd --- /dev/null +++ b/bl-kernel/ajax/user-logged.php @@ -0,0 +1,24 @@ +isLogged()) { + exit (json_encode(array( + 'status'=>1, + 'message'=>'The user is logged.' + ))); +} + +exit (json_encode(array( + 'status'=>0, + 'message'=>'The user is NOT logged.' +))); + + +?> diff --git a/bl-kernel/boot/admin.php b/bl-kernel/boot/admin.php index 246e6105..e2268c47 100644 --- a/bl-kernel/boot/admin.php +++ b/bl-kernel/boot/admin.php @@ -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 --- @@ -91,4 +92,4 @@ else // Load plugins after the admin area is loaded. Theme::plugins('afterAdminLoad'); -} \ No newline at end of file +} diff --git a/bl-kernel/boot/variables.php b/bl-kernel/boot/variables.php index a74b87f1..26c875aa 100644 --- a/bl-kernel/boot/variables.php +++ b/bl-kernel/boot/variables.php @@ -113,4 +113,7 @@ $GLOBALS['THUMBNAILS_HEIGHT'] = 400; $GLOBALS['THUMBNAILS_QUALITY'] = 100; // Autosave -$GLOBALS['AUTOSAVE_TIME'] = 2; // Minutes \ No newline at end of file +$GLOBALS['AUTOSAVE_TIME'] = 2; // Minutes + +// Alert +$GLOBALS['ALERT_DISSAPEAR_IN'] = 3; // Seconds diff --git a/bl-kernel/dbsite.class.php b/bl-kernel/dbsite.class.php index 09564d3f..c2c4e2b5 100644 --- a/bl-kernel/dbsite.class.php +++ b/bl-kernel/dbsite.class.php @@ -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) @@ -130,6 +131,11 @@ class dbSite extends dbJSON { return $this->getField('github'); } + + public function gitlab() + { + return $this->getField('gitlab'); + } public function googlePlus() { @@ -304,4 +310,4 @@ class dbSite extends dbJSON return date_default_timezone_set($timezone); } -} \ No newline at end of file +} diff --git a/bl-kernel/js/bludit-ajax.php b/bl-kernel/js/bludit-ajax.php index 6e987437..c85ab5b5 100644 --- a/bl-kernel/js/bludit-ajax.php +++ b/bl-kernel/js/bludit-ajax.php @@ -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: "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) { diff --git a/bl-kernel/js/functions.php b/bl-kernel/js/functions.php index af4d4e6e..70c2edbc 100644 --- a/bl-kernel/js/functions.php +++ b/bl-kernel/js/functions.php @@ -1,7 +1,7 @@ - \ No newline at end of file +