<?php 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
 include '../config/index.php';

 include('../module/index.php');

 $db = new Database();
 $con = $db->connect();


 $user = new User($con);

 $client_ip = $_SERVER['REMOTE_ADDR'];
 $user_agent = $_SERVER['HTTP_USER_AGENT'];

if(isset($_POST['login'])){
    $post = filter_var_array($_POST,FILTER_SANITIZE_SPECIAL_CHARS);
    $id =  $post['account'];
    $user->password =  $post['password'];

    if(empty($id || $user->password)){
        $error = "account or password is required";
        echo $db->redirect('../../login?errors='.$error);
    }elseif($user->login($id) == "not"){
        $error = "No user found";
        echo $db->redirect('../../login.php?errors='.$error);
    }elseif($user->login($id) == 'user'){
       echo  $user->loginLogs($user_agent ,$client_ip,$_SESSION['id']);
       $email = $_SESSION['email'];
       $status = $_SESSION['status'];
        if($status == 'ban'){
            $error = "Your account has been supended please contact support";
            echo $db->redirect('../../../login?errors='.$error); 
         }else{
          //  echo  $user->setOtp($email);
            echo $db->redirect("../../account/index?home=home");
         }
    }elseif($user->login($id) == 'admin'){
        echo  $user->loginLogs($user_agent ,$client_ip,$_SESSION['id']);
        echo $db->redirect("../../account/index?admin=admin");
    }else{
        $error = "Invalid password";
        echo $db->redirect('../../../login?errors='.$error);
    }
}

?>