2017 © Pedro Peláez
 

project privat

Simple private access package for Laravel.

image

code16/privat

Simple private access package for Laravel.

  • Wednesday, June 6, 2018
  • by code16
  • Repository
  • 2 Watchers
  • 6 Stars
  • 3,485 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 4 Versions
  • 110 % Grown

The README.md

Privat

Latest Version on Packagist MIT Licensed GitHub Tests Action Status Total Downloads, (*1)

Privat is a very simple password protection for Laravel projects. It's useful for websites in a staging state., (*2)

Screenshot, (*3)

Usage

Install with composer

composer require code16/privat

Add Privat middleware in your project

Add the following middleware in your project configuration., (*4)

\Code16\Privat\PrivatMiddleware::class

Typically, you can add it at the end of the 'web' key in your $middlewareGroups array (in app/Http/Kernel)., (*5)

Set Privat config

First create the privat config file:, (*6)

php artisan vendor:publish --provider="Code16\Privat\PrivatServiceProvider"

And then edit the new /config/privat.php accordingly (nothing fancy); you can handle it with this keys in your .env file:, (*7)

  • PRIVAT_RESTRICTED=true
  • PRIVAT_PASSWORD=mypassword

Exceptions

The except config param is built like this:, (*8)

"except" => [
    "hosts" => env("PRIVAT_EXCEPTED_HOSTS", ""),
    "urls" => env("PRIVAT_EXCEPTED_URLS", "")
]

The urls config key is meant to contain a comma separated list of URLs excluded from Privat; for instance "/login,/admin"., (*9)

The hosts config key is the same, but for hosts (in case of a multi-hosts website)., (*10)

Waiting page

If you need to present a public waiting page, here's how: set the waiting page view name in the waiting_view config key (in config/privat.php):, (*11)

"waiting_view" => "demo.waiting"

From then, all requests without the Privat registration will be redirected to /privat_waiting which will render the configured view, except /privat, which will still present the Privat form., (*12)

How does it work

Quite simple: if the given password is correct, Privat sets a session property, and look for it on each request. So, obviously, Privat won't work on non session based systems (an API for instance)., (*13)

License

MIT, (*14)

The Versions