Merge branch 'main' of https://github.com/ioannis20x/alphacar-dashboard into main
This commit is contained in:
BIN
alphacar-bg.png
Normal file
BIN
alphacar-bg.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 MiB |
BIN
alphacar-bg.png.bak
Normal file
BIN
alphacar-bg.png.bak
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
103
callback.php
Normal file
103
callback.php
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
$config = require 'config.php';
|
||||||
|
|
||||||
|
if (!isset($_GET['code'])) {
|
||||||
|
die('Keine Autorisierungscode empfangen');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Token holen
|
||||||
|
$ch = curl_init('https://discord.com/api/oauth2/token');
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
|
||||||
|
'client_id' => $config['client_id'],
|
||||||
|
'client_secret' => $config['client_secret'],
|
||||||
|
'grant_type' => 'authorization_code',
|
||||||
|
'code' => $_GET['code'],
|
||||||
|
'redirect_uri' => $config['redirect_uri'],
|
||||||
|
'scope' => 'identify guilds.members.read'
|
||||||
|
]));
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
$data = json_decode($response, true);
|
||||||
|
|
||||||
|
if (!isset($data['access_token'])) {
|
||||||
|
die('Fehler beim Token-Austausch');
|
||||||
|
}
|
||||||
|
|
||||||
|
$access_token = $data['access_token'];
|
||||||
|
|
||||||
|
// API Request Funktion
|
||||||
|
function apiRequest($url, $token) {
|
||||||
|
$ch = curl_init($url);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
"Authorization: Bearer $token"
|
||||||
|
]);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
return json_decode($response, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// User-Daten holen
|
||||||
|
$user = apiRequest('https://discord.com/api/users/@me', $access_token);
|
||||||
|
|
||||||
|
// Mitgliedschaft prüfen
|
||||||
|
$guild_member = apiRequest("https://discord.com/api/users/@me/guilds/{$config['guild_id']}/member", $access_token);
|
||||||
|
|
||||||
|
if (isset($guild_member['message'])) {
|
||||||
|
die('Du bist nicht auf dem Discord-Server.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🆕 Rollen-ID → Rollenname Mapping
|
||||||
|
$role_names = [
|
||||||
|
"1350944151381999666" => "Geschäftsführung",
|
||||||
|
"1350944244843544709" => "Stv. Geschäftsführung",
|
||||||
|
"1350943536891297914" => "Leitungsebene",
|
||||||
|
"1350945302395224206" => "Werkstattleiter",
|
||||||
|
"1350945473338544138" => "Ausbilder",
|
||||||
|
"1350945530519224320" => "Meister",
|
||||||
|
"1350945581194809376" => "Tuner",
|
||||||
|
"1350945688560861285" => "Stift"
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
// 🆕 Rollen-Rang (höchste zuerst)
|
||||||
|
$role_order = [
|
||||||
|
"1350944151381999666",
|
||||||
|
"1350944244843544709",
|
||||||
|
"1350943536891297914",
|
||||||
|
"1350945302395224206",
|
||||||
|
"1350945473338544138",
|
||||||
|
"1350945530519224320",
|
||||||
|
"1350945581194809376",
|
||||||
|
"1350945688560861285"
|
||||||
|
];
|
||||||
|
|
||||||
|
// 🆕 Höchste Rolle finden
|
||||||
|
$main_role_name = "Mitglied"; // Fallback
|
||||||
|
foreach ($role_order as $role_id) {
|
||||||
|
if (in_array($role_id, $guild_member['roles'])) {
|
||||||
|
$main_role_name = $role_names[$role_id];
|
||||||
|
break; // erste gefundene Rolle nehmen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rollen prüfen (ob die Person die „Adminrolle“ hat)
|
||||||
|
$hasRole = in_array($config['role_id'], $guild_member['roles']);
|
||||||
|
|
||||||
|
// Session setzen
|
||||||
|
$_SESSION['user'] = [
|
||||||
|
'id' => $user['id'],
|
||||||
|
'username' => $user['username'],
|
||||||
|
'discriminator' => $user['discriminator'],
|
||||||
|
'avatar' => $user['avatar'],
|
||||||
|
'hasRole' => $hasRole,
|
||||||
|
'nickname' => $guild_member['nick'] ?? $user['username'], // Nick wenn vorhanden
|
||||||
|
'main_role' => $main_role_name // 🆕 höchster Rollenname
|
||||||
|
];
|
||||||
|
|
||||||
|
header('Location: index.php');
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
14
config.php
14
config.php
@@ -1,7 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
include "db.php"
|
return [
|
||||||
|
'client_id' => '1391359380879835146',
|
||||||
$env = parse_ini_file(".env");
|
'client_secret' => 'KUlkgzqI-JcLenAmxmFGwV_UroPWW6ZV',
|
||||||
print($env["SITENAME"])
|
'redirect_uri' => 'http://localhost/alphacar/callback.php',
|
||||||
;
|
'guild_id' => '1350913088827691129',
|
||||||
|
'role_id' => '1350945581194809376'
|
||||||
|
];
|
||||||
|
?>
|
||||||
|
|||||||
17
header.php
17
header.php
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
?>
|
||||||
|
|
||||||
|
<nav>
|
||||||
|
<a href="index.php">Startseite</a>
|
||||||
|
|
||||||
|
<?php if (isset($_SESSION['user']) && $_SESSION['user']['hasRole']): ?>
|
||||||
|
<a href="admin.php">Admin-Menü</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (isset($_SESSION['user'])): ?>
|
||||||
|
<a href="logout.php">Logout</a>
|
||||||
|
<?php else: ?>
|
||||||
|
<a href="loginform.php">Login</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</nav>
|
||||||
|
|||||||
54
index.php
54
index.php
@@ -1,24 +1,56 @@
|
|||||||
<?php
|
<?php
|
||||||
include "config.php"
|
|
||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
if($_SESSION["loggedin"]){
|
if (!isset($_SESSION['user'])) {
|
||||||
include "header.php"
|
header('Location: loginform.php');
|
||||||
}
|
exit;
|
||||||
else{
|
|
||||||
include "loginform.php"
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<title>Willkommen</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<link rel="stylesheet" href="style.css">
|
||||||
<title><?php$SITENAME?></title>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div class="navbar">
|
||||||
|
<div class="navbar-links" id="mobileMenu">
|
||||||
|
<a href="index.php">🏠 Home</a>
|
||||||
|
<?php if ($_SESSION['user']['hasRole']): ?>
|
||||||
|
<a href="admin.php">✍️ Eintragung</a>
|
||||||
|
<div class="dropdown">
|
||||||
|
<a href="#">📂 Verwaltung ▼</a>
|
||||||
|
<div class="dropdown-content">
|
||||||
|
<a href="statistik.php">📊 Statistik</a>
|
||||||
|
<a href="lager.php">🔧 Lager</a>
|
||||||
|
<a href="#">📝 Platzhalter</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<div class="user-info">
|
||||||
|
<img src="https://cdn.discordapp.com/avatars/<?php echo $_SESSION['user']['id']; ?>/<?php echo $_SESSION['user']['avatar']; ?>.png" alt="Avatar">
|
||||||
|
<span><?php echo htmlspecialchars($_SESSION['user']['nickname']); ?></span>
|
||||||
|
<a href="logout.php"><button class="logout-btn">Logout</button></a>
|
||||||
|
<span class="burger" onclick="toggleMenu()">☰</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="padding: 20px;">
|
||||||
|
<h1>Willkommen, <?php echo htmlspecialchars($_SESSION['user']['nickname']); ?>!</h1>
|
||||||
|
|
||||||
|
<?php if ($_SESSION['user']['hasRole']): ?>
|
||||||
|
<p>Du bist als <strong><?php echo htmlspecialchars($_SESSION['user']['main_role']); ?></strong> eingeloggt.</p>
|
||||||
|
<?php else: ?>
|
||||||
|
<p>Du hast nicht die erforderliche Rolle für Admin-Menüpunkte.</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function toggleMenu() {
|
||||||
|
document.getElementById("mobileMenu").classList.toggle("show");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
// Start session
|
||||||
|
session_start();
|
||||||
|
?>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="style.css">
|
||||||
|
</head>
|
||||||
|
<div id="loginform">
|
||||||
|
<a class="discord-button" href="https://discord.com/api/oauth2/authorize?client_id=1391359380879835146&redirect_uri=http%3A%2F%2Flocalhost%2Falphacar%2Fcallback.php&response_type=code&scope=identify%20guilds.members.read">
|
||||||
|
<img src="https://cdn-icons-png.flaticon.com/512/2111/2111370.png" alt="Discord Logo">
|
||||||
|
Login mit Discord
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
6
logout.php
Normal file
6
logout.php
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
session_destroy();
|
||||||
|
header('Location: loginform.php');
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
148
style.css
Normal file
148
style.css
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
html, body {
|
||||||
|
height: 100%; /* Höhe auf 100% setzen */
|
||||||
|
margin: 0;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
background: url("alphacar-bg.png") no-repeat center center fixed;
|
||||||
|
background-size: cover;
|
||||||
|
background-attachment: fixed;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
body::before {
|
||||||
|
content: "";
|
||||||
|
position: fixed;
|
||||||
|
top: 0; left: 0; right: 0; bottom: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.6); /* Abdunkelung */
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
min-height: calc(100vh - 60px); /* Füllt den ganzen Bildschirm bis auf die Navbar */
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Navbar */
|
||||||
|
.navbar {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
background-color: rgba(31,31,31,0.9);
|
||||||
|
padding: 10px 20px;
|
||||||
|
}
|
||||||
|
.navbar a {
|
||||||
|
color: #fff;
|
||||||
|
text-decoration: none;
|
||||||
|
margin: 0 10px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dropdown */
|
||||||
|
.dropdown {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
.dropdown-content {
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
background-color: rgba(50, 50, 50, 0.95);
|
||||||
|
min-width: 160px;
|
||||||
|
box-shadow: 0px 8px 16px rgba(0,0,0,0.2);
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
.dropdown-content a {
|
||||||
|
color: #fff;
|
||||||
|
padding: 12px 16px;
|
||||||
|
text-decoration: none;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.dropdown-content a:hover {
|
||||||
|
background-color: #5865F2;
|
||||||
|
}
|
||||||
|
.dropdown:hover .dropdown-content {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-info {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.user-info img {
|
||||||
|
border-radius: 50%;
|
||||||
|
margin-right: 10px;
|
||||||
|
height: 35px;
|
||||||
|
width: 35px;
|
||||||
|
}
|
||||||
|
.logout-btn {
|
||||||
|
background-color: #5865F2;
|
||||||
|
border: none;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 5px;
|
||||||
|
color: #fff;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
.logout-btn:hover {
|
||||||
|
background-color: #4752C4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Burger für Mobile */
|
||||||
|
.navbar .burger {
|
||||||
|
display: none;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1.5em;
|
||||||
|
}
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.navbar-links {
|
||||||
|
display: none;
|
||||||
|
flex-direction: column;
|
||||||
|
background-color: rgba(31,31,31,0.95);
|
||||||
|
position: absolute;
|
||||||
|
top: 60px;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.navbar-links.show {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
.navbar .burger {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.dropdown-content {
|
||||||
|
position: static;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*LOGIN FORM*/
|
||||||
|
#loginform{
|
||||||
|
position: fixed;
|
||||||
|
inset: 0px;
|
||||||
|
width: 12rem;
|
||||||
|
height: 5rem;
|
||||||
|
max-width: 100vw;
|
||||||
|
max-height: 100dvh;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.discord-button{
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
background-color: #5865F2; /* Discord Blau */
|
||||||
|
color: #fff;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 1.2em;
|
||||||
|
padding: 12px 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
text-decoration: none;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.discord-button:hover {
|
||||||
|
background-color: #4752C4; /* dunkleres Blau beim Hover */
|
||||||
|
}
|
||||||
|
|
||||||
|
.discord-button img {
|
||||||
|
height: 24px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user