From b5910a00d206cce58f617db5979790f8ef52ab6c Mon Sep 17 00:00:00 2001 From: nliautaud Date: Mon, 6 Nov 2017 15:17:15 +0100 Subject: [PATCH 1/3] update documentation for Pico 2 YML --- README.md | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index cd15063..205dff2 100644 --- a/README.md +++ b/README.md @@ -18,28 +18,23 @@ Copy the `PicoUsers` directory to the `plugins/` directory of your Pico Project. ## Settings -Users, rights and others settings should be stored in Pico `config/config.php` file. - -```php -$config['users'] = array( - 'john' => '$2a$08$kA7StQeZgyuEJnIrvypwEeuyjSqxrvavOBSf33n4yWSJFhbQAkO1W', - 'editors' => array( - 'marc' => '$2a$08$V/En.8vnZFWGOwXvDvFYsO8PTq.KSA5eYTehICnErFnd3V.zzsj.K', - 'admins' => array( - 'john' => '$2a$08$bCVTtxqH/VxWuHqrZQ/QiOEcvvbVjl9UD3mTf.7AnXhS90DXj5IZ6' - ) - ), - 'family' => array( - 'mum' => '$2a$08$qYtklDGOy/cCK1K0Zh8qROkFW3/V7gFgve.0GQv/sPmLYHm0jEiTi', - 'dad' => '$2a$08$Eu7aKmOLz1Jme4iReWp6r.TfI2K3V3DyeRDV8oBS6gMtDPessqqru' - ) -); -$config['rights'] = array( - 'family-things' => 'family', - 'secret/infos' => 'editors', - 'secret/infos/' => 'editors/admins', - 'just-for-john' => 'john' -); +Users, rights and others settings can be defined in Pico config file. + +```yml +users: + john: $2a$08$kA7StQeZgyuEJnIrvypwEeuyjSqxrvavOBSf33n4yWSJFhbQAkO1W + editors: + marc: $2a$08$V/En.8vnZFWGOwXvDvFYsO8PTq.KSA5eYTehICnErFnd3V.zzsj.K + admins: + john: $2a$08$bCVTtxqH/VxWuHqrZQ/QiOEcvvbVjl9UD3mTf.7AnXhS90DXj5IZ6 + family: + mum: $2a$08$qYtklDGOy/cCK1K0Zh8qROkFW3/V7gFgve.0GQv/sPmLYHm0jEiTi + dad: $2a$08$Eu7aKmOLz1Jme4iReWp6r.TfI2K3V3DyeRDV8oBS6gMtDPessqqru +rights: + family-things: family + secret/infos: editors + secret/infos/: editors/admins + just-for-john: john ``` ### Users and groups @@ -56,12 +51,12 @@ The setting `rights` is a flat list of rules, associating a rule to a user or a > Note that you can target a specific path or all sub-paths by using or not a trailing slash. -PicoUsers will use these rules as *rights to view a given page*, but other plugins may define other meanings. Edits rights in [Pico Content Editor](https://github.com/nliautaud/pico-content-editor) for example : +PicoUsers will use these rules as *rights to view pages*, but other plugins may define other meanings, like editing in [Pico Content Editor](https://github.com/nliautaud/pico-content-editor). -```php -$config['rights'] = array( - 'PicoContentEditor/save' => 'admins' -); +```yml +rights: + some/path/page: editors + PicoContentEditor/save: admins ``` You can check for a specific right in your theme with the following Twig function : From d46feeba5bc080d30c7f97ea87cdaf110e5e0ce3 Mon Sep 17 00:00:00 2001 From: Nicolas Liautaud Date: Thu, 22 Mar 2018 20:03:48 +0100 Subject: [PATCH 2/3] add info about directory name --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 205dff2..5e615a0 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ Features login and logout system, unlimited users and hierarchical user groups, ## Installation -Copy the `PicoUsers` directory to the `plugins/` directory of your Pico Project. +Copy the `45-PicoUsers` directory to the `plugins/` directory of your Pico Project. + +*Note that the directory numerical prefix is needed to ensure the Pico plugins loading order.* ## Settings From 4d79375c1cb2cc908e5d67408281c322c73f8869 Mon Sep 17 00:00:00 2001 From: nliautaud Date: Tue, 5 Jun 2018 12:22:53 +0200 Subject: [PATCH 3/3] Pico plugin API 2 support --- 45-PicoUsers/PicoUsers.php | 52 +++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/45-PicoUsers/PicoUsers.php b/45-PicoUsers/PicoUsers.php index a10ccb5..d714451 100644 --- a/45-PicoUsers/PicoUsers.php +++ b/45-PicoUsers/PicoUsers.php @@ -5,16 +5,17 @@ */ require_once('password.php'); /** - * A hierarchical users and rights system plugin for Pico. + * A hierarchical users and rights system plugin for Pico 2. * * @author Nicolas Liautaud * @link https://github.com/nliautaud/pico-users * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License - * @version 0.2.3 */ class PicoUsers extends AbstractPicoPlugin { + const API_VERSION = 2; + private $user; private $users; private $rights; @@ -52,26 +53,14 @@ public function onRequestUrl(&$url) /** * Hide 403 and unauthorized pages. * - * Triggered after Pico has read all known pages - * See {@link DummyPlugin::onSinglePageLoaded()} for details about the - * structure of the page data. + * Triggered after Pico has discovered all known pages * - * @see Pico::getPages() - * @see Pico::getCurrentPage() - * @see Pico::getPreviousPage() - * @see Pico::getNextPage() - * @param array[] &$pages data of all known pages - * @param array|null &$currentPage data of the page being served - * @param array|null &$previousPage data of the previous page - * @param array|null &$nextPage data of the next page + * @see DummyPlugin::onPagesLoading() + * @see DummyPlugin::onPagesLoaded() + * @param array[] &$pages list of all known pages * @return void */ - public function onPagesLoaded( - array &$pages, - array &$currentPage = null, - array &$previousPage = null, - array &$nextPage = null - ) { + public function onPagesDiscovered(array &$pages) { foreach ($pages as $id => $page ) { if ($id == '403' || !$this->hasRight($page['url'], true)) { unset($pages[$id]); @@ -79,16 +68,16 @@ public function onPagesLoaded( } } /** + * Add various twig variables. + * * Triggered before Pico renders the page * - * @see Pico::getTwig() - * @see DummyPlugin::onPageRendered() - * @param Twig_Environment &$twig twig template engine - * @param array &$twigVariables template variables - * @param string &$templateName file name of the template + * @see DummyPlugin::onPageRendered() + * @param string &$templateName file name of the template + * @param array &$twigVariables template variables * @return void */ - public function onPageRendering(Twig_Environment &$twig, array &$twigVariables, &$templateName) + public function onPageRendering(&$templateName, array &$twigVariables) { $twigVariables['login_form'] = $this->html_form(); if ($this->user) { @@ -96,7 +85,18 @@ public function onPageRendering(Twig_Environment &$twig, array &$twigVariables, $twigVariables['username'] = basename($this->user); $twigVariables['usergroup'] = dirname($this->user); } - // {{ user_has_right('rule') }} + } + /** + * Add {{ user_has_right('rule') }} twig function. + * + * Triggered when Pico registers the twig template engine + * + * @see Pico::getTwig() + * @param Twig_Environment &$twig Twig instance + * @return void + */ + public function onTwigRegistered(Twig_Environment &$twig) + { $twig->addFunction(new Twig_SimpleFunction('user_has_right', array($this, 'hasRight'))); }