<commit_before><?php
/*
 * Current User class
 */
class CurrentUser extends User {
    protected $session; // current session id
    protected $ip; // user ip address
    
    /*
     * Create current user object
     * Store session id and ip address into object
     */
    function __construct() {
        session_name("felix"); // set session name
        session_start(); // start session
        $this->session = session_id(); // store session id into $session variable
        $this->ip = $_SERVER['REMOTE_ADDR'];
        if($this->isLoggedIn()) {
            $this->setUser($this->isLoggedIn());
        }
    }

    /*
     * Public: Resets the session cookie, regenerating its ID, and ensures old session data is removed
     */
    function resetToGuest()
    {
        // the true parameter clears the current session
        session_destroy();
        session_start();
        session_regenerate_id(true);
        
        $this->session = session_id();
    }

    /*
     * Private: Check if user has just logged in
     */

    /*
     * Public: Check if user is currently logged in
     *
     * Returns boolean
     */
    public function isLoggedIn() {
        if($_SESSION['felix']['loggedin'] && $this->isSessionRecent()){
            return $_SESSION['felix']['uname'];
        } else {
            // n.b. we don't reset the session here unless we have a bad one
            return false;
        }
    }

    /*
     * Public: Check if the session is recent (the last visited time is updated
     * on every visit, if this is greater than two hours then we need to log in
     * again, unless the cookie is valid
     */
    public function isSessionRecent()
    {
        if (!$_SESSION['felix']['loggedin']) {
            return false; // If we have no session, this method is meaningless.
        }

        global $db;
        $sql = "SELECT
                    TIMESTAMPDIFF(SECOND,timestamp,NOW()) AS timediff,
                    ip,
                    browser
                FROM `login`
                WHERE session_id='".$this->session."'
                AND logged_in=1
                AND valid=1
                ORDER BY timediff ASC
                LIMIT 1
        ";

        $user = $db->get_row($sql);

        if (
            $user->timediff <= SESSION_LENGTH 
            && $user->ip == $_SERVER['REMOTE_ADDR']
            && $user->browser == $_SERVER['HTTP_USER_AGENT']
        ) {
            return true;
        } else {<commit_msg>Check to make sure user has not changed the username in the cookie<commit_after><?php
/*
 * Current User class
 */
class CurrentUser extends User {
    protected $session; // current session id
    protected $ip; // user ip address
    
    /*
     * Create current user object
     * Store session id and ip address into object
     */
    function __construct() {
        session_name("felix"); // set session name
        session_start(); // start session
        $this->session = session_id(); // store session id into $session variable
        $this->ip = $_SERVER['REMOTE_ADDR'];
        if($this->isLoggedIn()) {
            $this->setUser($this->isLoggedIn());
        }
    }

    /*
     * Public: Resets the session cookie, regenerating its ID, and ensures old session data is removed
     */
    function resetToGuest()
    {
        // the true parameter clears the current session
        session_destroy();
        session_start();
        session_regenerate_id(true);
        
        $this->session = session_id();
    }

    /*
     * Private: Check if user has just logged in
     */

    /*
     * Public: Check if user is currently logged in
     *
     * Returns boolean
     */
    public function isLoggedIn() {
        if($_SESSION['felix']['loggedin'] && $this->isSessionRecent()){
            return $_SESSION['felix']['uname'];
        } else {
            // n.b. we don't reset the session here unless we have a bad one
            return false;
        }
    }

    /*
     * Public: Check if the session is recent (the last visited time is updated
     * on every visit, if this is greater than two hours then we need to log in
     * again, unless the cookie is valid
     */
    public function isSessionRecent()
    {
        if (!$_SESSION['felix']['loggedin']) {
            return false; // If we have no session, this method is meaningless.
        }

        global $db;
        $sql = "SELECT
                    TIMESTAMPDIFF(SECOND,timestamp,NOW()) AS timediff,
                    ip,
                    browser
                FROM `login`
                WHERE session_id='".$this->session."'
                AND logged_in=1
                AND valid=1
                AND user='".$_SESSION['felix']['uname']."'
                ORDER BY timediff ASC
                LIMIT 1
        ";

        $user = $db->get_row($sql);

        if (
            $user->timediff <= SESSION_LENGTH 
            && $user->ip == $_SERVER['REMOTE_ADDR']
            && $user->browser == $_SERVER['HTTP_USER_AGENT']
        ) {
            return true;
        } else {
{'fraction_non_alphanumeric': 0.11062992125984251, 'fraction_numerical': 0.0011811023622047244, 'mean_word_length': 1.6983536909187467, 'pattern_counts': {'":': 0, '<': 7, '<?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': '632970', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1327, 'n_words': 428}