mirror of
https://codeberg.org/ThisIsMiseryy/techstore
synced 2026-05-14 14:52:04 +00:00
Merge autenticazione utente
This commit is contained in:
@@ -6,6 +6,7 @@ USE TechStore;
|
||||
CREATE TABLE Users(
|
||||
UserID INTEGER PRIMARY KEY AUTO_INCREMENT,
|
||||
Name VARCHAR(32),
|
||||
Surname VARCHAR(32),
|
||||
Email VARCHAR(256),
|
||||
Password VARCHAR(255)
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
session_start();
|
||||
include 'db_conf.php';
|
||||
|
||||
// Query per ottenere tutti i prodotti
|
||||
@@ -22,8 +23,13 @@ if ($result === false) {
|
||||
<header style="display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f2f2f2; border-bottom: 1px solid #ddd;">
|
||||
<div id="logo" style="font-size: 24px; font-weight: bold;">TechStore</div>
|
||||
<div>
|
||||
<button style="margin-left: 10px; padding: 8px 16px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">Carrello</button>
|
||||
<button style="margin-left: 10px; padding: 8px 16px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Accesso</button>
|
||||
<a href=""><button style="margin-left: 10px; padding: 8px 16px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">Carrello</button></a>
|
||||
<?php if (isset($_SESSION['user'])): ?>
|
||||
<a href="logout.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer;">Logout</button></a>
|
||||
<span style="margin-left: 10px;">Benvenuto, <?php echo htmlspecialchars($_SESSION['user']); ?></span>
|
||||
<?php else: ?>
|
||||
<a href="login.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Accesso</button></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login - TechStore</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
session_start();
|
||||
include 'db_conf.php';
|
||||
|
||||
$error = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$email = $_POST['email'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
$sql = "SELECT Name, Password FROM Users WHERE Email = ?";
|
||||
if ($stmt = $conn->prepare($sql)) {
|
||||
$stmt->bind_param("s", $email);
|
||||
$stmt->execute();
|
||||
$stmt->store_result();
|
||||
|
||||
if ($stmt->num_rows > 0) {
|
||||
$stmt->bind_result($name, $hashed_password);
|
||||
$stmt->fetch();
|
||||
|
||||
if (password_verify($password, $hashed_password)) {
|
||||
$_SESSION['user'] = $name;
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
} else {
|
||||
$error = 'Credenziali errate.';
|
||||
}
|
||||
} else {
|
||||
$error = 'Credenziali errate.';
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
} else {
|
||||
$error = 'Errore nel database.';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<form action="" method="POST">
|
||||
<h2>Login</h2>
|
||||
<label for="email">Indirizzo e-mail:</label>
|
||||
<input type="email" id="email" name="email" required><br>
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" name="password" required><br><br>
|
||||
<button type="submit">Login</button>
|
||||
<p style="text-align: center;">Non hai un account? <a href="register.php">Registrati</a></p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_destroy();
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
?>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
include 'db_conf.php';
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Registrazione - TechStore</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$sql = "INSERT INTO Users (Name, Surname, Email, Password) VALUES (?, ?, ?, ?)";
|
||||
if($stmt = $conn->prepare($sql)){
|
||||
$stmt->bind_param("ssss", $name, $surname, $email, $password);
|
||||
|
||||
$name = $_POST['name'];
|
||||
$surname = $_POST['surname'];
|
||||
$email = $_POST['email'];
|
||||
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
|
||||
$stmt->execute();
|
||||
|
||||
echo "<p style='color: green; text-align: center;'>Registrazione avvenuta con successo! <a href=\"login.php\">Accedi</a></p>";
|
||||
}
|
||||
else{
|
||||
echo "Errore: " . $conn->error;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<form action="" method="POST">
|
||||
<h2>Registrazione</h2>
|
||||
<label for="name">Nome:</label>
|
||||
<input type="text" id="name" name="name" required><br>
|
||||
<label for="surname">Cognome:</label>
|
||||
<input type="text" id="surname" name="surname" required><br>
|
||||
<label for="email">Indirizzo e-mail:</label>
|
||||
<input type="email" id="email" name="email" required><br>
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" name="password" required><br>
|
||||
<label for="confirm_password">Conferma password:</label>
|
||||
<input type="password" id="confirm_password" name="confirm_password" required><br><br>
|
||||
<button type="submit">Registrati</button>
|
||||
<p style="text-align: center;">Hai già un account? <a href="login.php">Accedi</a></p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -35,4 +35,54 @@
|
||||
}
|
||||
.product-card button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
|
||||
/* Stili per il form di login */
|
||||
form {
|
||||
max-width: 400px;
|
||||
margin: 50px auto;
|
||||
padding: 20px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
background-color: #f9f9f9;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
form h2 {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
form label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
form input[type="text"],
|
||||
form input[type="password"],
|
||||
form input[type="email"] {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
form button {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
form button:hover {
|
||||
background-color: #218838;
|
||||
}
|
||||
Reference in New Issue
Block a user