Files
kaffeekasse-saas/konto.php
T
clemensandClaude Opus 5 a2dcc4df65 Zwei-Faktor-Anmeldung per TOTP
app/totp.php implementiert RFC 6238 selbst statt per Bibliothek: der
Algorithmus ist ein HMAC plus eine Truncation, und ein zweiter Faktor ist
die letzte Stelle fuer ungepruefte Abhaengigkeiten. Der QR-Code entsteht
aus dem ohnehin vorhandenen TCPDF, damit kein externer Dienst das
Geheimnis sieht.

Beim Login wird die Anmeldung bei aktivem zweitem Faktor nicht
abgeschlossen; der Zwischenzustand gewaehrt keinerlei Zugriff und ist
byte-identisch zu einem unangemeldeten Aufruf. users.totp_last_step
verhindert die Wiederverwendung eines abgefangenen Codes innerhalb seines
Gueltigkeitsfensters. Abschalten verlangt Passwort und Code.

APP_REQUIRE_2FA_FOR_ADMINS macht den Faktor fuer Platform-Admins
verbindlich, per Weiterleitung auf die Einrichtung statt als harte Sperre
- sonst koennte der Schalter den einzigen Admin aussperren. Standard aus.

check-konto-und-mandantenwechsel erwartete beim Login noch das entfernte
Kundenkuerzel-Feld und damit einen direkten Sprung aufs Dashboard; der
Check bildet jetzt den tatsaechlichen Weg ueber die Mandantenauswahl ab.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-23 23:51:45 +02:00

164 lines
6.8 KiB
PHP

<?php
require_once __DIR__ . '/functions.php';
require_once __DIR__ . '/app/features.php';
require_once __DIR__ . '/app/totp.php';
$user = saas_require_login();
$devVerificationToken = null;
$contractMailFailed = !empty($_SESSION['saas_contract_mail_failed']);
$verificationMailFailed = !empty($_SESSION['saas_verification_mail_failed']);
unset($_SESSION['saas_contract_mail_failed'], $_SESSION['saas_verification_mail_failed']);
if (saas_should_show_auth_links() && !empty($_SESSION['saas_dev_email_verification_token'])) {
$devVerificationToken = (string)$_SESSION['saas_dev_email_verification_token'];
unset($_SESSION['saas_dev_email_verification_token']);
}
$passwortFehler = [];
$passwortGeaendert = false;
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['aktion'] ?? '') === 'passwort_aendern') {
app_require_csrf();
$pdo = app_db_pdo();
$ergebnis = saas_change_password(
$pdo,
(int)$user['user_id'],
(string)($_POST['aktuelles_passwort'] ?? ''),
(string)($_POST['neues_passwort'] ?? ''),
(string)($_POST['neues_passwort_confirm'] ?? '')
);
if ($ergebnis['ok']) {
$passwortGeaendert = true;
} else {
$passwortFehler = $ergebnis['errors'];
}
}
include 'header.php';
include 'headerline.php';
include 'nav.php';
?>
<section id="banner">
<div class="content">
<h2>Kundenkonto</h2>
<?php if (isset($_GET['registered'])): ?>
<div class="hint-box success"><p>Das Kundenkonto wurde angelegt.</p></div>
<?php endif; ?>
<?php if ($contractMailFailed): ?>
<div class="hint-box error">
<p>Die Vertragsbestätigung konnte nicht per E-Mail versendet werden. Bitte speichere jetzt <a href="legal/agb-<?php echo saas_html(APP_TERMS_VERSION); ?>.txt" download>die AGB</a>, <a href="legal/avv-<?php echo saas_html(APP_DPA_VERSION); ?>.txt" download>den AVV</a> und bei privater Nutzung <a href="legal/widerruf-<?php echo saas_html(APP_WITHDRAWAL_VERSION); ?>.txt" download>die Widerrufsbelehrung</a>. Falls der Fehler bleibt, nutze bitte das <a href="<?php echo saas_html(app_legal_ticket_url()); ?>">Ticketsystem</a>.</p>
</div>
<?php endif; ?>
<?php if ($verificationMailFailed): ?>
<div class="hint-box error"><p>Die Verifizierungs-E-Mail konnte nicht versendet werden. Bitte versuche den Versand unten erneut oder nutze das <a href="<?php echo saas_html(app_legal_ticket_url()); ?>">Ticketsystem</a>.</p></div>
<?php endif; ?>
<?php if ($devVerificationToken !== null): ?>
<div class="hint-box success">
<p>Der Verifizierungslink wurde vorbereitet.</p>
<p><a href="email-verifizieren.php?token=<?php echo saas_html($devVerificationToken); ?>">Dev-Link zur E-Mail-Verifizierung</a></p>
</div>
<?php endif; ?>
<table>
<tr>
<th>Name</th>
<td><?php echo saas_html($user['display_name']); ?></td>
</tr>
<tr>
<th>E-Mail</th>
<td><?php echo saas_html($user['email']); ?></td>
</tr>
<tr>
<th>Kunde</th>
<td><?php echo saas_html($user['tenant_name']); ?></td>
</tr>
<tr>
<th>Kundenkürzel</th>
<td><?php echo saas_html($user['tenant_slug']); ?></td>
</tr>
<tr>
<th>Rolle</th>
<td><?php echo saas_html($user['role']); ?></td>
</tr>
<tr>
<th>E-Mail bestätigt</th>
<td><?php echo $user['email_verified_at'] !== null ? 'ja' : 'nein'; ?></td>
</tr>
<tr>
<th>Zwei-Faktor-Anmeldung</th>
<td><?php echo app_totp_is_active(app_db_pdo(), (int)$user['user_id']) ? 'aktiv' : 'nicht eingerichtet'; ?>
&ndash; <a href="zwei-faktor-einrichten.php">verwalten</a></td>
</tr>
</table>
<?php if ($user['email_verified_at'] === null): ?>
<form method="post" action="email-verifikation-senden.php">
<?php echo app_csrf_field(); ?>
<button type="submit">E-Mail-Verifizierung vorbereiten</button>
</form>
<?php endif; ?>
<h3>Passwort ändern</h3>
<?php if ($passwortGeaendert): ?>
<div class="hint-box success"><p>Das Passwort wurde geändert.</p></div>
<?php endif; ?>
<?php if ($passwortFehler !== []): ?>
<div class="hint-box error">
<?php foreach ($passwortFehler as $fehler): ?>
<p><?php echo saas_html($fehler); ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<form method="post" action="konto.php">
<?php echo app_csrf_field(); ?>
<input type="hidden" name="aktion" value="passwort_aendern">
<div class="row">
<div class="col-12">
<label for="aktuelles_passwort">Aktuelles Passwort</label>
<input type="password" name="aktuelles_passwort" id="aktuelles_passwort" autocomplete="current-password" required>
</div>
<div class="col-12">
<label for="neues_passwort">Neues Passwort (mindestens 8 Zeichen)</label>
<input type="password" name="neues_passwort" id="neues_passwort" autocomplete="new-password" required>
</div>
<div class="col-12">
<label for="neues_passwort_confirm">Neues Passwort wiederholen</label>
<input type="password" name="neues_passwort_confirm" id="neues_passwort_confirm" autocomplete="new-password" required>
</div>
</div>
<ul class="actions">
<li><button type="submit">Passwort ändern</button></li>
</ul>
</form>
<?php if (saas_can_manage_tenant_settings($user)): ?>
<ul class="actions">
<li><a href="mandant-einstellungen.php" class="button">Mandant-Einstellungen</a></li>
<?php if (app_feature_enabled(app_db_pdo(), (int)$user['tenant_id'], 'data_export')): ?>
<li><a href="datenexport.php" class="button">Datenexport</a></li>
<?php endif; ?>
<?php if (saas_user_has_role('owner', $user)): ?>
<li><a href="mandant-loeschen.php" class="button">Mandant löschen</a></li>
<?php endif; ?>
</ul>
<?php endif; ?>
<form method="post" action="logout.php">
<?php echo app_csrf_field(); ?>
<button type="submit">Abmelden</button>
</form>
</div>
</section>
<?php include 'footer.php'; ?>