<commit_before><?php

/**
* @author <NAME>
*/
class User extends Model
{
    public $id;
    public $username;
    public $password;
    public $firstname;
    public $lastname;
    public $isAdmin;

    public function __construct()
    {
       parent::__construct();
    }

    /**
     * Finds and returns an User by its id
     *
     * @param int $id
     * @return User
     */
    public static function find($id) {
        $result = DatabaseConnection::getResult("SELECT * FROM users WHERE id=:id", ["id" => $id]);
        var_dump($result);

        $userObject = new User();
        $userObject->id = $result[0]["id"];
        $userObject->username = $result[0]["username"];
        $userObject->password = $result[0]["password"];
        $userObject->firstname = $result[0]["firstname"];
        $userObject->lastname = $result[0]["lastname"];
        $userObject->isAdmin = $result[0]["isAdmin"];

        return $userObject;
    }

    /**
     * Return all users as an array
     *
     * @return array
     */
    public static function getAll() {
        $result = [];
        $sqlResult = DatabaseConnection::getResult("SELECT * FROM users");

        foreach($sqlResult as $user) {
            $userObject = new User();
	        $userObject->id = $result["id"];
	        $userObject->username = $result["username"];
	        $userObject->password = $result["password"];
	        $userObject->firstname = $result["firstname"];
	        $userObject->lastname = $result["lastname"];
	        $userObject->isAdmin = $result["isAdmin"];

            $result[] = $userObject;
        }

        return $result;
    }


}<commit_msg>Added more methods to the UserModel<commit_after><?php

/**
* @author <NAME>
*/
class User extends Model
{
    public $id;
    public $username;
    public $password;
    public $firstname;
    public $lastname;
    public $isAdmin;

    public function __construct()
    {
       parent::__construct();
    }

    /**
     * Checks whether a user is logged in or not
     *
     * @return bool
     */
    public static function auth() {

    	if(isset($_SESSION["user"]["logged_in"]) && $_SESSION["user"]["logged_in"] === true) {
    		return true;
    	}

    	return false;
    }

    /**
     * Try to login with a user
     *
     * @return bool
     */
    public function login() {

    	$checkUser = User::getByUsername($this->username);
    	if(password_verify($this->password, $checkUser->password)) {
    		return true;
    	}
    	

    	return false;
    }

    /**
     * Save the user data in db
     */
    public function register() {
    	DatabaseConnection::getResult("INSERT INTO users(username, password, firstname, lastname, isAdmin) VALUES(:username, :password, :firstname, :lastname, 0)",
    									["username" => $this->username,
    									"password" => password_hash($this->password),
    									"firstname" => $this->firstname,
    									"lastname" => $this->lastname]);
    }

    /**
     * Finds and returns an User by its id
     *
     * @param int $id
     * @return User
     */
    public static function find($id) {
        $result = DatabaseConnection::getResult("SELECT * FROM users WHERE id=:id", ["id" => $id]);

        $userObject = new User();
        $userObject->id = $result[0]["id"];
        $userObject->username = $result[0]["username"];
        $userObject->password = $result[0]["password"];
        $userObject->firstname = $result[0]["firstname"];
        $userObject->lastname = $result[0]["lastname"];
        $userObject->isAdmin = $result[0]["isAdmin"];

        return $userObject;
    }

    /**
     * Return all users as an array
     *
     * @return array
     */
    public static function getAll() {
        $result = [];
        $sqlResult = DatabaseConnection::getResult("SELECT * FROM users");

        foreach($sqlResult as $user) {
            $userObject = new User();
	        $userObject->id = $result["id"];
	        $userObject->username = $result["username"];
	        $userObject->password = $result["password"];
	        $userObject->firstname = $result["firstname"];
	        $userObject->lastname = $result["lastname"];
	        $userObject->isAdmin = $result["isAdmin"];

            $result[] = $userObject;
        }

        return $result;
    }

    /**
     * Return an user by its username
     *
     * @param string $username
     * @return User
     */
    public static function getByUsername($username) {
    	$result = DatabaseConnection::getResult("SELECT * FROM users WHERE username=:username", ["username" => $username]);

    	$userObject = new User();
        $userObject->id = $result[0]["id"];
        $userObject->username = $result[0]["username"];
        $userObject->password = $result[0]["password"];
        $userObject->firstname = $result[0]["firstname"];
        $userObject->lastname = $result[0]["lastname"];
        $userObject->isAdmin = $result[0]["isAdmin"];

        return $userObject;
    }


}
{'fraction_non_alphanumeric': 0.1591549295774648, 'fraction_numerical': 0.003822937625754527, 'mean_word_length': 2.397812713602187, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 49, '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': '6959271', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1451, 'n_words': 324}