3
I’m creating a MVC framework a few weeks (developing it and using it at the same time), I arrived at the part of creating the authentication system.
So I’d like to create a way for me to configure which routes the user can access when it’s not authenticated in the applications that are created on top of the Framework, without having to check each method whether the user is authenticated or not.
I already have the code section 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 really in the mood of calling a method to verify that the user is authenticated to every method I create. Then you would need a way to set up in Application::Run()
check if the user has permission to access the requested route.
There is already some standard in MVC models?
Please avoid long discussions in the comments; your talk was moved to the chat
– Maniero