Changeset 1100 in t29-www for lib


Ignore:
Timestamp:
Jan 18, 2017, 9:25:03 PM (7 years ago)
Author:
sven
Message:

Passwort-Demo: Barriere durch Zaun ersetzt. Damit lassen sich mehrere eingesperrte Textbereiche pro Seite machen und dahinter kann auch Text stehen.

Layout weiter minimalisiert, auf eine Zeile reduziert.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/simplepassword.php

    r1098 r1100  
    11<?php
     2/**
     3 * Simpler Passwortschutz von Textbereichen in einer t29-Seite.
     4 * Prinzipiell ist dieser Passwortschut wirkungsvoll, sofern HTTPS
     5 * verwendet wird. Die primitive Übermittlung per GET (oder POST)
     6 * sorgt aber dafür, dass die Benutzererfahrung schwach ist (das
     7 * Passwort wird etwa plain-text in der URL angezeigt oder ein einfaches
     8 * Neuladen einer ansonsten statischen Seite führt stets zu den POST-
     9 * Warnungen).
     10 *
     11 * In der Praxis auf t29 ist dieser Passwortschutz allerdings schon alleine
     12 * deswegen völlig wirkungslos, weil die Files alle öffentlich per
     13 * SVN einsehbar sind. Aber Heribert wollte es ja so. Ist nur ein
     14 * Demonstrator.
     15 *
     16 * Beispiel einer verwenden Seite gibt es weiter unten.
     17 *
     18 * Es gibt zwei Varianten des Schutzes, wobei der t29FencedContent
     19 * der allgemeinere ist. Die t29PasswordBarrier hingegen geht nur,
     20 * wenn die Seite danach aufhört.
     21 *
     22 * Aktuelle Demo zu t29FencedContent gibt es unter
     23 * /physical-computing/geschuetzte-demo.php
     24 *
     25 **/
     26
     27class t29FencedContent {
     28        public $password;
     29        public $paramkey = 't29-pwd-barrier';
     30        public $id; // used in form #id
     31
     32        function __construct($id, $password=Null) {
     33                $this->id = $id;
     34                $this->password = $password;
     35        }
     36
     37        function isAuthenticated() {
     38                return (isset($_GET[$this->paramkey]) &&
     39                        $_GET[$this->paramkey] == $this->password);
     40        }
     41
     42        function failedToAuthenticate() {
     43                return (isset($_GET[$this->paramkey]) &&
     44                        $_GET[$this->paramkey] != $this->password);
     45        }
     46
     47        function printAnchor() {
     48                print '<!-- t29FencedContent anchor -->';
     49                print '<a id="'.$this->id.'"></a>';
     50        }
     51
     52        function printMiniForm() {
     53                // Print small inline "login/logut" form, Heribert style
     54                if( $this->failedToAuthenticate()) {
     55                        ?>
     56                        Passwort falsch, bitte nochmal probieren:
     57                        <?php
     58                        $this->printLoginForm();
     59                } else if($this->isAuthenticated()) {
     60                        $this->printLogoutForm();
     61                } else {
     62                        ?>
     63                        Passwort:
     64                        <?php
     65                        $this->printLoginForm();
     66                }
     67        }
     68
     69        function printLoginForm() {
     70                ?>
     71                <form method="get" style="display: inline-block;"
     72                   action="#<?php echo $this->id; ?>">
     73                        <input type="password" name="<?= $this->paramkey; ?>">
     74                        <input type="submit" value="Anmelden">
     75                </form>
     76                <?php
     77        }
     78
     79        function printLogoutForm() {
     80                ?>
     81                <form method="get" class="inline">
     82                        <input type="submit" value="Abmelden">
     83                </form>
     84                <?php
     85        }
     86
     87        function start() {
     88                if(!$this->isAuthenticated()) {
     89                        // buffer (thus hide) content
     90                        ob_start();
     91                }
     92        }
     93
     94        function end() {
     95                if(!$this->isAuthenticated()) {
     96                        // delete buffer content, thus hide content
     97                        ob_end_clean();
     98                }
     99        }
     100
     101}
     102
     103
     104
    2105/**
    3106 * Simpler Passwortschutz im Sinne einer "Barriere", die inmitten einer
Note: See TracChangeset for help on using the changeset viewer.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License