Initial commit

This commit is contained in:
ldy
2025-06-06 17:14:52 +08:00
parent 0465a9baef
commit f0aabfb5ac
91 changed files with 4466 additions and 0 deletions

38
login/RegisterByDB.php Normal file
View File

@@ -0,0 +1,38 @@
<?php
include "../indexes/ConnectDB.php";
//get posted messages
$user = $_POST["user"]; // username from login form
$pwd = $_POST["pwd"]; // password from login form
$user_type = $_POST["user_type"]; // password from login form
// check if user is empty
$sql_regname = "SELECT * FROM $user_type WHERE name = '$user'";
$res = mysqli_query($conn, $sql_regname);
$row = mysqli_num_rows($res);
if($row == 0){
if($user){
// prepare sql
$sql_insert = "INSERT INTO `$user_type` (`name`, `pwd`) VALUES ('$user', '$pwd')";
$result = mysqli_query($conn, $sql_insert); //if success, return 1
// redirect to interfaces
if($result > 0){
echo "<script type='text/javascript'>
window.location.href = './interfaces/register_success.php';
</script>";
}
else {
echo "<script type='text/javascript'>
window.location.href = './interfaces/register_interrupted.php';
</script>";
}
}
}
else{
echo "<script type='text/javascript'>
window.location.href = './interfaces/register_failed.php';
</script>";
}
?>

18
login/index_login.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
include "../indexes/ConnectDB.php";
// Start the session
session_start();
// Check if the user is already logged in
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
echo "<script type='text/javascript'>
window.top.location.href = '../home.php';
</script>";
}
else {
echo "<script type='text/javascript'>
window.location.href = './login.html';
</script>";
}
?>

View File

@@ -0,0 +1,17 @@
#area{
position: absolute;
text-align: center;
width: 300px;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
user-select: none;
font-family: Arial, Helvetica, sans-serif;
}
img{
width: 45%;
height: 45%;
margin: none;
}

View File

@@ -0,0 +1,16 @@
<html>
<head>
<title>Admin</title>
<link rel="stylesheet" href="./profile.css" type="text/css" />
</head>
<body>
<div id="area">
<img src="../../icon/admin.svg">
<h2 style="margin: none;"><?php session_start(); echo $_SESSION['username']; ?></h2>
<p>User Type: Administrator</p>
<a href="../logout.php" style="text-decoration: none; color: white; background-color: rgba(69, 67, 67, 0.6);
border-radius: 5px; align-items: center; left: 50%;">Log out</a>
</div>
</body>
</html>

View File

@@ -0,0 +1,30 @@
<html>
<head>
<title>User</title>
<link rel="stylesheet" href="./profile.css" type="text/css" />
</head>
<body>
<div id="area">
<img src="../../icon/buyer.svg">
<h2 style="margin: none;">
<?php
include '../../indexes/ConnectDB.php';
session_start();
echo $_SESSION['username'];
?>
</h2>
<p>User Type: Buyer</p>
<?php
$sql = "SELECT money FROM buyer WHERE name='" . $_SESSION['username'] . "'";
$res = mysqli_query($conn, $sql);
$money = mysqli_fetch_array($res);
?>
<p>Balance: ¥<?php echo $money['money']; ?></p>
<a href="../../indexes/process/receipt.php" style="text-decoration: none; color: white; background-color: rgba(69, 67, 67, 0.6);
border-top-left-radius: 5px; border-bottom-left-radius: 5px;">My Receipt</a>
<a href="../logout.php" style="text-decoration: none; color: white; background-color: rgba(69, 67, 67, 0.6);
border-top-right-radius: 5px; border-bottom-right-radius: 5px;">Log out</a>
</div>
</body>
</html>

View File

@@ -0,0 +1,18 @@
<html>
<head>
<title>Error Occurred</title>
<link rel="stylesheet" href="./instruct.css" type="text/css" />
</head>
<body>
<div id="area">
<img src="../../icon/close.svg">
<h2 style="margin: none; padding: none;">Oops!</h2>
<h2>Your Username or Password is incorrect!</h2>
<a href='../../login.html' style="text-decoration: none;">Try again</a>
<script type='text/javascript'>
setTimeout(function() {window.location.href = '../login.html';}, 1500);
</script>
</div>
</body>
</html>

View File

@@ -0,0 +1,31 @@
<html>
<head>
<title>Seller</title>
<link rel="stylesheet" href="./profile.css" type="text/css" />
</head>
<body>
<div id="area">
<img src="../../icon/seller.svg">
<h2 style="margin: none;">
<?php
include '../../indexes/ConnectDB.php';
session_start();
echo $_SESSION['username'];
?>
</h2>
<p>User Type: Seller</p>
<?php
$sql = "SELECT profit FROM seller WHERE name='" . $_SESSION['username'] . "'";
$res = mysqli_query($conn, $sql);
$money = mysqli_fetch_array($res);
?>
<p>Profit: ¥<?php echo $money['profit']; ?></p>
<a href="../../indexes/process/receipt.php" style="text-decoration: none; color: white; background-color: rgba(69, 67, 67, 0.6);
border-top-left-radius: 5px; border-bottom-left-radius: 5px;">My Receipt</a>
<a href="../logout.php" style="text-decoration: none; color: white; background-color: rgba(69, 67, 67, 0.6);
border-top-right-radius: 5px; border-bottom-right-radius: 5px;">Log out</a>
</div>
</body>
</html>

View File

@@ -0,0 +1,16 @@
<html>
<head>
<title>Success</title>
<link rel="stylesheet" href="./instruct.css" type="text/css" />
</head>
<body>
<div id="area">
<img src="../../icon/check.svg">
<h1>Welcome, <?php include '../../indexes/ConnectDB.php'; session_start(); echo $_SESSION['username']; ?>!</h1>
<script type='text/javascript'>
setTimeout(function() {window.top.location.href = '../../home.php';}, 1000);
</script>
</div>
</body>
</html>

View File

@@ -0,0 +1,34 @@
#area{
position: absolute;
text-align: center;
width: 200px;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
user-select: none;
font-family: Arial, Helvetica, sans-serif;
}
img{
width: 100%;
height: 100px;
margin: none;
margin-top: 10%;
}
a{
display:table-cell;
vertical-align: middle;
border: 1px solid rgba(35, 34, 34, 0.6);
width: 200px;
height: 32px;
line-height: 30px;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
box-shadow: 0px 0px 0px rgba(69, 67, 67, 0.6);
transition: 0.3s;
cursor: hand;
}
a:hover {
box-shadow: 0px 0px 10px #424242;
}

View File

@@ -0,0 +1,18 @@
<html>
<head>
<title>Error Occurred</title>
<link rel="stylesheet" href="./instruct.css" type="text/css" />
</head>
<body>
<div id="area">
<img src="../../icon/close.svg">
<h2 style="margin: none; padding: none;">Oops!</h2>
<h2>your username seems has already been registered.</h2>
<a href='../../login.html' style="text-decoration: none;">Try again</a>
<script type='text/javascript'>
setTimeout(function() {window.location.href = '../register.html';}, 1500);
</script>
</div>
</body>
</html>

View File

@@ -0,0 +1,18 @@
<html>
<head>
<title>Error Occurred</title>
<link rel="stylesheet" href="./instruct.css" type="text/css" />
</head>
<body>
<div id="area">
<img src="../../icon/close.svg">
<h2 style="margin: none; padding: none;">Oops!</h2>
<h2>Errors occurred during registeration, please try agian later.</h2>
<a href='../../login.html' style="text-decoration: none;">Try again</a>
<script type='text/javascript'>
setTimeout(function() {window.location.href = '../register.html';}, 1500);
</script>
</div>
</body>
</html>

View File

@@ -0,0 +1,16 @@
<html>
<head>
<title>Success</title>
<link rel="stylesheet" href="./instruct.css" type="text/css" />
</head>
<body>
<div id="area">
<img src="../../icon/check.svg">
<h1>Successfully registered!</h1>
<script type='text/javascript'>
setTimeout(function() {window.location.href = '../login.html';}, 1000);
</script>
</div>
</body>
</html>

66
login/login.css Normal file
View File

@@ -0,0 +1,66 @@
#area{
position: absolute;
text-align: center;
width: 300px;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
user-select: none;
font-family: Arial, Helvetica, sans-serif;
}
input{
background-color: rgba(255, 255, 255, 0.5);
border-radius: 5px;
border-top: none;
border-left: none;
border-right: none;
outline: none;
border-bottom: 1px solid grey;
height: 32px;
width: 300px;
box-shadow: 0px 0px 0px #424242;
transition: 0.3s;
backdrop-filter: blur(20px);
}
input:focus{
background-color: rgb(234, 241, 254);
box-shadow: 0px 0px 10px #424242;
}
input:hover{
box-shadow: 0px 0px 10px #424242;
}
label {
display:table-cell;
vertical-align: middle;
border: 1px solid rgba(35, 34, 34, 0.6);
width: 300px;
height: 32px;
line-height: 30px;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
box-shadow: 0px 0px 0px rgba(69, 67, 67, 0.6);
transition: 0.3s;
cursor: hand;
}
label:hover {
box-shadow: 0px 0px 10px #424242;
}
button{
height: 32px;
width: 300px;
border: solid white 0px;
background: linear-gradient(to right, rgb(26, 117, 172), rgb(26, 158, 144));
color: white;
cursor: hand;
box-shadow: 0px 0px 0px #424242;
transition: 0.3s;
border-radius: 5px;
}
button:hover {
box-shadow: 0px 0px 10px #424242;
}
p{
font-family: Arial, Helvetica, sans-serif;
}

59
login/login.html Normal file
View File

@@ -0,0 +1,59 @@
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="./login.css" type="text/css" />
</head>
<body>
<div id="area" style="text-align: center;">
<h1>Login</h1>
<!--input area-->
<form action = "./login.php" method="POST">
<input type="text" name="user" placeholder="Username" required>
<br><br>
<input type="password" name="pwd" placeholder="Password" required>
<br><br>
<label for="buyer" id="lb_buyer" onmousedown="implement(this)"
style="border-top-left-radius: 5px; border-bottom-left-radius: 5px;">Buyer</label>
<input type="radio" value="buyer" name="user_type" id="buyer" hidden required/>
<label for="seller" id="lb_seller" onmousedown="implement(this)">Seller</label>
<input type="radio" value="seller" name="user_type" id="seller" hidden required/>
<label for="admin" id="lb_admin" onmousedown="implement(this)"
style="border-top-right-radius: 5px; border-bottom-right-radius: 5px;">Administrator</label>
<input type="radio" value="admin" name="user_type" id="admin" oninvalid="radio_alert()" hidden required/>
<p id="msg" style="color: red; font-size: small; padding: none; margin: none;"></p>
<button type="submit">Log in</button>
</form>
<p style="font-size: small;">Don't have an account? <a href="register.html" style="text-decoration: none;">Sign up</a></p>
</div>
<script>
//beautify label
function implement(tag){
document.getElementById("msg").innerHTML = "";
if(tag.id == "lb_buyer"){
document.getElementById("lb_seller").style = "reset";
document.getElementById("lb_admin").style = "border-top-right-radius: 5px; border-bottom-right-radius: 5px;";
tag.style="border-top-left-radius: 5px; border-bottom-left-radius: 5px; background-color: rgba(69, 67, 67, 0.6); color: white;";
}
if(tag.id == "lb_seller"){
document.getElementById("lb_buyer").style = "border-top-left-radius: 5px; border-bottom-left-radius: 5px;";
document.getElementById("lb_admin").style = "border-top-right-radius: 5px; border-bottom-right-radius: 5px;";
tag.style="background-color: rgba(69, 67, 67, 0.6); color: white;";
}
if(tag.id == "lb_admin"){
document.getElementById("lb_buyer").style = "border-top-left-radius: 5px; border-bottom-left-radius: 5px;";
document.getElementById("lb_seller").style = "reset";
tag.style="border-top-right-radius: 5px; border-bottom-right-radius: 5px; background-color: rgba(69, 67, 67, 0.6); color: white;";
}
}
//alert if user choose nothing
function radio_alert(){
document.getElementById("lb_buyer").style = "border-top-left-radius: 5px; border-bottom-left-radius: 5px; background-color: pink;";
document.getElementById("lb_seller").style = "background-color: pink;";
document.getElementById("lb_admin").style = "border-top-right-radius: 5px; border-bottom-right-radius: 5px; background-color: pink;";
document.getElementById("msg").innerHTML = "Please choose a user type!";
}
</script>
</body>
</html>

63
login/login.php Normal file
View File

@@ -0,0 +1,63 @@
<?php
include "../indexes/ConnectDB.php";
// Start the session
session_start();
//get posted messages
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$user = $_POST["user"];
$pwd = $_POST["pwd"];
$user_type = $_POST["user_type"];
//select from db
$sql = "SELECT * FROM $user_type WHERE name = '$user' AND pwd = '$pwd' ";
// get the result from the query
$result = mysqli_query($conn, $sql);
// if the query returns some record, that means username and password are in the DB.
if(mysqli_num_rows($result)>0){
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $user;
$_SESSION['user_type'] = $user_type;
//redirect to interface
echo "<script type='text/javascript'>
window.location.href = './interfaces/login_success.php';
</script>";
}
else{
echo "<script type='text/javascript'>
window.location.href = './interfaces/login_failed.php';
</script>";
}
}
// Check if the user is already logged in
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
//check usertype and redirct to user page
if(isset($_SESSION['user_type']) && $_SESSION['user_type'] === 'buyer'){
echo "<script type='text/javascript'>
window.location.href = './interfaces/login_buyer.php';
</script>";
}
if(isset($_SESSION['user_type']) && $_SESSION['user_type'] === 'seller'){
echo "<script type='text/javascript'>
window.location.href = './interfaces/login_seller.php';
</script>";
}
if(isset($_SESSION['user_type']) && $_SESSION['user_type'] === 'admin'){
echo "<script type='text/javascript'>
window.location.href = './interfaces/login_admin.php';
</script>";
}
}
else {
echo "<script type='text/javascript'>
window.top.location.href = './login.html';
</script>";
}
?>

19
login/logout.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
// Start the session
session_start();
// Unset all of the session variables
$_SESSION = array();
// Destroy the session
session_destroy();
// Redirect the user to the login page
echo "<script type='text/javascript'>
window.top.location.href = '../index.html';
</script>";
exit;
?>

49
login/register.html Normal file
View File

@@ -0,0 +1,49 @@
<html>
<head>
<title>Register</title>
<link rel="stylesheet" href="./login.css" type="text/css" />
</head>
<body>
<div id="area" style="text-align: center;">
<h1>Register</h1>
<!--input area-->
<form action = "./RegisterByDB.php" method="POST">
<input type="text" name="user" placeholder="Username" required>
<br><br>
<input type="password" name="pwd" placeholder="Password" required>
<br><br>
<label for="buyer" id="lb_buyer" onmousedown="implement(this)"
style="border-top-left-radius: 5px; border-bottom-left-radius: 5px;">Buyer</label>
<input type="radio" value="buyer" name="user_type" id="buyer" hidden required/>
<label for="seller" id="lb_seller" onmousedown="implement(this)"
style="border-top-right-radius: 5px; border-bottom-right-radius: 5px;">Seller</label>
<input type="radio" value="seller" name="user_type" id="seller" oninvalid="radio_alert()" hidden required/>
<p id="msg" style="color: red; font-size: small; padding: none; margin: none;"></p>
<button type="submit">Sign up</button>
</form>
<p style="font-size: small;">Already have an account? <a href="login.html" style="text-decoration: none;">Sign in</a></p>
</div>
<script>
//beautify label
function implement(tag){
document.getElementById("msg").innerHTML = "";
if(tag.id == "lb_buyer"){
document.getElementById("lb_seller").style = "border-top-right-radius: 5px; border-bottom-right-radius: 5px;";
tag.style="border-top-left-radius: 5px; border-bottom-left-radius: 5px; background-color: rgba(69, 67, 67, 0.6); color: white;";
}
if(tag.id == "lb_seller"){
document.getElementById("lb_buyer").style = "border-top-left-radius: 5px; border-bottom-left-radius: 5px;";
tag.style="border-top-right-radius: 5px; border-bottom-right-radius: 5px; background-color: rgba(69, 67, 67, 0.6); color: white;";
}
}
//alert if user choose nothing
function radio_alert(){
document.getElementById("lb_buyer").style = "border-top-left-radius: 5px; border-bottom-left-radius: 5px; background-color: pink;";
document.getElementById("lb_seller").style = "border-top-right-radius: 5px; border-bottom-right-radius: 5px; background-color: pink;";
document.getElementById("msg").innerHTML = "Please choose a user type!";
}
</script>
</body>
</html>