<?php
require_once 'includes/auth.php';

$auth = new Auth();

$error = '';
$success = '';

if (isset($_GET['error']) && $_GET['error'] === 'session_lost') {
    $error = 'Your login session was not saved. The server accepted your credentials but your browser did not keep the session cookie. Try again, or contact support if this continues.';
}

if ($auth->isLoggedIn()) {
    header("Location: user/dashboard.php");
    exit();
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $result = $auth->login($_POST);
    if ($result['success']) {
        header("Location: user/dashboard.php");
        exit();
    } else {
        $error = $result['message'];
    }
}

$page_title = "Login";
include 'includes/header.php';
?>

<link rel="stylesheet" href="home/style/style_log.css">
<style>
    .logincontainer {
        margin: 40px auto 100px auto;
        padding: 0 10px;
        max-width: 500px
    }

    .logincontainer.with-social {
        max-width: 650px
    }

    .logincontainer .social-signin-btns {
        padding: 23px 0
    }

    @media (max-width:500px) {
        .logincontainer .social-signin-btns .btn {
            display: block;
            width: 100%
        }
    }

    @media (max-width:600px) {
        .logincontainer {
            margin: 0 auto 30px auto
        }
    }

    @media (min-width:768px) {
        .logincontainer.with-social .login-form {
            padding-right: 29px;
            border-right: 1px solid #ddd
        }

        .logincontainer .social-signin-btns .btn {
            display: block;
            width: 100%
        }
    }

</style>
<style type="text/css">
    @keyframes tawkMaxOpen {
        0% {
            opacity: 0;
            transform: translate(0, 30px);
            ;
        }

        to {
            opacity: 1;
            transform: translate(0, 0px);
        }
    }

    @-moz-keyframes tawkMaxOpen {
        0% {
            opacity: 0;
            transform: translate(0, 30px);
            ;
        }

        to {
            opacity: 1;
            transform: translate(0, 0px);
        }
    }

    @-webkit-keyframes tawkMaxOpen {
        0% {
            opacity: 0;
            transform: translate(0, 30px);
            ;
        }

        to {
            opacity: 1;
            transform: translate(0, 0px);
        }
    }

    #d0nmgkh-1599928865653 {
        outline: none !important;
        visibility: visible !important;
        resize: none !important;
        box-shadow: none !important;
        overflow: visible !important;
        background: none !important;
        opacity: 1 !important;
        filter: alpha(opacity=100) !important;
        -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity1) !important;
        -moz-opacity: 1 !important;
        -khtml-opacity: 1 !important;
        top: auto !important;
        right: 10px !important;
        bottom: 90px !important;
        left: auto !important;
        position: fixed !important;
        border: 0 !important;
        min-height: 0 !important;
        min-width: 0 !important;
        max-height: none !important;
        max-width: none !important;
        padding: 0 !important;
        margin: 0 !important;
        -moz-transition-property: none !important;
        -webkit-transition-property: none !important;
        -o-transition-property: none !important;
        transition-property: none !important;
        transform: none !important;
        -webkit-transform: none !important;
        -ms-transform: none !important;
        width: auto !important;
        height: auto !important;
        display: none !important;
        z-index: 2000000000 !important;
        background-color: transparent !important;
        cursor: auto !important;
        float: none !important;
        border-radius: unset !important;
        pointer-events: auto !important
    }

    #xFEjK6J-1599928865658.open {
        animation: tawkMaxOpen .25s ease !important;
    }

</style>


<br>
<br><br>
<section id="main-body">
    <div class="container">
        <div class="row">
            <!-- Container for main page display content -->
            <div class="col-xs-12 main-content">
                <div class="logincontainer">
                    <div class="header-lined">
                            <h1 class="text-warning">Login <small> </small></h1>
                    </div>
                        <div class="bg-white p-5 rounded-lg shadow">
                    <div class="providerLinkingFeedback"></div>
                    <div class="row">
                        <div class="col-sm-12">

<script language="javascript">
function checkform() {
    if (document.mainform.email.value=='') {
        alert("Please type your email!");
        document.mainform.email.focus();
        return false;
    }
    if (document.mainform.password.value=='') {
        alert("Please type your password!");
        document.mainform.password.focus();
        return false;
    }
    return true;
}
</script>

<?php if (!empty($error)): ?>
    <div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>

<?php if (defined('SHOW_DEBUG_ERRORS') && SHOW_DEBUG_ERRORS): ?>
    <div class="alert alert-info small">
        <strong>Debug info</strong><br>
        Session ID: <?php echo htmlspecialchars(session_id() ?: '(none)'); ?><br>
        Logged in: <?php echo $auth->isLoggedIn() ? 'yes' : 'no'; ?><br>
        HTTPS: <?php echo (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'yes' : 'no'; ?><br>
        Check server log: <code>error_log</code> in the project root.
    </div>
<?php endif; ?>

<form method="post" name="mainform" onsubmit="return checkform()">
    <input type="hidden" name="follow" value="<?php echo isset($_REQUEST['follow']) ? htmlspecialchars($_REQUEST['follow']) : ''; ?>">
    <input type="hidden" name="follow_id" value="<?php echo isset($_REQUEST['follow_id']) ? htmlspecialchars($_REQUEST['follow_id']) : ''; ?>">

    <div class="form-group">
            <label for="inputEmail">Email</label>
            <input type="email" class="form-control mb-0" placeholder="Enter Email" name="email" value="<?php echo isset($_POST['email']) ? htmlspecialchars($_POST['email']) : ''; ?>">
    </div>
    <div class="form-group">
            <label for="inputPassword">Password</label>
            <input type="password" class="form-control mb-0" id="exampleInputPassword1" placeholder="Enter Password" name="password" value="">
    </div>

    <?php // If you have a captcha include, uncomment or adapt the following line
    // include 'includes/captcha.php'; ?>

    <div class="checkbox">
            <label>
                    <input type="checkbox" name="rememberme"> Remember me
            </label>
    </div>

    <div class="text-center margin-bottom">
    </div>
    <div align="center">
            <button type="submit" class="btn btn-warning jj float-right">Sign in</button><br><br>
            <a href="forgot-password.php" class="btn btn-link">Forgot password?</a>
            <br><center>Don't have an account? <a href="register" class="text-warning">Register</a></center>
    </div>

</form>
                </div>
                        </div>
                        <div class="col-sm-5 hidden">
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.main-content -->
            <div class="clearfix"></div>
        </div>

    </div>
</section>

<?php include 'includes/footerm.php'; ?>

