Coder Social home page Coder Social logo

pico-private's Introduction

Pico Private Plugin

Provide an authentication form to keep your Pico site or part of it private.

Install

  1. Download a copy and extract the folder pico_private in your plugins folder,
  2. Setup your theme,
  3. Test everything is working with user "admin" and password "admin",
  4. Open the pico_private_pass.php file and insert your users and theirs password,
  5. REMOVE admin user.

Pico executes plugins by alphabetical order. If we want to protect all our URLs even those generated from plugins, we must execute Pico Private first. In order to execute Pico Private first, it's a good idea to prepend the folder's name with an underscore like _pico_private.

How it works

By default, the whole site will be "protected" behind a login form, but it's possible to keep just some content private.

The plugin will display a login form when a user cannot access content without being identified. Once logged in, the user will be able to browse your website normally.

Users and passwords are stored in pico_private_conf.php and you can add as many users you want. Passwords must be a SHA1 string.

Keep some part private

If you don't want the whole site to be private, you can change the configuration in pico_private_conf.php. The variable $pico_private_conf['config']['private'] can take two values :

  • "all" : The whole site is private
  • "meta" : Only content with meta Private: true will be private.

Keep in mind that once a user is identified, he can access every contents with private meta !

Configuration

Add users

Users are stored in an associative array :

  • Keys are usernames
  • Values are SHA1 passwords

Setup your theme

All you need to do is create inside your theme's folder a login.html page which will display the login form. The form is pretty simple :

<form method="post">
   {% if login_error %}<p class="error">{{ login_error }}</p>{% endif %}
   <input type="text" name="username" id="username" placeholder="Username" value="{{ username }}"/>
   <input type="password" name="password" id="password" placeholder="Password"/>
   <input class="alignright" type="submit" value="Login" />
   {% if redirect_url %}<input type="hidden" name="redirect_url" value="{{ redirect_url }}"/>{% endif %}
</form>
```

Then it's up to you to style the form to match your site design.

When the user is logged_in, the plugin adds two variables to the `$twig_vars`, that you can use in your theme : 

* `{{ authed }}` : Is user logged_in (boolean)
* `{{ username }}` : The username (string)

### Password only mode

If a single password is secure enough for your needs the easiest way is to change those two lines:

In your template file replace the username input field with:

```html
<input type="hidden" name="username" id="username" value="no_user"/>
```

In the pico_private_pass.php file add:

```php
$pico_private_conf['users']['no_user'] = '-hashedpw-';
```

pico-private's People

Contributors

jbleuzen avatar elpoto avatar kicsihobi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.