diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-05-25 19:48:15 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-05-25 19:48:15 +0200 |
commit | 19d16efebc3fb5c0b2aede29aa91d31000ffd124 (patch) | |
tree | 48e55d1dc335efe5ce306c0a984300de9d4998b4 /app | |
parent | 55fc826f9827dd86427534c11594c0d9c4f0b8d1 (diff) | |
download | wcms-19d16efebc3fb5c0b2aede29aa91d31000ffd124.tar.gz wcms-19d16efebc3fb5c0b2aede29aa91d31000ffd124.zip |
add page specific password protection close #118
Diffstat (limited to 'app')
-rw-r--r-- | app/class/Controller.php | 1 | ||||
-rw-r--r-- | app/class/Controllerpage.php | 12 | ||||
-rw-r--r-- | app/class/Page.php | 14 | ||||
-rw-r--r-- | app/class/Routes.php | 1 | ||||
-rw-r--r-- | app/view/templates/editleftbar.php | 3 | ||||
-rw-r--r-- | app/view/templates/pagepassword.php | 39 |
6 files changed, 68 insertions, 2 deletions
diff --git a/app/class/Controller.php b/app/class/Controller.php index 2b38988..7fb972c 100644 --- a/app/class/Controller.php +++ b/app/class/Controller.php @@ -171,6 +171,5 @@ class Controller $this->user->destroysession($this->session->wsession); $this->session->addtosession('wsession', ''); $this->usermanager->add($this->user); - } } diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php index e864dd3..2e1c285 100644 --- a/app/class/Controllerpage.php +++ b/app/class/Controllerpage.php @@ -131,15 +131,25 @@ class Controllerpage extends Controller if ($pageexist) { $canread = $this->user->level() >= $this->page->secure(); + // Check page password + if (!empty($this->page->password())) { + if (empty($_POST['pagepassword']) || $_POST['pagepassword'] !== $this->page->password()) { + $this->showtemplate('pagepassword', ['pageid' => $this->page->id()]); + exit; + } + } + if ($this->page->daterender() < $this->page->datemodif()) { if (Config::reccursiverender()) { $this->reccursiverender($this->page); } $this->page = $this->renderpage($this->page); } + + if ($canread) { $this->page->addaffcount(); - if ($this->user->level() < 2) { + if ($this->user->isvisitor()) { $this->page->addvisitcount(); } } diff --git a/app/class/Page.php b/app/class/Page.php index a369aed..e5b84ac 100644 --- a/app/class/Page.php +++ b/app/class/Page.php @@ -45,6 +45,7 @@ class Page extends Dbitem protected $sleep; protected $redirection; protected $refresh; + protected $password; public const LEN = 255; @@ -109,6 +110,7 @@ class Page extends Dbitem $this->setsleep(0); $this->setredirection(''); $this->setrefresh(0); + $this->setpassword(''); } // _____________________________________________________ G E T ____________________________________________________ @@ -361,6 +363,11 @@ class Page extends Dbitem return $this->refresh; } + public function password($type = 'string') + { + return $this->password; + } + @@ -701,6 +708,13 @@ class Page extends Dbitem $this->refresh = $refresh; } + public function setpassword($password) + { + if (is_string($password) && strlen($password) > 0 && strlen($password) < 64) { + $this->password = $password; + } + } + // __________________________________ C O U N T E R S ______________________________ diff --git a/app/class/Routes.php b/app/class/Routes.php index c59531d..0433079 100644 --- a/app/class/Routes.php +++ b/app/class/Routes.php @@ -54,6 +54,7 @@ class Routes ['POST', '/!timeline/add', 'Controllertimeline#add', 'timelineadd'], ['POST', '/!timeline/clap', 'Controllertimeline#clap', 'timelineclap'], ['GET', '/[cid:page]/', 'Controllerpage#read', 'pageread/'], + ['POST', '/[cid:page]/', 'Controllerpage#read', 'pageread/post'], ['GET', '/[cid:page]', 'Controllerpage#read', 'pageread'], ['GET', '/[cid:page]/add', 'Controllerpage#add', 'pageadd'], ['GET', '/[cid:page]/add:[cid:copy]', 'Controllerpage#addascopy', 'pageaddascopy'], diff --git a/app/view/templates/editleftbar.php b/app/view/templates/editleftbar.php index 812c30d..0c77337 100644 --- a/app/view/templates/editleftbar.php +++ b/app/view/templates/editleftbar.php @@ -192,6 +192,9 @@ <label for="refresh" title="Time before redirection (in seconds)">Refresh time</label> <input type="number" name="refresh" value="<?= $page->refresh() ?>" id="refresh" min="0" max="180"> + <label for="password" title="specific page password protection">Password</label> + <input type="text" name="password" value="<?= $page->password() ?>" id="password" min="0" max="64"> + </fieldset> </details> diff --git a/app/view/templates/pagepassword.php b/app/view/templates/pagepassword.php new file mode 100644 index 0000000..509c7ee --- /dev/null +++ b/app/view/templates/pagepassword.php @@ -0,0 +1,39 @@ +<?php + +$this->layout('readerlayout') ?> + +<?php +$this->start('head'); +?> + +<head> + <?= Wcms\Config::alertcss() ? '<link href="' . Wcms\Model::dirtopath(Wcms\Model::ASSETS_CSS_DIR) . 'global.css" rel="stylesheet" />' : '' ?> +</head> + + +<?php +$this->stop(); +?> + + + +<?php $this->start('page') ?> + +<body class="alert"> + +<main class="alert"> + + +<h1>This page is password protected</h1> + +<form action="<?= $this->url('pageread/post', ['page' => $pageid]) ?>" method="post"> +<label for="pagepassword">Page password</label> +<input type="password" name="pagepassword" id="pagepassword" autofocus required> +</form> + +</main> + + +</body> + +<?php $this->stop() ?>
\ No newline at end of file |