<?php
include('includes/functions.php');

// Iniciar a sessão se ainda não estiver iniciada
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}

// Verificar se o usuário está logado
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === TRUE) {
    if ($_SESSION['name'] === 'admin') {
        header("Location: user.php");
    } else {
        header("Location: dns.php");
    }
    exit;
}

// Verificar o login do usuário ao enviar o formulário
if (isset($_POST["login"])) {
    $username = $_POST["username"];
    $userData = $db->select('users', '*', 'username = :username', '', [':username' => $username]);
    
    if ($userData) {
        $storedPassword = $userData[0]['password'];
        $enteredPassword = $_POST["password"];
        
        if ($enteredPassword == $storedPassword) {
            session_regenerate_id();
            $_SESSION['loggedin'] = TRUE;
            $_SESSION['name'] = $_POST['username'];
            
            if ($_SESSION['name'] === 'admin') {
                header('Location: user.php');
            } else {
                header('Location: dns.php');
            }
            exit;
        } else {
            header('Location: ./api/index.php');
            exit;
        }
    } else {
        header('Location: ./api/index.php');
        exit;
    }
}
?>


<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<meta name="author" content="eonbry. MASTER IBO">
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
	<link rel="stylesheet" href="./css/css.css">
    <title>IBO MASTER</title>
</head>
<style>
body{
  background-color: #181828;
  background-image: url("./img/binding_dark.webp");
  color #fff;
}

#particles-js{
  background-size: cover;
  background-position: 50% 50%;
  background-repeat: no-repeat;
  /*width: 100%;
  height: 100vh;*/
  background: #8000FF;
  display: flex;
  justify-content: center;
  align-items: center;

}

.particles-js-canvas-el{
  position: fixed;
}
</style>
<div id="js-particles"></div>
<br><br>
        <div class="container">
            <div class="row">
                <div class="col-lg-4 mx-md-auto">
                    <div class="text-center">
                        <img class="w-75 p-3" src="./img/logo.png" alt="">
                    </div>
                    <br>
                    <form method="post">
                        <div class="form-group">
                            <input type="text" class="form-control form-control-lg"
                                   placeholder="Usuário" name="username" required autofocus>
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control form-control-lg"
                                   placeholder="Senha" name="password" required>
                        </div>
                        <input type="submit" class="btn btn-warning btn-lg btn-block" value="Acessar" name="login">
                    </form>
					<br>
                 <center><a class="list-grup-item" href="https://scripts-apks.webnode.page/" target="_blank">&nbsp&nbsp&nbsp&nbsp&#169  <?=date("Y")?> * IBO MASTER REVENDA - * </a></center>
                 <center><a class="list-grup-item" href="https://t.me/ebjnasciment" target="_blank">&nbsp&nbsp&nbsp&nbsp&#169  <?=date("Y")?> * CONTATO * </a></center>
                </div>
            </div>
        </div>
<br><br>

<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
<script src="js/particles.js"></script>

