/home/awneajlw/.trash/signin.php
<?php
/**
* Sign In Page - User Authentication
* This page handles user login with email and password
* Features: Form validation, database authentication, session management
* Redirects to home page on successful login
*/
// Start session if not already started
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
// Include required files
require_once 'config/database.php'; // Database connection configuration
require_once 'includes/auth.php'; // Authentication functions
/**
* Login Form Submission Handler
* Process POST request when login form is submitted
* Validates user credentials and creates session
*/
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['email']) && isset($_POST['password'])) {
$email = trim($_POST['email']);
$password = $_POST['password'];
if (!empty($email) && !empty($password)) {
try {
$database = new Database();
$db = $database->getConnection();
// Allow login with email or username
$query = "SELECT * FROM users WHERE email = ? OR name = ?";
$stmt = $db->prepare($query);
$stmt->execute([$email, $email]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['name'] = $user['name'];
$_SESSION['email'] = $user['email'];
$_SESSION['role'] = $user['role'];
$_SESSION['last_activity'] = time();
// Login successful - redirect to home.php
header('Location: home.php');
exit();
} else {
$login_error = 'Invalid email or password';
}
} catch (Exception $e) {
$login_error = 'Login failed. Please try again.';
}
} else {
$login_error = 'Please fill in all fields';
}
}
// If already logged in, redirect to home
if (isLoggedIn()) {
header('Location: home.php');
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SIGN IN - OPTI SLIP</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', sans-serif;
min-height: 100vh;
background: #f8fafc;
}
.header {
background: #374151;
padding: 15px 30px;
color: white;
font-size: 18px;
font-weight: 600;
text-transform: uppercase;
}
.main-container {
display: flex;
min-height: calc(100vh - 60px);
}
.left-section {
flex: 1;
background: #059669;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 60px 40px;
position: relative;
clip-path: polygon(0 0, 85% 0, 100% 100%, 0% 100%);
}
.logo-container {
text-align: center;
margin-bottom: 40px;
}
.logo-icon {
width: 120px;
height: 120px;
background: transparent;
border: 3px solid white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 20px;
position: relative;
}
.logo-icon::before {
content: '';
position: absolute;
left: 20px;
width: 30px;
height: 30px;
border: 2px solid white;
border-radius: 4px;
background: transparent;
}
.logo-icon::after {
content: '';
position: absolute;
right: 20px;
width: 30px;
height: 30px;
border: 2px solid white;
border-radius: 4px;
background: transparent;
}
.logo-text {
color: white;
font-size: 24px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 2px;
}
.description-text {
color: white;
font-size: 16px;
line-height: 1.6;
text-align: center;
max-width: 400px;
opacity: 0.9;
}
.right-section {
flex: 1;
background: white;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 60px 40px;
position: relative;
clip-path: polygon(15% 0, 100% 0, 100% 100%, 0% 100%);
}
.welcome-text {
font-size: 48px;
font-weight: 700;
color: #1f2937;
margin-bottom: 40px;
text-align: center;
}
.form-container {
width: 100%;
max-width: 400px;
}
.form-group {
margin-bottom: 25px;
}
.form-label {
display: block;
font-size: 14px;
font-weight: 600;
color: #374151;
margin-bottom: 8px;
}
.form-input {
width: 100%;
padding: 15px 20px;
border: 2px solid #d1d5db;
border-radius: 8px;
font-size: 16px;
transition: all 0.3s ease;
background: white;
}
.form-input:focus {
outline: none;
border-color: #059669;
box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
}
.remember-section {
display: flex;
align-items: center;
margin-bottom: 25px;
}
.remember-checkbox {
width: 18px;
height: 18px;
margin-right: 10px;
accent-color: #059669;
}
.remember-label {
font-size: 14px;
color: #6b7280;
}
.signin-btn {
width: 100%;
padding: 15px 20px;
background: #059669;
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
text-transform: uppercase;
cursor: pointer;
transition: all 0.3s ease;
margin-bottom: 25px;
}
.signin-btn:hover {
background: #047857;
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(5, 150, 105, 0.3);
}
.divider {
display: flex;
align-items: center;
margin: 25px 0;
text-align: center;
}
.divider::before,
.divider::after {
content: '';
flex: 1;
height: 1px;
background: #d1d5db;
}
.divider-text {
padding: 0 20px;
color: #6b7280;
font-size: 14px;
font-weight: 500;
}
.social-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
margin-bottom: 25px;
}
.social-btn {
padding: 12px 20px;
border: 1px solid #d1d5db;
border-radius: 8px;
background: white;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
font-weight: 500;
color: #374151;
}
.social-btn:hover {
border-color: #9ca3af;
background: #f9fafb;
}
.google-text {
color: #ea4335;
font-weight: 600;
}
.facebook-text {
color: #1877f2;
font-weight: 600;
}
.signup-link {
text-align: center;
color: #6b7280;
font-size: 14px;
}
.signup-link a {
color: #059669;
text-decoration: none;
font-weight: 600;
}
.signup-link a:hover {
text-decoration: underline;
}
.alert {
padding: 12px 16px;
border-radius: 8px;
margin-bottom: 20px;
text-align: center;
background: #fef2f2;
border: 1px solid #fecaca;
color: #dc2626;
}
@media (max-width: 768px) {
.main-container {
flex-direction: column;
}
.left-section {
clip-path: none;
padding: 40px 20px;
}
.right-section {
clip-path: none;
padding: 40px 20px;
}
.welcome-text {
font-size: 36px;
}
.logo-icon {
width: 80px;
height: 80px;
}
.logo-text {
font-size: 20px;
}
}
@media (max-width: 480px) {
.social-buttons {
grid-template-columns: 1fr;
}
.welcome-text {
font-size: 28px;
}
}
</style>
</head>
<body>
<!-- Header -->
<div class="header">
SIGN in
</div>
<!-- Main Container -->
<div class="main-container">
<!-- Left Section -->
<div class="left-section">
<div class="logo-container">
<div class="logo-icon">
<!-- Glasses icon created with CSS -->
</div>
<div class="logo-text">OPTI SLIP</div>
</div>
<div class="description-text">
Lorem ipsum dolor sit amet consectetur. Hendrerit blandit justo tincidunt turpis vel donec. Nam ullamcorper neque volutpat tellus eget molestie in amet. Sodales eu ac aliquet erat risus. Quisque.
</div>
</div>
<!-- Right Section -->
<div class="right-section">
<div class="welcome-text">welcome !</div>
<div class="form-container">
<?php if (isset($login_error)): ?>
<div class="alert">
<i class="fas fa-exclamation-triangle me-2"></i>
<?php echo htmlspecialchars($login_error); ?>
</div>
<?php endif; ?>
<form method="POST" action="signin.php">
<div class="form-group">
<label class="form-label">Email or Username</label>
<input type="text" name="email" class="form-input" placeholder="Enter your email or username" value="<?php echo isset($_POST['email']) ? htmlspecialchars($_POST['email']) : ''; ?>" required>
</div>
<div class="form-group">
<label class="form-label">Password</label>
<input type="password" name="password" class="form-input" value="********" required>
</div>
<div class="remember-section">
<input type="checkbox" class="remember-checkbox" checked>
<label class="remember-label">Remember me</label>
</div>
<button type="submit" class="signin-btn">
SIGN IN
</button>
</form>
<div class="divider">
<span class="divider-text">OR</span>
</div>
<div class="social-buttons">
<button type="button" class="social-btn google-btn">
Continue with <span class="google-text">Google</span>
</button>
<button type="button" class="social-btn facebook-btn">
Continue with<span class="facebook-text"> Facebook</span>
</button>
</div>
<div class="signup-link">
Don't Have An Account ? <a href="register.php">Sign Up</a>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Social login placeholders
document.querySelector('.google-btn').addEventListener('click', function() {
alert('Google login functionality will be implemented');
});
document.querySelector('.facebook-btn').addEventListener('click', function() {
alert('Facebook login functionality will be implemented');
});
// Form validation
document.querySelector('form').addEventListener('submit', function(e) {
const email = document.querySelector('input[name="email"]').value;
const password = document.querySelector('input[name="password"]').value;
if (!email || !password) {
e.preventDefault();
alert('Please fill in all fields');
}
});
</script>
</body>
</html>