Webbserver - Love Blomberg

Show sourcecode

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

public_html/smartkortet/auth/

login.php
logout.php
register.php

register.php

84 lines UTF-8 Windows (CRLF)
<?php

declare(strict_types=1);

require_once 
__DIR__ '/../includes/functions.php';
startAppSession();

require_once 
__DIR__ '/../includes/auth.php';

requireGuest();

$error '';

if (
$_SERVER['REQUEST_METHOD'] === 'POST') {
    
verifyCsrf();

    [
$ok$text] = registerUser(
        
$_POST['name'] ?? '',
        
$_POST['email'] ?? '',
        
$_POST['password'] ?? ''
    
);

    if (
$ok) {
        
setFlash('success'$text);
        
redirect('/auth/login.php');
    } else {
        
$error $text;
    }
}

$csrf csrfToken();
?>
<!doctype html>
<html lang="sv">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="apple-mobile-web-app-title" content="Smartkortet">
    <meta name="theme-color" content="#0b1220">
    <title>Skapa konto | Smartkortet</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="<?= e(url('assets/css/style.css')) ?>">
    <link rel="icon" href="<?= e(url('assets/icon.svg')) ?>" type="image/svg+xml">
    <link rel="shortcut icon" href="<?= e(url('assets/icon.svg')) ?>" type="image/svg+xml">
    <link rel="apple-touch-icon" sizes="180x180" href="<?= e(url('assets/icon-180.png')) ?>">
    <link rel="apple-touch-icon" sizes="512x512" href="<?= e(url('assets/icon-512.png')) ?>">
</head>
<body data-theme="dark">
    <main class="auth-shell">
        <section class="card auth-card">
            <h1>Skapa ditt konto</h1>
            <p class="subtitle">Spara saldo, köp och statistik i molnet.</p>

            <?php if ($error !== ''): ?>
                <div class="notice error"><?= e($error?></div>
            <?php endif; ?>

            <form method="post" class="stack">
                <input type="hidden" name="csrf_token" value="<?= e($csrf?>">
                <label class="field">
                    <span>Namn</span>
                    <input type="text" name="name" required>
                </label>
                <label class="field">
                    <span>E-post</span>
                    <input type="email" name="email" required>
                </label>
                <label class="field">
                    <span>Lösenord</span>
                    <input type="password" name="password" minlength="8" required>
                </label>
                <button class="btn" type="submit">Skapa konto</button>
            </form>

            <p class="auth-switch">Har du redan konto? <a href="<?= e(url('auth/login.php')) ?>">Logga in</a></p>
        </section>
    </main>
</body>
</html>