- commit
- 6e358992999edf12d636d2c7cf17f174dda5eddf
- parent
- 934a5b9e8ff74eb7f58aec3131843e651b06fa4d
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2018-10-21 09:04
add users view
Diffstat
| M | index.php | 35 | +++++++++++++++++++++++++++++++++++ |
| M | templates/base.html | 1 | + |
| A | templates/users.html | 21 | +++++++++++++++++++++ |
3 files changed, 57 insertions, 0 deletions
diff --git a/index.php b/index.php
@@ -160,6 +160,13 @@ class Pupupu 160 160 return $this->cache[$key]; 161 161 } 162 162 -1 163 public function putYaml($path, $data) -1 164 { -1 165 $key = "yml:$path"; -1 166 $this->cache[$key] = $data; -1 167 $this->put($path, 'yml', Yaml::dump($data)); -1 168 } -1 169 163 170 public function getSubpages($path) 164 171 { 165 172 $subpages = array(); @@ -282,6 +289,17 @@ class Pupupu 282 289 $users = $this->getYaml('/_users'); 283 290 return password_verify($password, $users[$name] ?? ''); 284 291 } -1 292 -1 293 public function setPassword($name, $password=false) -1 294 { -1 295 $users = $this->getYaml('/_users'); -1 296 if ($password) { -1 297 $users[$name] = password_hash($password, PASSWORD_DEFAULT); -1 298 } else { -1 299 unset($users[$name]); -1 300 } -1 301 $this->putYaml('/_users', $users); -1 302 } 285 303 } 286 304 287 305 function ensureTrailingSlash() @@ -371,6 +389,21 @@ function pageView($pupupu, $twig) 371 389 } 372 390 } 373 391 -1 392 function usersView($pupupu, $twig) -1 393 { -1 394 if ($_SERVER['REQUEST_METHOD'] == 'GET') { -1 395 echo $twig->render('users.html', array( -1 396 'users' => $pupupu->getYaml('/_users'), -1 397 )); -1 398 } elseif (isset($_POST['delete'])) { -1 399 $pupupu->setPassword($_POST['name'], false); -1 400 header('Location: ', true, 302); -1 401 } else { -1 402 $pupupu->setPassword($_POST['name'], $_POST['password']); -1 403 header('Location: ', true, 302); -1 404 } -1 405 } -1 406 374 407 function errorView($pupupu, $twig, $error) 375 408 { 376 409 http_response_code($error->getCode()); @@ -400,6 +433,8 @@ if (isset($_SERVER['REQUEST_METHOD'])) { 400 433 siteView($pupupu, $twig); 401 434 } elseif (substr($_GET['path'], 0, 7) === '/_files') { 402 435 filesView($pupupu, $twig); -1 436 } elseif (substr($_GET['path'], 0, 7) === '/_users') { -1 437 usersView($pupupu, $twig); 403 438 } else { 404 439 pageView($pupupu, $twig); 405 440 }
diff --git a/templates/base.html b/templates/base.html
@@ -14,6 +14,7 @@ 14 14 <a href="?">{{ 'pages'|trans }}</a> 15 15 <a href="?path=%2F_files">{{ 'files'|trans }}</a> 16 16 <a href="?path=%2F_site">{{ 'site'|trans }}</a> -1 17 <a href="?path=%2F_users">{{ 'users'|trans }}</a> 17 18 </nav> 18 19 </header> 19 20
diff --git a/templates/users.html b/templates/users.html
@@ -0,0 +1,21 @@
-1 1 {% extends 'base.html' %}
-1 2
-1 3 {% block main %}
-1 4 <form method="post" class="form--line">
-1 5 <input type="text" name="name">
-1 6 <input type="password" name="password">
-1 7 <button>{{ 'Add user'|trans }}</button>
-1 8 </form>
-1 9
-1 10 <ul class="file-list">
-1 11 {% for name, hash in users %}
-1 12 <li>
-1 13 <div class="file-list__main">{{ name }}</div>
-1 14 <form method="post">
-1 15 <input type="hidden" name="name" value="{{ name }}">
-1 16 <button class="button--danger button--small" name="delete">{{ 'Delete'|trans }}</button>
-1 17 </form>
-1 18 </li>
-1 19 {% endfor %}
-1 20 </ul>
-1 21 {% endblock %}