first commit

This commit is contained in:
2026-04-11 18:57:00 +02:00
commit 58bcc8f0f3
29 changed files with 3290 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
final class Auth
{
public function __construct(private UserRepository $users)
{
}
public function check(): bool
{
return isset($_SESSION['user']) && is_array($_SESSION['user']);
}
public function user(): ?array
{
if (!$this->check()) {
return null;
}
return $_SESSION['user'];
}
public function attempt(string $username, string $password): bool
{
$user = $this->users->verify($username, $password);
if ($user === null) {
return false;
}
$this->login($user);
return true;
}
public function login(array $user): void
{
session_regenerate_id(true);
$_SESSION['user'] = [
'username' => $user['username'],
'is_admin' => (bool) ($user['is_admin'] ?? false),
];
}
public function logout(): void
{
unset($_SESSION['user']);
session_regenerate_id(true);
}
}
+69
View File
@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
final class Defaults
{
public static function settings(): array
{
return [
'labels' => [
'sleep_feeling' => [
1 => 'hundemüde',
2 => 'müde',
3 => 'geht so',
4 => 'ausgeschlafen',
5 => 'sehr ausgeschlafen',
],
],
'scoring' => [
'mood_multiplier' => 3,
'energy_multiplier' => 2,
'stress_multiplier' => 2,
'sleep_feeling_multiplier' => 2,
'sleep_duration_points' => [
'lt4' => 0,
'h4' => 2,
'h5' => 5,
'h6' => 8,
'h7' => 10,
'h8' => 9,
'h9' => 7,
'h10plus' => 5,
],
'sport_bands' => [
['min' => 0, 'max' => 0, 'points' => 0],
['min' => 1, 'max' => 20, 'points' => 2],
['min' => 21, 'max' => 45, 'points' => 5],
['min' => 46, 'max' => 10000, 'points' => 7],
],
'walk_bands' => [
['min' => 0, 'max' => 0, 'points' => 0],
['min' => 1, 'max' => 15, 'points' => 2],
['min' => 16, 'max' => 40, 'points' => 5],
['min' => 41, 'max' => 10000, 'points' => 7],
],
'journal_points' => 2,
],
'ratings' => [
['label' => 'Scheißtag', 'min' => 0, 'max' => 39],
['label' => 'schwerer Tag', 'min' => 40, 'max' => 54],
['label' => 'okayer Tag', 'min' => 55, 'max' => 69],
['label' => 'guter Tag', 'min' => 70, 'max' => 84],
['label' => 'super Tag', 'min' => 85, 'max' => 106],
],
'guardrails' => [
[
'mood_max' => 3,
'energy_max' => null,
'cap_label' => 'okayer Tag',
],
[
'mood_max' => 2,
'energy_max' => 3,
'cap_label' => 'schwerer Tag',
],
],
];
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
final class View
{
public static function render(string $template, array $data = []): void
{
$pageTitle = $data['pageTitle'] ?? 'Mood';
$page = $data['page'] ?? 'dashboard';
$authUser = $data['authUser'] ?? null;
$flashes = pull_flashes();
extract($data, EXTR_SKIP);
ob_start();
require base_path('templates/pages/' . $template . '.php');
$content = (string) ob_get_clean();
require base_path('templates/layout.php');
}
}