Compare commits

..

No commits in common. "556ef5ee5ff459217e8e7035e11f8aaea295f5ed" and "f6c454099e42d97edd8964e811a42b95af1babf6" have entirely different histories.

5 changed files with 343 additions and 323 deletions

View File

@ -1,220 +1,274 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="id"> <html lang="id">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Login & Register - Memory Game</title> <title>Login</title>
<style> <style>
/* --- 1. RESET & BACKGROUND UTAMA --- */
* { box-sizing: border-box; }
body { body {
margin: 0; margin: 0;
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
background: linear-gradient(135deg, #d9a7ff, #fbc2eb, #a1c4fd); background: linear-gradient(135deg, #d9a7ff, #fbc2eb, #a1c4fd);
min-height: 100vh; min-height: 100vh;
display: flex; overflow-y: auto;
justify-content: center; overflow-x: hidden;
align-items: center; display: flex;
overflow-x: hidden; justify-content: center;
align-items: center;
} }
/* --- 2. CONTAINER KARTU (LOGIC SLIDING) --- */ .container, .login-card {
.auth-card { background: rgba(255,255,255,0.7);
width: 380px; backdrop-filter: blur(10px);
background: rgba(255, 255, 255, 0.75); padding: 40px;
backdrop-filter: blur(12px); border-radius: 25px;
border-radius: 25px; width: 350px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2); z-index: 10;
overflow: hidden; /* Sembunyikan form yang ada di luar area */ box-shadow: 0 10px 28px rgba(0,0,0,0.2);
position: relative; position: relative;
z-index: 10;
transition: height 0.4s cubic-bezier(0.25, 1, 0.5, 1), transform 0.4s ease;
} }
.auth-card:hover { .icon-wrapper {
transform: scale(1.01); display: flex;
justify-content: center;
margin-bottom: 20px;
position: relative;
} }
.form-wrapper { .icon-bg {
width: 100%; width: 90px; height: 90px;
overflow: hidden; background: linear-gradient(45deg, purple, hotpink);
border-radius: 50%;
filter: blur(12px);
position: absolute;
animation: glow 3s infinite alternate;
} }
/* Container Form (Lebar 200% untuk 2 form) */ .icon {
.forms-container { width: 70px; height: 70px;
display: flex; border-radius: 50%;
width: 200%; background: linear-gradient(45deg, purple, hotpink);
transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55); display: flex;
justify-content: center;
align-items: center;
} }
/* Geser ke kanan (Register) saat active */ .title {
.auth-card.active .forms-container { text-align: center;
transform: translateX(-50%); font-size: 22px;
} margin-bottom: 10px;
background: linear-gradient(45deg, purple, hotpink);
/* --- 3. STYLING FORM INDIVIDUAL --- */ -webkit-background-clip: text;
form { background-clip: text;
width: 50%; color: transparent;
flex-shrink: 0;
padding: 40px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center; /* Center content vertically if height allows */
}
/* Typography */
h2 {
margin: 10px 0 10px; /* Adjusted margin since icon is gone */
text-align: center;
font-size: 26px;
background: linear-gradient(45deg, purple, hotpink);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
} }
.subtitle { .subtitle {
text-align: center; text-align: center;
color: gray; color: gray;
font-size: 14px; margin-bottom: 20px;
margin-bottom: 25px; animation:appear 3s ease-out;
} }
label { label {
font-size: 14px; font-size: 14px;
color: #444; color: #444;
width: 100%;
margin-bottom: 6px;
font-weight: bold;
} }
input { input {
width: 100%; width: 100%;
padding: 12px; padding: 12px;
border-radius: 12px; border-radius: 12px;
border: 2px solid #ccc; border: 2px solid #ccc;
background: #fafafa; background: #fafafa;
margin-bottom: 15px; margin-bottom: 15px;
font-size: 14px;
transition: 0.3s;
} }
input:focus { input:focus {
outline: none; outline: none;
border-color: purple; border-color: purple;
background: #fff;
box-shadow: 0 0 8px rgba(128, 0, 128, 0.1);
} }
/* Tombol */ #errorBox {
.btn-submit { color: red;
width: 100%; background: #ffe5e5;
padding: 14px; padding: 10px;
background: linear-gradient(45deg, purple, hotpink); border-radius: 10px;
color: white; margin-bottom: 10px;
border-radius: 15px; display: none;
border: none;
cursor: pointer;
font-size: 16px;
font-weight: bold;
transition: 0.25s ease;
margin-top: 10px;
box-shadow: 0 4px 15px rgba(128, 0, 128, 0.2);
} }
.btn-submit:hover { .btn {
transform: scale(1.02); width: 100%;
box-shadow: 0 6px 20px rgba(128, 0, 128, 0.35); padding: 14px;
background: linear-gradient(45deg, purple, hotpink);
color: white;
border-radius: 15px;
border: none;
cursor: pointer;
font-size: 16px;
transition: 0.2s;
} }
/* Link Switch */ .btn:hover {
.switch-text { transform: scale(1.02);
margin-top: 20px; box-shadow: 0 4px 15px rgba(0,0,0,0.3);
font-size: 14px;
color: #555;
} }
.switch-text a { .btn-login {
color: purple; width: 100%;
text-decoration: none; padding: 14px;
font-weight: bold; background: linear-gradient(45deg, purple, hotpink);
cursor: pointer; color: white;
border-radius: 15px;
border: none;
cursor: pointer;
font-size: 16px;
transition: 0.25s ease;
} }
.switch-text a:hover { .btn-login:hover {
text-decoration: underline; transform: scale(1.03);
box-shadow: 0 4px 15px rgba(0,0,0,0.25);
} }
/* Error Box */ .login-container {
.error-box { max-height: none;
width: 100%; height: auto;
color: #d8000c; overflow: visible;
background: #ffbaba; padding-bottom: 40px;
padding: 10px;
border-radius: 10px;
margin-bottom: 15px;
font-size: 13px;
text-align: center;
display: none;
} }
/* --- 4. DEKORASI (BUAH & GLITTER) --- */ .login-link {
.fruit { text-align: center;
position: absolute; margin-top: 15px;
width: 90px;
opacity: 0.85;
animation: float 6s infinite ease-in-out, drift 15s infinite linear;
pointer-events: none;
z-index: 1;
} }
/* Posisi Buah */ .login-link a {
.f1 { top: 8%; left: 10%; animation-delay: .3s; width: 80px; } color: purple;
.f2 { top: 65%; right: 12%; animation-delay: .7s; } text-decoration: underline;
.f3 { top: 22%; right: 55%; animation-delay: 1.1s; width: 60px; }
.f4 { bottom: 15%; left: 28%; animation-delay: .9s; }
.f5 { bottom: 10%; right: 30%; animation-delay: 1.4s; width: 70px; }
.f6 { top: 40%; left: 50%; animation-delay: .5s; }
.f7 { bottom: 30%; left: 15%; animation-delay: 1.2s; width: 50px; }
.f8 { top: 75%; right: 40%; animation-delay: .8s; }
.f9 { top: 50%; left: 80%; animation-delay: 1s; width: 85px; }
.f10 { bottom: 20%; right: 5%; animation-delay: 1.3s; }
@keyframes float {
0% { transform: translateY(0) rotate(0deg); }
50% { transform: translateY(-20px) rotate(6deg); }
100% { transform: translateY(0) rotate(0deg); }
}
@keyframes drift {
0% { transform: translateX(0); }
50% { transform: translateX(15px); }
100% { transform: translateX(0); }
} }
.glitter { .glitter {
position: absolute; position: absolute;
width: 4px; width: 4px;
height: 4px; height: 4px;
background: purple; background: purple;
border-radius: 50%; border-radius: 50%;
opacity: 0; opacity: 0;
animation: glitter-burst 2s infinite ease-out; animation: glitter-burst 2s infinite ease-out;
pointer-events: none; pointer-events: none;
z-index: 11; }
.demo-toggle {
margin-top: 10px;
width: 100%;
padding: 10px;
border: none;
border-radius: 12px;
background: rgba(255,255,255,0.6);
cursor: pointer;
font-size: 15px;
transition: 0.3s;
}
.demo-section {
margin-top: 20px;
padding-bottom: 20px;
overflow: visible;
}
.demo-toggle:hover {
background: rgba(255,255,255,0.85);
}
.demo-box {
overflow: hidden;
max-height: 0;
opacity: 0;
transition: max-height 0.5s ease, opacity 0.4s ease;
background: rgba(255, 255, 255, 0.6);
padding: 15px;
border-radius: 12px;
line-height: 1.6;
}
.demo-box.show {
max-height: 1000px;
opacity: 1;
}
.hidden {
display: none !important;
} }
@keyframes glitter-burst { @keyframes glitter-burst {
0% { transform: scale(0.4); opacity: 0.9; } 0% {
50% { opacity: 1; } transform: scale(0.4) translate(0,0);
100% { transform: scale(1) translate(var(--x), var(--y)); opacity: 0; } opacity: 0.9;
}
50% {
opacity: 1;
}
100% {
transform: scale(1) translate(var(--x), var(--y));
opacity: 0;
}
} }
</style> @keyframes glow {
0% { opacity: 0.2; }
100% { opacity: 0.55; }
}
.fruit {
position: absolute;
width: 95px;
opacity: .85;
animation: float 6s infinite ease-in-out, drift 15s infinite linear;
pointer-events: none;
}
.f1 { top: 8%; left: 10%; animation-delay: .3s; }
.f2 { top: 65%; right: 12%; animation-delay: .7s; }
.f3 { top: 22%; right: 55%; animation-delay: 1.1s; }
.f4 { bottom: 15%; left: 28%; animation-delay: .9s; }
.f5 { bottom: 10%; right: 30%; animation-delay: 1.4s; }
.f6 { top: 40%; left: 50%; animation-delay: .5s; }
.f7 { bottom: 30%; left: 15%; animation-delay: 1.2s; }
.f8 { top: 75%; right: 40%; animation-delay: .8s; }
.f9 { top: 50%; left: 80%; animation-delay: 1s; }
.f10 { bottom: 20%; right: 5%; animation-delay: 1.3s; }
@keyframes float {
0% { transform: translateY(0) rotate(0deg); }
50% { transform: translateY(-20px) rotate(6deg); }
100% { transform: translateY(0) rotate(0deg); }
}
@keyframes drift {
0% { transform: translateX(0); }
50% { transform: translateX(15px); }
100% { transform: translateX(0); }
}
.login-card, .container {
transition: transform .4s ease;
}
.login-card:hover, .container:hover {
transform: scale(1.012);
}
</style>
</head> </head>
<body> <body>
<div class="bg-animated">
<div class="bg-circle one"></div>
<div class="bg-circle two"></div>
<div class="bg-circle three"></div>
</div>
<img src="images/fruit1.png" class="fruit f1"> <img src="images/fruit1.png" class="fruit f1">
<img src="images/fruit2.png" class="fruit f2"> <img src="images/fruit2.png" class="fruit f2">
@ -227,160 +281,121 @@ input:focus {
<img src="images/fruit9.png" class="fruit f9"> <img src="images/fruit9.png" class="fruit f9">
<img src="images/fruit10.png" class="fruit f10"> <img src="images/fruit10.png" class="fruit f10">
<div class="auth-card" id="authCard"> <div class="login-card">
<div class="form-wrapper"> <div class="icon-wrapper">
<div class="forms-container"> <div class="icon-circle">
<form id="loginForm" action="login.php" method="POST">
<h2>Selamat Datang! ✨</h2>
<p class="subtitle">Login untuk bermain Memory Flip</p>
<div id="loginError" class="error-box"></div>
<label>Username</label>
<input type="text" id="loginUser" name="username" placeholder="Masukan Username" required>
<label>Password</label>
<input type="password" id="loginPass" name="password" placeholder="Masukan Password" required>
<button type="submit" class="btn-submit" name="btn-login">Login Sekarang</button>
<p class="switch-text">
Belum punya akun?
<a onclick="toggleAuth('register')">Daftar Sekarang</a>
</p>
</form>
<form id="registerForm" action="register.php" method="POST">
<h2>Buat Akun Baru ✨</h2>
<p class="subtitle">Daftar untuk memulai petualangan</p>
<div id="regError" class="error-box"></div>
<label>Username</label>
<input type="text" id="regUser" name="username" placeholder="Pilih Username" required>
<label>Email</label>
<input type="email" id="regEmail" name="email" placeholder="Masukan Email" required>
<label>Password</label>
<input type="password" id="regPass" name="password" placeholder="Minimal 6 karakter" required>
<label>Konfirmasi Password</label>
<input type="password" id="regConfirm" name="confirm_password" placeholder="Ketik ulang password" required>
<button type="submit" class="btn-submit" name="btn-register">Daftar Sekarang</button>
<p class="switch-text">
Sudah punya akun?
<a onclick="toggleAuth('login')">Login Sekarang</a>
</p>
</form>
</div>
</div> </div>
</div> </div>
<div class="header-text">
<h2>Selamat Datang! ✨</h2>
<p>Login untuk bermain Memory Flip Card Game</p>
</div>
<form id="loginForm" action="login.php" method="POST">
<label>E-mail</label>
<input type="text" name="username" required id="username" placeholder="Masukan Username">
<label>Password</label>
<input type="password" name="password" required id="password" placeholder="Masukan Password">
<div id="errorBox" class="error"></div>
<button class="btn-login">Login Sekarang</button>
</form>
<p class="register-text">
Belum punya akun?
<a href="register.html">Daftar Sekarang</a>
</p>
<script> <script>
/* --- LOGIC SLIDING & HEIGHT ADJUSTMENT --- */ /* LOGIN VALIDATION */
const card = document.getElementById("authCard"); document.getElementById("loginForm").addEventListener("submit", function(e) {
const loginForm = document.getElementById("loginForm"); e.preventDefault(); // jangan reload halaman
const registerForm = document.getElementById("registerForm");
function setHeight() { const username = document.getElementById("username").value.trim();
const isActive = card.classList.contains("active"); const password = document.getElementById("password").value.trim();
const formHeight = isActive ? registerForm.offsetHeight : loginForm.offsetHeight; const errorBox = document.getElementById("errorBox");
card.style.height = formHeight + "px";
errorBox.style.display = "none";
errorBox.innerText = "";
// Validasi form ringan
if (!username || !password) {
showError("Username dan password harus diisi");
return;
} }
function toggleAuth(mode) { if (password.length < 6) {
// Sembunyikan pesan error saat pindah showError("Password minimal 6 karakter");
document.getElementById("loginError").style.display = "none"; return;
document.getElementById("regError").style.display = "none";
if (mode === 'register') {
card.classList.add("active");
} else {
card.classList.remove("active");
}
setTimeout(setHeight, 50);
} }
window.addEventListener("load", setHeight); // Ambil data user dari localStorage
window.addEventListener("resize", setHeight); const usersData = localStorage.getItem("users");
const users = usersData ? JSON.parse(usersData) : [];
// Cari user berdasarkan username
const user = users.find(u => u.username === username);
/* --- LOGIC LOGIN --- */ // Jika user tidak ada atau password salah
loginForm.addEventListener("submit", function(e) { if (!user || user.password !== password) {
e.preventDefault(); showError("Username atau password salah");
const username = document.getElementById("loginUser").value.trim(); return;
const password = document.getElementById("loginPass").value.trim();
const errorBox = document.getElementById("loginError");
errorBox.style.display = "none";
if (!username || !password) return showMsg(errorBox, "Isi semua data!");
const usersData = localStorage.getItem("users");
const users = usersData ? JSON.parse(usersData) : [];
const user = users.find(u => u.username === username);
if (!user || user.password !== password) {
return showMsg(errorBox, "Username atau password salah");
}
localStorage.setItem("loggedInUser", JSON.stringify(user));
window.location.href = "mainboard.html";
});
/* --- LOGIC REGISTER --- */
registerForm.addEventListener("submit", function(e) {
e.preventDefault();
const username = document.getElementById("regUser").value.trim();
const email = document.getElementById("regEmail").value.trim();
const password = document.getElementById("regPass").value.trim();
const confirm = document.getElementById("regConfirm").value.trim();
const errorBox = document.getElementById("regError");
errorBox.style.display = "none";
if (!username || !email || !password || !confirm) return showMsg(errorBox, "Semua kolom wajib diisi!");
if (password.length < 6) return showMsg(errorBox, "Password minimal 6 karakter!");
if (password !== confirm) return showMsg(errorBox, "Password tidak cocok!");
// Simpan data (Simulasi)
const users = JSON.parse(localStorage.getItem("users") || "[]");
users.push({ username, password, email });
localStorage.setItem("users", JSON.stringify(users));
alert("Registrasi Berhasil! Silakan Login.");
toggleAuth('login');
});
function showMsg(element, msg) {
element.innerText = msg;
element.style.display = "block";
setHeight();
} }
// Login sukses
localStorage.setItem("loggedInUser", JSON.stringify(user));
window.location.href = "mainboard.html";
});
/* --- GLITTER EFFECT --- */ function showError(msg) {
document.addEventListener("DOMContentLoaded", function () { const errorBox = document.getElementById("errorBox");
const card = document.querySelector(".auth-card"); errorBox.innerText = msg;
for (let i = 0; i < 15; i++) { errorBox.style.display = "block";
const g = document.createElement("div"); }
g.className = "glitter";
g.style.setProperty("--x", (Math.random() * 200 - 100) + "px"); /* Toggle Demo */
g.style.setProperty("--y", (Math.random() * 200 - 100) + "px"); function toggleDemo() {
g.style.left = (Math.random() * 100) + "%"; const box = document.getElementById("demoBox");
g.style.top = (Math.random() * 100) + "%"; const btn = document.querySelector(".demo-toggle");
g.style.animationDelay = (Math.random() * 2) + "s";
card.appendChild(g); box.classList.toggle("show");
}
if (box.classList.contains("show")) {
btn.textContent = "Sembunyikan Demo Akun ▲";
} else {
btn.textContent = "Lihat Demo Akun ▼";
}
}
/* GLITTER EFFECT */
document.addEventListener("DOMContentLoaded", function () {
const card = document.querySelector(".login-card");
if (!card) return;
for (let i = 0; i < 20; i++) {
const g = document.createElement("div");
g.className = "glitter";
g.style.setProperty("--x", (Math.random() * 200 - 100) + "px");
g.style.setProperty("--y", (Math.random() * 200 - 100) + "px");
g.style.left = (Math.random() * 100) + "%";
g.style.top = (Math.random() * 100) + "%";
g.style.animationDelay = (Math.random() * 2) + "s";
card.appendChild(g);
}
});
setInterval(() => {
document.querySelectorAll(".glitter").forEach(g => {
g.style.setProperty("--x", (Math.random() * 200 - 100) + "px");
g.style.setProperty("--y", (Math.random() * 200 - 100) + "px");
g.style.left = Math.random() * window.innerWidth + "px";
g.style.top = Math.random() * window.innerHeight + "px";
}); });
}, 900);
</script> </script>
</body> </body>
</html> </html>

View File

@ -1,9 +1,9 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="id"> <html lang="id">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Login</title> <title>Login</title>
<style> <style>
body { body {
@ -260,7 +260,7 @@ input:focus {
transform: scale(1.012); transform: scale(1.012);
} }
</style> </style>
</head> </head>
<body> <body>
@ -303,7 +303,7 @@ input:focus {
<div id="errorBox" class="error"></div> <div id="errorBox" class="error"></div>
<button type="submit" class="btn-login" name="btn-login">Login Sekarang</button> <button class="btn-login">Login Sekarang</button>
</form> </form>
<p class="register-text"> <p class="register-text">

View File

@ -2,11 +2,15 @@
session_start(); session_start();
require_once "Config.php"; require_once "Config.php";
if(isset($_POST['btn-login'])){ if (!isset($_POST['username']) || !isset($_POST['password'])) {
$username = $_POST['username']; echo "Username atau password salah";
$password = $_POST['password']; exit;
}
// Ambil user berdasarkan username $username = $_POST['username'];
$password = $_POST['password'];
// Ambil user berdasarkan username
$stmt = mysqli_prepare($conn, "SELECT * FROM user WHERE username=?"); $stmt = mysqli_prepare($conn, "SELECT * FROM user WHERE username=?");
mysqli_stmt_bind_param($stmt, "s", $username); mysqli_stmt_bind_param($stmt, "s", $username);
mysqli_stmt_execute($stmt); mysqli_stmt_execute($stmt);
@ -24,7 +28,4 @@ if (!$row || !password_verify($password, $row['password'])) {
$_SESSION['username'] = $row['username']; $_SESSION['username'] = $row['username'];
echo "<script>alert('Silakan login.'); window.location.href='mainboard.html';</script>"; echo "<script>alert('Silakan login.'); window.location.href='mainboard.html';</script>";
exit; exit;
}
?> ?>

View File

@ -149,7 +149,7 @@ input:focus {
} }
/* Button */ /* Button */
.btn-register { .btn {
width: 100%; width: 100%;
background: linear-gradient(45deg, purple, hotpink); background: linear-gradient(45deg, purple, hotpink);
color: white; color: white;
@ -245,7 +245,7 @@ input:focus {
<div id="errorBox"></div> <div id="errorBox"></div>
<button type="submit" class="btn-register" name="btn-register">Daftar Sekarang</button> <button type="submit" class="btn">Daftar Sekarang</button>
</form> </form>
<p class="login-link"> <p class="login-link">

View File

@ -2,11 +2,11 @@
session_start(); session_start();
require_once "Config.php"; require_once "Config.php";
if(isset($_POST['btn-register'])) { if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username']; $username = trim($_POST['username']);
$email = $_POST['email']; $email = trim($_POST['email']);
$password = $_POST['password']; $password = trim($_POST['password']);
$confirmPassword = password_hash($_POST['confirm_password'],PASSWORD_DEFAULT); $confirmPassword = trim($_POST['confirm_password']);
if (!$username || !$email || !$password || !$confirmPassword) { if (!$username || !$email || !$password || !$confirmPassword) {
echo "<script>alert('Semua field harus diisi'); window.history.back();</script>"; echo "<script>alert('Semua field harus diisi'); window.history.back();</script>";
@ -28,7 +28,7 @@ if(isset($_POST['btn-register'])) {
exit; exit;
} }
// cek username & email di database
$stmt = mysqli_prepare($conn, "SELECT id FROM user WHERE username=? OR email=?"); $stmt = mysqli_prepare($conn, "SELECT id FROM user WHERE username=? OR email=?");
mysqli_stmt_bind_param($stmt, "ss", $username, $email); mysqli_stmt_bind_param($stmt, "ss", $username, $email);
mysqli_stmt_execute($stmt); mysqli_stmt_execute($stmt);
@ -39,6 +39,10 @@ if(isset($_POST['btn-register'])) {
exit; exit;
} }
// hash password
$hash = password_hash($password, PASSWORD_DEFAULT);
// insert user
$stmt = mysqli_prepare($conn, "INSERT INTO user (username, email, password, role) VALUES (?, ?, ?, 'player')"); $stmt = mysqli_prepare($conn, "INSERT INTO user (username, email, password, role) VALUES (?, ?, ?, 'player')");
mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hash); mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hash);
mysqli_stmt_execute($stmt); mysqli_stmt_execute($stmt);