Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/submissions/projekt-matkort-handler/
.github/
add_logs.php
admin/
api/
card_balance.php
classes/
config/
food_logs.php
forgot_password.php
includes/
index.php
insert_restaurants.php
install.php
login.php
logout.php
public/
register.php
reset_password.php
verify.php
register.php
134 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
include_once './config/database.php';
include_once './classes/User.php';
$error = '';
$success = '';
// Processing
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = htmlspecialchars(trim($_POST['name']));
$email = htmlspecialchars(trim($_POST['email']));
$password = htmlspecialchars(trim($_POST['password']));
$confirm_password = htmlspecialchars(trim($_POST['confirm_password']));
// Validation
if (empty($name) || empty($email) || empty($password)) {
$error = "Alla fält måste fyllas i.";
}
elseif (strlen($email) < 3) {
$error = "Användarnamn måste vara minst 3 tecken.";
}
elseif (strlen($password) < 6) {
$error = "Lösenord måste vara minst 6 tecken.";
}
elseif ($password !== $confirm_password) {
$error = "Lösenorden matchar inte.";
} else {
try {
$token = User::register($pdo, $name, $email, $password);
$actual_link = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/verify.php?token=" . $token;
if ($local) {
// Mock email being "sent" on screen for local dev
$success = 'Konto skapat! Vänligen kolla din e-post (15 min innan länk går ut).<br><br>
<span style="font-size:12px; color:#555;">[DEV MOCK EMAIL MSG] KLICKA HÄR FÖR ATT VERIFIERA:<br>
<a href="'.$actual_link.'">'.$actual_link.'</a></span>';
} else {
// Real production email
$subject = "Verifiera ditt konto - Matkort Handler";
$message = "Välkommen!\n\nKlicka på följande länk för att verifiera ditt konto:\n\n" . $actual_link . "\n\n(Länken slutar fungera om 15 minuter)";
$headers = "From: noreply@" . $_SERVER['HTTP_HOST'] . "\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
mail($email, $subject, $message, $headers);
$success = "Konto skapat! En verifieringslänk har skickats till din e-post. Titta i skräpposten om du inte hittar den.";
}
} catch (Exception $e) {
$error = $e->getMessage();
}
}
}
$page_title = 'Registrera';
require_once './includes/header.php';
?>
<div class="auth-container">
<div class="auth-box">
<h1>Skapa konto</h1>
<?php if ($error): ?>
<div class="error-message">
<?php echo htmlspecialchars($error); ?>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div class="success-message">
<?php echo htmlspecialchars($success); ?>
</div>
<?php endif; ?>
<form method="POST" action="register.php">
<div class="form-group">
<label for="name">Namn:</label>
<input
type="text"
id="name"
name="name"
value="<?php echo isset($_POST['name']) ? htmlspecialchars($_POST['name']) : ''; ?>"
required
>
</div>
<div class="form-group">
<label for="username">Epost:</label>
<input
type="email"
id="email"
name="email"
value="<?php echo isset($_POST['email']) ? htmlspecialchars($_POST['email']) : ''; ?>"
required
>
</div>
<div class="form-group">
<label for="password">Lösenord:</label>
<input
type="password"
id="password"
name="password"
required
>
</div>
<div class="form-group">
<label for="confirm_password">Bekräfta lösenord:</label>
<input
type="password"
id="confirm_password"
name="confirm_password"
required
>
</div>
<button type="submit" class="btn btn-primary">Registrera</button>
</form>
<p class="register-link">
Har du redan ett konto? <a href="./login.php">Logga in här</a>
</p>
</div>
</div>
<?php require_once './includes/footer.php'; ?>