<commit_before><?php defined('BLUDIT') or die('Bludit CMS.');

class Login {

    protected $users;
    protected $site;

    function __construct()
    {
        if (isset($GLOBALS['users'])) {
            $this->users = $GLOBALS['users'];
        } else {
            $this->users = new Users();
        }

        if (isset($GLOBALS['site'])) {
            $this->site = $GLOBALS['site'];
        } else {
            $this->site = new Site();
        }

        // Start the Session
        if (!Session::started()) {
            Session::start($this->site->urlPath(), $this->site->isHTTPS());
        }
    }

    // Returns the username
    public function username()
    {
        return Session::get('username');
    }

    // Returns the role
    public function role()
    {
        return Session::get('role');
    }

    // Returns the authentication token
    public function tokenAuth()
    {
        return Session::get('tokenAuth');
    }

    // Returns TRUE if the user is logged, FALSE otherwise
    public function isLogged()
    {
        if (Session::get('fingerPrint')===$this->fingerPrint()) {
            $username = Session::get('username');
            if (!empty($username) && $this->users->getUserDB($username) !== false) {
                return true;
            } else {
                Log::set(__METHOD__.LOG_SEP.'Session username empty or user not found, destroying the session.');
                Session::destroy();
                return false;
            }
        }

        Log::set(__METHOD__.LOG_SEP.'FingerPrints are different. ['.Session::get('fingerPrint').'] != ['.$this->fingerPrint().']');
        return false;
    }

    // Set the session for the user logged<commit_msg>check if the user of the session is in the database - change method<commit_after><?php defined('BLUDIT') or die('Bludit CMS.');

class Login {

    protected $users;
    protected $site;

    function __construct()
    {
        if (isset($GLOBALS['users'])) {
            $this->users = $GLOBALS['users'];
        } else {
            $this->users = new Users();
        }

        if (isset($GLOBALS['site'])) {
            $this->site = $GLOBALS['site'];
        } else {
            $this->site = new Site();
        }

        // Start the Session
        if (!Session::started()) {
            Session::start($this->site->urlPath(), $this->site->isHTTPS());
        }
    }

    // Returns the username
    public function username()
    {
        return Session::get('username');
    }

    // Returns the role
    public function role()
    {
        return Session::get('role');
    }

    // Returns the authentication token
    public function tokenAuth()
    {
        return Session::get('tokenAuth');
    }

    // Returns TRUE if the user is logged, FALSE otherwise
    public function isLogged()
    {
        if (Session::get('fingerPrint')===$this->fingerPrint()) {
            $username = Session::get('username');
            if (!empty($username) && $this->users->exists($username)) {
                return true;
            } else {
                Log::set(__METHOD__.LOG_SEP.'Session username empty or user not found, destroying the session.');
                Session::destroy();
                return false;
            }
        }

        Log::set(__METHOD__.LOG_SEP.'FingerPrints are different. ['.Session::get('fingerPrint').'] != ['.$this->fingerPrint().']');
        return false;
    }

    // Set the session for the user logged
{'fraction_non_alphanumeric': 0.15256667622598222, 'fraction_numerical': 0.0, 'mean_word_length': 1.94843617920541, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '207175', 'n_tokens_mistral': 949, 'n_tokens_neox': 916, 'n_words': 232}