<?php
    error_reporting(E_ALL ^ E_NOTICE);  

    session_start();
    
    /*
        Date :  June 1, 2016
        Maintaining sessions directly with PHP Sessions for the time being.
        Assuming that the traffic at any given point in time is limited, it might suffice.$_COOKIE
        
        Will need to rework later for more persistant and scalable sessions.
    */
    
    function loginUser($user){
        if(session_start()){
            $_SESSION["user"] = json_decode(json_encode($user));
            $_SESSION["login_time"] = time();
            $_SESSION["start_time"] = time();
            $_SESSION["is_verified"] = $user->is_verified;
            $_SESSION["email_id"] = $user->email_id;
            $_SESSION["account_user_id"] = $user->_id;
            // echo($_SESSION["verified"]);
            // die();
        }
    }
    // logoutUser();
    function logoutUser($user = NULL){
        session_start();
        session_unset();
        session_destroy();
    }
    
    function isLoggedIn(){
        return (isset($_SESSION["user"]) && !is_null($_SESSION["user"]));
    }

    function isVerified(){
        return ($_SESSION["is_verified"]);
    }
    
    /*
    echo json_encode($_SESSION);
    $time_elapsed =  time() - $_SESSION['start_time'] ;
    echo "Time elapsed sonce start time is ";
    echo $time_elapsed;
    */
?>