Skip to content

Commit

Permalink
Hide 403 pages, close #9
Browse files Browse the repository at this point in the history
  • Loading branch information
nliautaud committed Sep 16, 2017
1 parent f8f6177 commit 79b8ca9
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions 45-PicoUsers/PicoUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @link https://github.com/nliautaud/pico-users
* @link http://picocms.org
* @license http://opensource.org/licenses/MIT The MIT License
* @version 0.2.2
* @version 0.2.3
*/
final class PicoUsers extends AbstractPicoPlugin
{
Expand Down Expand Up @@ -52,15 +52,15 @@ public function onConfigLoaded(array &$config)
*/
public function onRequestUrl(&$url)
{
$page_url = rtrim($url, '/');
if (!$this->is_authorized($this->base_url . $page_url)) {
if (!$this->is_authorized($this->base_url . $url)) {
$url = '403';
header('HTTP/1.1 403 Forbidden');
}
}
/**
* 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.
*
Expand All @@ -81,7 +81,7 @@ public function onPagesLoaded(
array &$nextPage = null
) {
foreach ($pages as $id => $page ) {
if (!$this->is_authorized(rtrim($page['url'], '/'))) {
if ($id == '403' || !$this->is_authorized($page['url'])) {
unset($pages[$id]);
}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ function check_login()
unset($_SESSION[$fp]);
return;
}

// login action
if (isset($_POST['login'])
&& isset($_POST['pass'])) {
Expand All @@ -140,7 +140,7 @@ function check_login()
$path = $_SESSION[$fp]['path'];
$hash = $_SESSION[$fp]['hash'];
$user = $this->get_user($path);

if ($user['hash'] === $hash) {
$this->log_user($user, $fp);
}
Expand Down Expand Up @@ -210,7 +210,7 @@ function search_users( $name, $pass, $users = null , $path = '' )
}

if ($name !== null && $name !== $username) continue;

if (!password_verify($pass, $userdata)) continue;

$results[] = array(
Expand Down Expand Up @@ -245,6 +245,7 @@ function get_user( $path )
private function is_authorized($url)
{
if (!$this->rights) return true;
$url = rtrim($url, '/');
foreach ($this->rights as $auth_path => $auth_user )
{
// url is concerned by this rule and user is not (unauthorized)
Expand Down

0 comments on commit 79b8ca9

Please sign in to comment.