Show sourcecode
The following files exists in this folder. Click to view.
public_html/smartkortet/pages/
hem.php
historik.php
installningar.php
restauranger.php
statistik.php
installningar.php
142 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
<?php
declare(strict_types=1);
require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../includes/data.php';
$userId = (int) $user['id'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
verifyCsrf();
$action = $_POST['action'] ?? '';
if ($action === 'update_profile') {
$name = trim($_POST['name'] ?? '');
$email = mb_strtolower(trim($_POST['email'] ?? ''));
if ($name === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
setFlash('error', 'Ange giltigt namn och e-post.');
redirect('/index.php?tab=installningar');
}
$dup = db()->prepare('SELECT id FROM users WHERE email = :email AND id <> :id LIMIT 1');
$dup->execute(['email' => $email, 'id' => $userId]);
if ($dup->fetch()) {
setFlash('error', 'E-postadressen används redan av ett annat konto.');
redirect('/index.php?tab=installningar');
}
$stmt = db()->prepare('UPDATE users SET name = :name, email = :email WHERE id = :id');
$stmt->execute(['name' => $name, 'email' => $email, 'id' => $userId]);
setFlash('success', 'Profil uppdaterad.');
redirect('/index.php?tab=installningar');
}
if ($action === 'update_password') {
$current = $_POST['current_password'] ?? '';
$new = $_POST['new_password'] ?? '';
if (mb_strlen($new) < 8) {
setFlash('error', 'Nytt lösenord måste vara minst 8 tecken.');
redirect('/index.php?tab=installningar');
}
$stmt = db()->prepare('SELECT password_hash FROM users WHERE id = :id LIMIT 1');
$stmt->execute(['id' => $userId]);
$row = $stmt->fetch();
if (!$row || !password_verify($current, $row['password_hash'])) {
setFlash('error', 'Nuvarande lösenord stämmer inte.');
redirect('/index.php?tab=installningar');
}
$update = db()->prepare('UPDATE users SET password_hash = :password_hash WHERE id = :id');
$update->execute([
'password_hash' => password_hash($new, PASSWORD_DEFAULT),
'id' => $userId,
]);
setFlash('success', 'Lösenord uppdaterat.');
redirect('/index.php?tab=installningar');
}
if ($action === 'update_theme') {
$theme = $_POST['theme_preference'] ?? 'light';
saveUserTheme($userId, $theme);
setFlash('success', 'Tema sparat.');
redirect('/index.php?tab=installningar');
}
}
$flash = getFlash();
$currentTheme = getUserTheme($userId);
?>
<article class="card panel">
<h3>Kontoinställningar</h3>
<?php if ($flash): ?>
<div class="notice <?= e($flash['type']) ?>"><?= e($flash['message']) ?></div>
<?php endif; ?>
<div class="settings-grid">
<form method="post" class="stack card inset-card">
<input type="hidden" name="csrf_token" value="<?= e(csrfToken()) ?>">
<input type="hidden" name="action" value="update_profile">
<h4>Profil</h4>
<label class="field">
<span>Namn</span>
<input type="text" name="name" required value="<?= e($user['name']) ?>">
</label>
<label class="field">
<span>E-post</span>
<input type="email" name="email" required value="<?= e($user['email']) ?>">
</label>
<button class="btn" type="submit">Spara profil</button>
</form>
<form method="post" class="stack card inset-card">
<input type="hidden" name="csrf_token" value="<?= e(csrfToken()) ?>">
<input type="hidden" name="action" value="update_password">
<h4>Byt lösenord</h4>
<label class="field">
<span>Nuvarande lösenord</span>
<input type="password" name="current_password" required>
</label>
<label class="field">
<span>Nytt lösenord</span>
<input type="password" name="new_password" minlength="8" required>
</label>
<button class="btn" type="submit">Uppdatera lösenord</button>
</form>
<form method="post" class="stack card inset-card">
<input type="hidden" name="csrf_token" value="<?= e(csrfToken()) ?>">
<input type="hidden" name="action" value="update_theme">
<h4>Utseende</h4>
<label class="field">
<span>Tema</span>
<select name="theme_preference">
<option value="light" <?= $currentTheme === 'light' ? 'selected' : '' ?>>Light</option>
<option value="dark" <?= $currentTheme === 'dark' ? 'selected' : '' ?>>Dark</option>
</select>
</label>
<button class="btn" type="submit">Spara tema</button>
</form>
<div class="stack form-actions">
<h3>TIPS! Lägg till sidan på din hemskärm som en web-app! (iPhone)</h3>
<div style="display: flex;">
<img style="border-top-left-radius: 16px; border-bottom-left-radius: 16px;" src="https://images.macrumors.com/t/32ZDJ7-FKIjKi8kRFCKi9As6gD0=/800x0/article-new/2025/08/ios-add-to-home-screen1.jpg?lossy" width="50%" alt="">
<img style="border-top-right-radius: 16px; border-bottom-right-radius: 16px;" src="https://images.macrumors.com/t/edvsfRer7wqkzfFM4bXbKBb8qyg=/800x0/article-new/2025/08/ios-add-to-home-screen2.jpg?lossy" width="50%" alt="">
</div>
</div>
<div class="stack form-actions" style="margin-top: 16px;">
<a class="btn btn-danger" href="<?= e(url('auth/logout.php')) ?>">Logga ut</a>
</div>
</div>
</article>