I'm creating a MVC framework a couple of weeks (developing it and using it at the same time), I got to the part of creating the authentication system.
So I would like to create a way for me to configure which routes the user can access when he is not authenticated in the applications that are created on top of Framework , without having to check each method if the user is authenticated or not.
I already have the code snippet where I call the controller to get an idea of what I'm developing.
class Application {
public static function RUN() {
$request = New Request();
$class = '\Controller\'.$request->class.'Controller';
if (!empty($request->post['mvc:model'])){
$model = '\Model\' . array_remove($request->post, 'mvc:model') . 'Model';
$param = New $model($request->post);
} else if (!empty($request->lost))
$param = $request->lost;
else {
$param = NULL;
}
try {
$app = New $class();
$action = $request->action;
if (!is_null($param) && !empty($param))
$app->$action($param);
else
$app->$action();
} catch (SystemException $e) {
if ( strpos(Exceptions::E_FILENOTFOUND.'|'.Exceptions::E_CLASSNOTEXIST, $e->getCode()) !== FALSE){
$app = New \Controller\FileNotFound();
$app->file = $class;
$app->index();
} else {
$app = New \Controller\ErrorController();
$app->message = $e->getMessage();
$app->error = $class;
$app->index();
}
}
$app->output();
}
}
The point is that I'm not in the mood to call a method to verify that the user is authenticated to every method I create. So I would need a way to set up in Application::Run()
to check if the user has permission to access the requested route.
Is there any default in MVC templates?