View sourcecode

The following files exists in this folder. Click to view.

admin.php

71 lines UTF-8 Unix (LF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
require_once __DIR__ "/functions.php";

require_login();
require_role('user');

// Hämta flash-meddelande om det finns
$flash $_SESSION['flash'] ?? null;
unset(
$_SESSION['flash']);

// Säkert hämta användarnamn
$user = (is_array($_SESSION['user']) && isset($_SESSION['user']['name']))
    ? 
$_SESSION['user']['name']
    : 
"okänd";
?>
<!doctype html>
<html lang="sv">
<head>
  <meta charset="utf-8">
  <title>Adminpanel</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="style.css">
</head>
<body>

<div class="page-container">

  <h1>Admin</h1>

  <?php if ($flash !== null): ?>
    <div class="flash"><?= htmlspecialchars($flash?></div>
  <?php endif; ?>

  <div class="card">
    <p>Hej <strong><?= htmlspecialchars($user?></strong>! Du är inloggad.</p>

    <ul>
      <li><a href="logout.php">Logga ut</a></li>
      <li><a href="index.php">Till startsidan</a></li>
    </ul>

    <hr>

    <h3>Uppdatera lösenord</h3>
    <form method="post" action="users.php">
      <input type="hidden" name="action" value="update_password">
      <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">

      <label>Nuvarande lösenord</label>
      <input type="password" name="old_password" required>

      <label>Nytt lösenord</label>
      <input type="password" name="new_password" required>

      <button type="submit">Uppdatera</button>
    </form>

    <hr>

    <h3>Ta bort konto</h3>
    <form method="post" action="users.php" onsubmit="return confirm('Är du säker? Detta kan inte ångras.');">
      <input type="hidden" name="action" value="delete_account">
      <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
      <button class="btn-danger">Ta bort mitt konto</button>
    </form>
  </div>

</div>

</body>
</html>