diff --git a/.gitignore b/.gitignore index f0ee7bb..b471de2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -sys/*.sqlite \ No newline at end of file +sys/*.sqlite +docs/* \ No newline at end of file diff --git a/app/classes/controller.php b/app/classes/controller.php new file mode 100644 index 0000000..f458ba1 --- /dev/null +++ b/app/classes/controller.php @@ -0,0 +1,43 @@ +load_model('meta\model'); + $this->page->build_header(); + } + + /** + * Destruct controller and build page footer + */ + public function __destruct() + { + $this->page->build_footer(); + } + +} diff --git a/app/modules/meta/controllers/category.php b/app/modules/meta/controllers/category.php index 0e62ced..92ef9a2 100644 --- a/app/modules/meta/controllers/category.php +++ b/app/modules/meta/controllers/category.php @@ -18,7 +18,7 @@ * * @package meta */ -class Category extends miniMVC\Controller { +class category extends meta\controller { /** * Initialize the Controller @@ -26,10 +26,6 @@ class Category extends miniMVC\Controller { public function __construct() { parent::__construct(); - - $this->load_model('meta\model'); - - $this->page->build_header(); } /** @@ -37,13 +33,6 @@ class Category extends miniMVC\Controller { */ public function index() { - $id = (int) miniMVC\get_last_segment(); - - if ($id === 0) - { - return miniMVC\show_404(); - } - $this->detail(); } @@ -69,15 +58,23 @@ class Category extends miniMVC\Controller { } // Render the basic page - $this->index(); + $this->detail(-1); } /** * Returns the sections / editing options for a category */ - public function detail() + public function detail($id = 0) { - $id = (int) miniMVC\get_last_segment(); + if ($id === 0) + { + $id = (int) miniMVC\get_last_segment(); + } + + if ($id === 0) + { + miniMVC\show_404(); + } $data = array( 'category' => $this->model->get_category_by_id($id), @@ -86,7 +83,6 @@ class Category extends miniMVC\Controller { ); $this->load_view('category_detail', $data); - $this->page->build_footer(); } } diff --git a/app/modules/meta/controllers/genre.php b/app/modules/meta/controllers/genre.php index c8a5ea7..3163137 100644 --- a/app/modules/meta/controllers/genre.php +++ b/app/modules/meta/controllers/genre.php @@ -18,7 +18,7 @@ * * @package meta */ -class Genre extends miniMVC\Controller { +class genre extends meta\controller { /** * Initialize the Controller @@ -26,10 +26,6 @@ class Genre extends miniMVC\Controller { public function __construct() { parent::__construct(); - - $this->load_model('meta\model'); - - $this->page->build_header(); } /** @@ -51,7 +47,6 @@ class Genre extends miniMVC\Controller { $data['genres'] = $this->model->get_genres(); $this->load_view('genres', $data); - $this->page->build_footer(); } /** @@ -95,7 +90,6 @@ class Genre extends miniMVC\Controller { ); $this->load_view('genre_detail', $data); - $this->page->build_footer(); } } diff --git a/app/modules/meta/controllers/section.php b/app/modules/meta/controllers/section.php index 7260261..01c375a 100644 --- a/app/modules/meta/controllers/section.php +++ b/app/modules/meta/controllers/section.php @@ -16,12 +16,25 @@ /** * Section Controller */ -class Section extends \miniMVC\Controller { +class section extends meta\controller { /** * Constructor */ public function __construct() + { + parent::__construct(); + } + + public function index() + { + + } + + /** + * Adds a new section to the current category + */ + public function add() { } diff --git a/app/modules/meta/controllers/welcome.php b/app/modules/meta/controllers/welcome.php index 2ce9a24..cc5050c 100644 --- a/app/modules/meta/controllers/welcome.php +++ b/app/modules/meta/controllers/welcome.php @@ -18,7 +18,7 @@ * * @package meta */ -class Welcome extends miniMVC\Controller { +class welcome extends miniMVC\Controller { /** * Initialize the constructor @@ -30,6 +30,7 @@ class Welcome extends miniMVC\Controller { parent::__construct(); $this->load_model('meta\model'); + $this->load_model('meta\user_model'); } diff --git a/app/modules/meta/models/model.php b/app/modules/meta/models/model.php index aa2e920..5aa913a 100644 --- a/app/modules/meta/models/model.php +++ b/app/modules/meta/models/model.php @@ -20,7 +20,7 @@ namespace meta; * * @package meta */ -class Model extends \miniMVC\Model { +class model extends \miniMVC\Model { /** * Reference to database connection diff --git a/app/modules/meta/models/user_model.php b/app/modules/meta/models/user_model.php index 34e7d7b..25bdd98 100644 --- a/app/modules/meta/models/user_model.php +++ b/app/modules/meta/models/user_model.php @@ -20,7 +20,14 @@ namespace meta; * * @package meta */ -class User_model extends \miniMVC\Model { +class user_model extends \miniMVC\Model { + + /** + * Reference to bcrypt object + * + * @var Bcrypt + */ + protected $bcrypt; /** * Initialize the User model @@ -28,6 +35,34 @@ class User_model extends \miniMVC\Model { public function __construct() { parent::__construct(); + + $this->bcrypt = new \Bcrypt(15); + } + + // -------------------------------------------------------------------------- + + /** + * Check and see if the login is valid + * + * @param string + * @param string + * @return bool + */ + public function check_login($username, $pass) + { + $query = $this->db->from('user') + ->where('username', $username) + ->get(); + + $row = $query->fetch(\PDO::FETCH_ASSOC); + + // The user does not exist + if (empty($row)) + { + return FALSE; + } + + return $this->bcrypt->verify($pass, $row['hash']); } } diff --git a/app/views/errors/error_404.php b/app/views/errors/error_404.php index e210433..b82ebbb 100644 --- a/app/views/errors/error_404.php +++ b/app/views/errors/error_404.php @@ -11,9 +11,9 @@