<?php

class LoginModel {

	private $db;
    public function __construct()
    {
        $this->db = new Database;
        
    }
	public function login($data){
        $this->db->query('SELECT * FROM users WHERE username = :id');
        $this->db->bind(':id', $data['username']);
        $row = $this->db->single();
        if($this->db->rowCount() > 0){
            if (password_verify($data['password'], $row->password)) {
                $_SESSION['user_id'] = $row->id;
                $_SESSION['name'] = $row->username;
                $_SESSION['is_admin'] = $row->is_admin;
                return true;
            } else {
               return false;
            }
        }else{
            return false;
        }


	}
}