mirror of
https://codeberg.org/ThisIsMiseryy/techstore
synced 2026-05-14 14:52:04 +00:00
Merge branch 'feature/account-page'
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
session_start();
|
||||
include 'db_conf.php';
|
||||
|
||||
// Query per ottenere tutti i prodotti
|
||||
$sql = "SELECT p.ProductID, p.ProductName, c.Name AS 'CategoryName', p.Description, p.Price, p.StockQuantity, p.ImagePath FROM Products p JOIN Categories c ON p.CategoryID=c.CategoryID";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
if ($result === false) {
|
||||
die("Errore nella query: " . $conn->error);
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Il mio account - TechStore</title>
|
||||
<link rel="stylesheet" href="assets/style.css">
|
||||
<script src="assets/js/cart.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<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;"><a href="index.php"><img src="img/logo.png" alt="Logo TechStore" height="32px"></a></div>
|
||||
<div>
|
||||
<a href="cart.php"><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['name'])): ?>
|
||||
<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['name']); ?></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>
|
||||
|
||||
<?php if (isset($_SESSION['name'])): ?>
|
||||
<div class="account-layout">
|
||||
<div class="my-sidebar">
|
||||
<ul>
|
||||
<li><a href="account.php">Il mio account</a></li>
|
||||
<li><a href="orders.php">I miei ordini</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="my-container">
|
||||
<h1>Account di <?php echo htmlspecialchars($_SESSION['name']); ?><?php if ($_SESSION['role'] == 'admin') { echo ' (Admin)'; } ?></h1>
|
||||
<p><strong>Nome completo:</strong> <?php echo htmlspecialchars($_SESSION['name']) . ' ' . htmlspecialchars($_SESSION['surname']); ?></p>
|
||||
<br>
|
||||
<a href="deleteAccount.php" style="padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer;">Elimina account</a>
|
||||
<br><br>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<?php header('Location: login.php'); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $conn->close(); ?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -208,4 +208,60 @@ form button:hover {
|
||||
}
|
||||
.checkout-btn:hover {
|
||||
background-color: #218838;
|
||||
}
|
||||
|
||||
/* Layout pagina account */
|
||||
.account-layout {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 20px;
|
||||
max-width: 1100px;
|
||||
margin: 20px auto;
|
||||
padding: 0 20px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.my-sidebar {
|
||||
flex: 0 0 240px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.my-sidebar ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.my-sidebar li {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.my-sidebar a {
|
||||
color: #007bff;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.my-sidebar a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.my-container {
|
||||
flex: 1 1 580px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.account-layout {
|
||||
flex-direction: column;
|
||||
}
|
||||
.my-sidebar,
|
||||
.my-container {
|
||||
flex: 1 1 100%;
|
||||
}
|
||||
}
|
||||
+7
-2
@@ -8,7 +8,8 @@ CREATE TABLE Users(
|
||||
Name VARCHAR(32),
|
||||
Surname VARCHAR(32),
|
||||
Email VARCHAR(256),
|
||||
Password VARCHAR(255)
|
||||
Password VARCHAR(255),
|
||||
Role VARCHAR(8) DEFAULT 'user'
|
||||
);
|
||||
|
||||
CREATE TABLE Categories(
|
||||
@@ -53,4 +54,8 @@ INSERT INTO Categories(Name) VALUES
|
||||
INSERT INTO Products(ProductName,Description,CategoryID,Price,ImagePath,StockQuantity) VALUES
|
||||
('Yealink T31P',"Telefono IP con PoE, Ethernet a 100M, 2 linee",3,'51.21','example/t31p.jpg',104),
|
||||
('Lenovo ThinkCentre M920q','Mini PC (Ricondizionato) Intel Core i5, 512GB SSD, 16GB RAM, Windows 11 Pro',1,'299','example/tcM920q.jpg',69),
|
||||
('Mercusys MS116GS Switch 16 Porte','Switch Gigabit 16 Porte, Montaggio Desktop o Rack, Plug & Play, Priorità del Traffico, Prevenzione Loop, Modalità di Isolamento, Funzionamento Silenzioso, Case in Metallo',2,'44.99','example/mercusysMS116GS.jpg',727);
|
||||
('Mercusys MS116GS Switch 16 Porte','Switch Gigabit 16 Porte, Montaggio Desktop o Rack, Plug & Play, Priorità del Traffico, Prevenzione Loop, Modalità di Isolamento, Funzionamento Silenzioso, Case in Metallo',2,'44.99','example/mercusysMS116GS.jpg',727);
|
||||
|
||||
-- Inserimento utente admin di base (password = changeme)
|
||||
INSERT INTO Users (Name,Surname,Email,Password,Role) VALUES
|
||||
('Ellen', 'Joe', 'admin@example.com', '$2y$12$zEXyLRdKvvvoH4/zuIuwYuQLA5GwsvZw2usIhxxbYyw4.uoeghe4m', 'admin');
|
||||
@@ -16,9 +16,9 @@ session_start();
|
||||
<div id="logo" style="font-size: 24px; font-weight: bold;"><a href="index.php"><img src="img/logo.png" alt="Logo TechStore" height="32px"></a></div>
|
||||
<div>
|
||||
<a href="cart.php"><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'])): ?>
|
||||
<?php if (isset($_SESSION['name'])): ?>
|
||||
<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>
|
||||
<span style="margin-left: 10px;">Benvenuto, <a href="account.php"><?php echo htmlspecialchars($_SESSION['name']); ?></a></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; ?>
|
||||
|
||||
@@ -25,9 +25,9 @@ if ($result === false) {
|
||||
<div id="logo"><img src="img/logo.png" alt="Logo TechStore" height="32px"></div>
|
||||
<div>
|
||||
<a href="cart.php"><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'])): ?>
|
||||
<?php if (isset($_SESSION['name'])): ?>
|
||||
<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>
|
||||
<span style="margin-left: 10px;">Benvenuto, <a href="account.php"><?php echo htmlspecialchars($_SESSION['name']); ?></a></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; ?>
|
||||
|
||||
@@ -17,18 +17,21 @@
|
||||
$email = $_POST['email'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
$sql = "SELECT Name, Password FROM Users WHERE Email = ?";
|
||||
$sql = "SELECT UserID, Name, Surname, Password, Role 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->bind_result($user_id, $name, $surname, $hashed_password, $role);
|
||||
$stmt->fetch();
|
||||
|
||||
if (password_verify($password, $hashed_password)) {
|
||||
$_SESSION['user'] = $name;
|
||||
$_SESSION['id'] = $user_id;
|
||||
$_SESSION['name'] = $name;
|
||||
$_SESSION['surname'] = $surname;
|
||||
$_SESSION['role'] = $role;
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
} else {
|
||||
|
||||
+2
-2
@@ -36,9 +36,9 @@ if ($stmt = $conn->prepare($sql)) {
|
||||
<div id="logo" style="font-size: 24px; font-weight: bold;"><a href="index.php"><img src="img/logo.png" alt="Logo TechStore" height="32px"></a></div>
|
||||
<div>
|
||||
<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'])): ?>
|
||||
<?php if (isset($_SESSION['name'])): ?>
|
||||
<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>
|
||||
<span style="margin-left: 10px;">Benvenuto, <a href="account.php"><?php echo htmlspecialchars($_SESSION['name']); ?></a></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; ?>
|
||||
|
||||
Reference in New Issue
Block a user