Wednesday, July 1, 2015

myFrontController v0.2

Usually the continuation of a good movie is bad, hopefully my version 0.2 of myFrontController is a real progress.


I moved the files inside specific folders like: controllers, model, login, admin etc. Doing this means I need to implement a more complex autoloading function.

$folders=array('\\controller\\','\\model\\','\\login\\','\\view\\');
   
    foreach($folders as $folder){
       
       if(file_exists($dir . $folder . $class . '.class.php')){
            require_once $dir . $folder . $class . '.class.php';
        }


It is not covering some situations for this reason you may see some "include" in some classes, but I promise to solve the issue in v0.3

I am trying to start using comments in the style used by PHP Documentor. Step by step I hope to get used to write them. An  IDE would probably automatically generate the comments skeleton but at the moment I am using Notepad++

In the image below it is more or less described how my website works and a little on how I implemented the separation of concerns following the MVC design pattern ideas.



Changes from version 0.1 of myFrontController:

added DBCon.class.php - handles connection to database and fetching data

added StaticPages.classes.php -
added BlogModel.classes.php

- replace & with & in the links

----------- database --------------------------------
shift from SQLite to MySQL
create database "myblog"
create table  static_pages
alter table blogposts add column title varchar(255)


----------------------------------------------------------------------------------------------------------------------------------------
added basic login module (based on cookies) to the have an Admin view from where you can add new posts
added:
index_admin.php
/controller/Admin.class.php
/login/LoginUser.class.php

--------------------------------------------------
login module explained:
    first I hardcoded the username and passord inside the static function validateUserPass of the class LoginUser
    ---
    static public function validateUserPass($user,$pass){
            if(($user=='admin')&&($pass=='1234')){
                return true;

    ---

    From a form, username and password are sent via POST method using hidden fields (login.php):

            <form action="index.php" method="POST" >
                Username <br>
                <input type="text" name="username">
                <br>Password <br>
                <input type="text" name="password">
                <input type="submit" value="Login">
                <input type="hidden" name="controller" value="Admin">
                <input type="hidden" name="action" value="validateLogin">
            </form>

    ---
    the hidden values indicate controller name "Admin" and action "validateLogin"

    if the user and password match the ones hardcoded than we set a cookie containing an md5 hash of the user name + a secret word.

     setcookie('PageLogin', md5($user.self::$secret_word));
     setcookie('PageLoginUser', $user);


The files can be downloaded from this link:  https://drive.google.com/file/d/0B4lszAGYHn-dTXNOX2psd2QweGc/view?usp=sharing

No comments:

Post a Comment