login/edit: optional fields to change password
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 9 Jun 2018 06:41:34 +0000 (08:41 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 14 Jun 2018 12:45:18 +0000 (14:45 +0200)
Inline login/pass page.

login/edit.php
login/pass.inc.php

index 563a3a567b6771c2962ea03a08589acce23676f5..2adfc5168848b2df9e941afaa734ca9e66a60cf7 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 global $User;
-if (empty($user = $User)) {
+if (empty($user = &$User)) {
        return;
 }
 
@@ -58,6 +58,13 @@ if ($_POST) {
                }
        }
 
+       if (!empty($_POST['newpass'])) {
+               require_once('login/pass.inc.php');
+               if ($error = passform($user, $_POST)) {
+                       $colwarn['pass'] = $error;
+               }
+       }
+
        if ($colwarn) {
                print "<p class=warn>Instellingen zijn niet (volledig) opgeslagen. Probeer het later nog eens.</p>\n\n";
        }
@@ -72,7 +79,6 @@ if ($_POST) {
        Geef een e-mailadres op waarmee we u kunnen bereiken indien nodig.
        Wij zullen dit adres nooit vrij- of doorgeven.
        </p>
-       <p>
 <?php
 foreach ($cols as $col => &$colconf) {
        print "\t";
@@ -92,7 +98,26 @@ foreach ($cols as $col => &$colconf) {
        }
        print "<br />\n";
 }
+
+if (isset($user['pass'])) {
+       if ($hide = empty($_POST['newpass'])) {
+?>
+       <p><a onclick="document.getElementById('pass').removeAttribute('hidden'); this.remove()">Wachtwoord wijzigen</a></p>
+<?php
+       }
+?>
+       <div id="pass"<?php if ($hide) print ' hidden'; ?>>
+               <label for="newpass">Wachtwoord:</label>
+               <input type="password" name="oldpass" value="" placeholder="Huidig wachtwoord" />
+               <input type="password" name="newpass" value="" placeholder="Nieuw wachtwoord" />
+<?php
+       if ($error = @$colwarn['pass']) {
+               print " <span class=warn>$error</span>\n";
+       }
+?>
+       </div>
+<?php
+}
 ?>
        <input type="submit" value="Opslaan" />
-       </p>
 </form>
index 2b4665c01765a4b61fdbb247031725f9eb084e03..cbfb1db9205a10a4eff22fe3e8c6b00bc5d4a7dd 100644 (file)
@@ -40,7 +40,9 @@ function passform($user, $input = [])
 
        $authhash = md5($input['newpass']);
        $user['auth'] = "{$user['name']}:$authhash";
-       login_setcookie();
+       if ($GLOBALS['User'] === $user) {
+               login_setcookie();
+       }
        return;
 }