/home/awneajlw/public_html/codestechvista.com/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 output buffering to prevent headers already sent error
ob_start();
// 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['user_name'] = $user['name'];
$_SESSION['user_email'] = $user['email'];
$_SESSION['name'] = $user['name'];
$_SESSION['email'] = $user['email'];
$_SESSION['role'] = $user['role'];
$_SESSION['logged_in'] = true;
$_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;
margin: 0;
padding: 0;
}
.header {
background: #374151;
padding: 15px 30px;
color: white;
font-size: 18px;
font-weight: 600;
text-transform: uppercase;
}
.main-container {
background: white;
overflow: hidden;
width: 100%;
min-height: 100vh;
display: flex;
position: relative;
}
.left-section {
flex: 1;
background: #169D53;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 60px 40px;
position: relative;
clip-path: polygon(0 0, 100% 0, 65% 100%, 0% 100%);
color: white;
}
.logo-container {
text-align: center;
margin-bottom: 40px;
}
.logo-icon {
width: 120px;
height: 120px;
background: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 20px;
position: relative;
}
.glasses-container {
display: flex;
align-items: center;
gap: 5px;
}
.glasses-lens {
width: 35px;
height: 35px;
border: 3px solid #169D53;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 10px;
color: #169D53;
font-weight: bold;
}
.glasses-bridge {
width: 8px;
height: 3px;
background: #169D53;
border-radius: 2px;
}
.logo-image {
/* width: 100%; */
/* height: 100%; */
width: 220px;
height: auto;
object-fit: contain;
border-radius: 50%;
display: block;
/* background: red; Debugging - remove if working */
}
.description-text {
color: white;
font-size: 196x;
/* line-height: 1.6; */
text-align: center;
max-width: 320px;
opacity: 0.95;
}
.right-section {
flex: 1;
background: white;
display: flex;
flex-direction: column;
justify-content: center;
padding: 60px 50px;
position: relative;
}
.welcome-text {
font-size: 56px;
font-weight: 700;
color: #1f2937;
margin-bottom: 50px;
text-align: left;
}
.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: 18px 20px;
border: 2px solid #e5e7eb;
border-radius: 12px;
font-size: 16px;
transition: all 0.3s ease;
background: white;
}
.form-input:focus {
outline: none;
border-color: #169D53;
box-shadow: 0 0 0 3px rgba(22, 157, 83, 0.1);
}
.remember-section {
display: flex;
align-items: center;
margin-bottom: 25px;
}
.remember-checkbox {
width: 20px;
height: 20px;
margin-right: 12px;
accent-color: #169D53;
}
.remember-label {
font-size: 14px;
color: #6b7280;
}
.signin-btn {
width: 100%;
padding: 18px 20px;
background: #169D53;
color: white;
border: none;
border-radius: 12px;
font-size: 16px;
font-weight: 600;
text-transform: uppercase;
cursor: pointer;
transition: all 0.3s ease;
margin-bottom: 30px;
box-shadow: 0 4px 12px rgba(22, 157, 83, 0.3);
}
.signin-btn:hover {
background: #138043;
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(22, 157, 83, 0.4);
}
.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: 15px 20px;
border: 2px solid #e5e7eb;
border-radius: 12px;
background: white;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
font-size: 19px;
font-weight: 500;
color: #374151;
gap: 5px;
white-space: nowrap;
}
.social-btn:hover {
border-color: #9ca3af;
background: #f9fafb;
}
.google-btn {
background: #fff;
border: 2px solid #dadce0;
color: #3c4043;
}
.google-btn:hover {
background: #f8f9fa;
border-color: #dadce0;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.google-btn i {
color: #ea4335;
font-size: 18px;
}
.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: #169D53;
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;
}
}
.remember-section {
display: flex;
justify-content: space-between; /* Left me checkbox, right me link */
align-items: center;
margin-bottom: 20px;
}
.remember-left {
display: flex;
align-items: center;
gap: 8px; /* Checkbox aur label ke beech gap */
}
.remember-label {
font-size: 14px;
color: #6b7280;
cursor: pointer;
}
.forgot-link a {
font-size: 14px;
color: #169D53;
text-decoration: none;
font-weight: 600;
}
.forgot-link a:hover {
text-decoration: underline;
}
</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"> -->
<img src="assets/images/OptiSlip.png" alt="Opti Slip Logo" class="logo-image" onload="console.log('Image loaded!')" onerror="console.log('Image failed to load'); this.style.background='blue'; this.alt='IMAGE NOT FOUND';"">
<!-- </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">
<div class="remember-left">
<input type="checkbox" class="remember-checkbox" id="remember">
<label for="remember" class="remember-label">Remember me</label>
</div>
<div class="forgot-link">
<a href="forgot_password.php">Forgot Password?</a>
</div>
</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" onclick="signInWithGoogle()">
<i class="fab fa-google"></i>
<span>Continue with Google</span>
</button>
<!-- <button type="button" class="social-btn facebook-btn">
<span>Continue with</span>
<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>
<!-- Google API Script -->
<script src="https://apis.google.com/js/api.js"></script>
<script src="https://accounts.google.com/gsi/client" async defer></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Google Sign-In Configuration
const GOOGLE_CLIENT_ID = '73807454033-o7n4e623mhv335nonlm0r3n34mievdv7.apps.googleusercontent.com';
// Initialize Google Sign-In
function initializeGoogleSignIn() {
gapi.load('auth2', function() {
gapi.auth2.init({
client_id: GOOGLE_CLIENT_ID
});
});
}
// Google Sign-In Function
function signInWithGoogle() {
// Auto-detect environment for redirect URI
const isLocal = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
const redirectUri = isLocal ?
'http://localhost/optical_slip/auth/google_callback.php' :
'https://optislip.com/auth/google_callback.php';
const authUrl = 'https://accounts.google.com/o/oauth2/auth?' +
'client_id=' + GOOGLE_CLIENT_ID +
'&redirect_uri=' + encodeURIComponent(redirectUri) +
'&scope=email profile' +
'&response_type=code' +
'&access_type=offline';
// Redirect to Google OAuth
window.location.href = authUrl;
}
// Initialize on page load
window.onload = function() {
initializeGoogleSignIn();
};
// 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>
<?php
// Clean up output buffer
ob_end_flush();
?>