comments in controllers hinzugefügt + review + testing
This commit is contained in:
Regular → Executable
+7
-1
@@ -2,6 +2,7 @@
|
||||
|
||||
class AuthController
|
||||
{
|
||||
// Zeigt das Login-Formular
|
||||
public function showLogin(): void
|
||||
{
|
||||
View::render('auth/login', [
|
||||
@@ -10,6 +11,7 @@ class AuthController
|
||||
]);
|
||||
}
|
||||
|
||||
// Prueft die Anmeldedaten und startet die Sitzung
|
||||
public function login(): void
|
||||
{
|
||||
verify_csrf_token();
|
||||
@@ -50,6 +52,7 @@ class AuthController
|
||||
redirect('dashboard');
|
||||
}
|
||||
|
||||
// Zeigt das Registrierungsformular
|
||||
public function showRegister(): void
|
||||
{
|
||||
View::render('auth/register', [
|
||||
@@ -58,6 +61,7 @@ class AuthController
|
||||
]);
|
||||
}
|
||||
|
||||
// Legt ein neues Konto an
|
||||
public function register(): void
|
||||
{
|
||||
verify_csrf_token();
|
||||
@@ -109,11 +113,13 @@ class AuthController
|
||||
redirect('login');
|
||||
}
|
||||
|
||||
// Beendet die Sitzung
|
||||
public function logout(): void
|
||||
{
|
||||
verify_csrf_token();
|
||||
|
||||
$_SESSION = [];
|
||||
|
||||
if (ini_get('session.use_cookies')) {
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), '', time() - 42000, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
|
||||
@@ -151,4 +157,4 @@ class AuthController
|
||||
|
||||
return is_string($value) ? $value : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
Regular → Executable
+9
-1
@@ -2,6 +2,7 @@
|
||||
|
||||
class HabitController
|
||||
{
|
||||
// Zeigt das Dashboard mit allen Habits des Benutzers
|
||||
public function dashboard(): void
|
||||
{
|
||||
require_login();
|
||||
@@ -26,6 +27,7 @@ class HabitController
|
||||
]);
|
||||
}
|
||||
|
||||
// Zeigt das leere Formular zum Anlegen
|
||||
public function create(): void
|
||||
{
|
||||
require_login();
|
||||
@@ -37,6 +39,7 @@ class HabitController
|
||||
]);
|
||||
}
|
||||
|
||||
// Speichert einen neuen Habit
|
||||
public function store(): void
|
||||
{
|
||||
require_login();
|
||||
@@ -58,6 +61,7 @@ class HabitController
|
||||
redirect('dashboard');
|
||||
}
|
||||
|
||||
// Zeigt das Formular zum Bearbeiten
|
||||
public function edit(): void
|
||||
{
|
||||
require_login();
|
||||
@@ -76,6 +80,7 @@ class HabitController
|
||||
]);
|
||||
}
|
||||
|
||||
// Uebernimmt die Aenderungen eines bestehenden Habits
|
||||
public function update(): void
|
||||
{
|
||||
require_login();
|
||||
@@ -85,6 +90,7 @@ class HabitController
|
||||
$data = $this->validatedData();
|
||||
|
||||
if (!empty($data['errors'])) {
|
||||
// ID mitgeben, sonst zeigt das Formular auf keinen Datensatz mehr
|
||||
View::render('habits/form', [
|
||||
'habit' => array_merge($_POST, ['id' => $id]),
|
||||
'categories' => Category::all(),
|
||||
@@ -98,6 +104,7 @@ class HabitController
|
||||
redirect('dashboard');
|
||||
}
|
||||
|
||||
// Loescht einen Habit
|
||||
public function delete(): void
|
||||
{
|
||||
require_login();
|
||||
@@ -135,6 +142,7 @@ class HabitController
|
||||
$errors['description'] = 'Die Beschreibung darf maximal 1000 Zeichen lang sein.';
|
||||
}
|
||||
|
||||
// Gegen die Datenbank pruefen, damit keine erfundene ID durchkommt
|
||||
if ($categoryId !== '' && !Category::exists((int) $categoryId)) {
|
||||
$errors['category_id'] = 'Bitte waehle eine gueltige Kategorie aus.';
|
||||
}
|
||||
@@ -151,4 +159,4 @@ class HabitController
|
||||
'errors' => $errors,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Regular → Executable
+10
-4
@@ -2,6 +2,7 @@
|
||||
|
||||
class ReminderController
|
||||
{
|
||||
// Zeigt das Formular zum Anlegen einer Erinnerung
|
||||
public function create(): void
|
||||
{
|
||||
require_login();
|
||||
@@ -20,6 +21,7 @@ class ReminderController
|
||||
]);
|
||||
}
|
||||
|
||||
// Speichert eine neue Erinnerung
|
||||
public function store(): void
|
||||
{
|
||||
require_login();
|
||||
@@ -52,6 +54,7 @@ class ReminderController
|
||||
redirect('dashboard');
|
||||
}
|
||||
|
||||
// Zeigt das Formular zum Bearbeiten
|
||||
public function edit(): void
|
||||
{
|
||||
require_login();
|
||||
@@ -105,6 +108,7 @@ class ReminderController
|
||||
redirect('dashboard');
|
||||
}
|
||||
|
||||
// Loescht eine Erinnerung
|
||||
public function delete(): void
|
||||
{
|
||||
require_login();
|
||||
@@ -144,10 +148,12 @@ class ReminderController
|
||||
$activeValue = $this->postString('is_active');
|
||||
$errors = [];
|
||||
|
||||
if (!preg_match('/^(?:[01]\\d|2[0-3]):[0-5]\\d$/', $time)) {
|
||||
// Uhrzeit muss dem Format HH:MM zwischen 00:00 und 23:59
|
||||
if (!preg_match('/^(?:[01]\d|2[0-3]):[0-5]\d$/', $time)) {
|
||||
$errors['reminder_time'] = 'Bitte gib eine Uhrzeit im Format HH:MM ein.';
|
||||
}
|
||||
|
||||
// Leerer Wochentag ist erlaubt und bedeutet taeglich
|
||||
if ($weekdayValue !== '' && !preg_match('/^[1-7]$/', $weekdayValue)) {
|
||||
$errors['weekday'] = 'Bitte waehle einen gueltigen Wochentag aus.';
|
||||
}
|
||||
@@ -168,14 +174,14 @@ class ReminderController
|
||||
{
|
||||
$value = $_GET[$key] ?? '';
|
||||
|
||||
return is_string($value) && preg_match('/^[1-9]\\d*$/', $value) ? (int) $value : 0;
|
||||
return is_string($value) && preg_match('/^[1-9]\d*$/', $value) ? (int) $value : 0;
|
||||
}
|
||||
|
||||
private function postId(string $key): int
|
||||
{
|
||||
$value = $_POST[$key] ?? '';
|
||||
|
||||
return is_string($value) && preg_match('/^[1-9]\\d*$/', $value) ? (int) $value : 0;
|
||||
return is_string($value) && preg_match('/^[1-9]\d*$/', $value) ? (int) $value : 0;
|
||||
}
|
||||
|
||||
private function postString(string $key): string
|
||||
@@ -184,4 +190,4 @@ class ReminderController
|
||||
|
||||
return is_string($value) ? trim($value) : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
Regular → Executable
Regular → Executable
+4
-1
@@ -31,6 +31,7 @@ class Reminder
|
||||
return $statement->fetchAll();
|
||||
}
|
||||
|
||||
// Legt eine Erinnerung an
|
||||
public static function createForHabit(int $habitId, int $userId, array $data): bool
|
||||
{
|
||||
$statement = Database::connection()->prepare(
|
||||
@@ -50,6 +51,7 @@ class Reminder
|
||||
return $statement->rowCount() === 1;
|
||||
}
|
||||
|
||||
// Aktualisiert eine Erinnerung
|
||||
public static function update(int $id, int $userId, array $data): bool
|
||||
{
|
||||
$statement = Database::connection()->prepare(
|
||||
@@ -82,6 +84,7 @@ class Reminder
|
||||
return $statement->execute(['id' => $id, 'user_id' => $userId]);
|
||||
}
|
||||
|
||||
// Schaltet zwischen aktiv und pausiert um
|
||||
public static function toggle(int $id, int $userId): bool
|
||||
{
|
||||
$statement = Database::connection()->prepare(
|
||||
@@ -93,4 +96,4 @@ class Reminder
|
||||
|
||||
return $statement->execute(['id' => $id, 'user_id' => $userId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user