Skip to content

Commit

Permalink
Big fix #1 #2
Browse files Browse the repository at this point in the history
1. [](#fix)
* Fix bug when the private tag is on first position
* Fix #1 : Added var home on config for full private redirection
* Fix #2 : Compatibility sessions with other plugins
* (Thanks to Vivalldi)

2. [](#improved)
* Update Documentation
  • Loading branch information
Diyzzuf committed Mar 10, 2015
1 parent 4b42bca commit 5f0c303
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# v0.4.6
## 03/10/2015

1. [](#fix)
* Fix bug when the private tag is on first position
* Fix #1 : Added var home on config for full private redirection
* Fix #2 : Compatibility sessions with other plugins
* (Thanks to Vivalldi)

2. [](#improved)
* Update Documentation

# v0.4.5
## 02/18/2015

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ To customize this parameters (and more), you first need to create an override co
1. **Change** the default password in your `user/config/plugins/private.yaml`
2. **Change** the default security salt in your `user/config/plugins/private.yaml`
3. **Customize** your privacy rules
4. **Customize** your home path for full private website

# Options

Expand All @@ -46,11 +47,13 @@ Enable or Disable the entire plugin (default: `true`).
enabled: (true|false)

###### Routing
Routes of login and logout page. You can customize it by simple replacement of the value (e.g: login: "/admin" for "mywebsite.com/admin" )
Routes of login, logout and home page. You can customize it by simple replacement of the value (e.g: login: "/admin" for "mywebsite.com/admin" )
The home option is only for full private website (Bug fix #1)

routes:
login: "/login"
logout: "/logout"
home: "/"

###### Security Salt
Security Salt for session. You can go to this [generator](http://www.sethcardoza.com/tools/random-password-generator/) for your own.
Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Private
version: 0.4.5
version: 0.4.6
description: "Provide an authentication form to keep your Grav site or part of it private."
icon: lock
author:
Expand Down
23 changes: 15 additions & 8 deletions private.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ public function onPluginsInitialized()

if( $options['enabled'] == true) {

session_start();
if (!isset($_SESSION)) {
session_start();
}

if($uri->path() == $options['routes']['logout']) {
session_destroy();
unset($_SESSION[$options['session_ss']]);
unset($_SESSION['username']);
$this->grav->redirect('/');
}

Expand All @@ -52,14 +55,14 @@ public function onPluginsInitialized()
return;
}
else {
$this->grav->redirect('/');
$this->grav->redirect($options['routes']['home']);
}

}

else {
if($options['private_site'] == true && (!isset($_SESSION[$options['session_ss']]) || $_SESSION[$options['session_ss']] == false ) ){
$_SESSION['referer_redirect'] = $uri->path();
// $_SESSION['referer_redirect'] = $uri->path();
$this->grav->redirect($options['routes']['login']);
} else {
$this->enable([
Expand Down Expand Up @@ -106,14 +109,14 @@ public function onPageInitialized()
else {

if($options['private_site'] == true ) {
$_SESSION['referer_redirect'] = $uri->path();
// $_SESSION['referer_redirect'] = $uri->path();
$this->grav->redirect($options['routes']['login']);
}

else {
if (array_key_exists( 'tag', $this->grav['page']->taxonomy() )) {
$find_tag = array_search( $options['private_tag'], $this->grav['page']->taxonomy()['tag'] );
if( $find_tag ) {
if( is_numeric($find_tag) ) {
$_SESSION['referer_redirect'] = $uri->path();
$this->grav->redirect($options['routes']['login']);
} else {
Expand Down Expand Up @@ -155,8 +158,12 @@ protected function getLoginPage()
if ( false === $this->sendLogin() ) {
$page->content($twig->twig()->render('login.html.twig', ['private' => $options, 'page' => $page, 'login_error' => 'fail']));
} else {
$redirect_referer = $_SESSION['referer_redirect'];
unset($_SESSION['referer_redirect']);
if($options['private_site'] == true ) {
$redirect_referer = $options['routes']['home'];
}else{
$redirect_referer = $_SESSION['referer_redirect'];
unset($_SESSION['referer_redirect']);
}
$this->grav->redirect($redirect_referer);
}
}
Expand Down
1 change: 1 addition & 0 deletions private.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ enabled: true
routes:
login: "/login"
logout: "/logout"
home: "/"

session_ss: random_value

Expand Down

0 comments on commit 5f0c303

Please sign in to comment.