I built a filter which checks some keys and ids sent and then gives the go or no go. The problem is that a filter in Laravel should return a string while I just wnat to return a boolean and let it trigger the intended route.
Filter:
Route::filter('api_checkauth', function($route)
{
//user"ok"
$user_id = (int) $route->getParameter('user_id');
$sig = $route->getParameter('sig');
$user = User::find($user_id);
if($user) {
//user email
$email = $user->email;
//user api key
$api_key = $user->api_key;
//recreate signature
$_sig = hash_hmac("sha256", $email . $user_id, $api_key);
if($_sig === $sig) {
return Response::json(array("message"=>"Request Ok"),200);
} else {
return Response::json(array("message"=>"Request Bad"),400);
}
} else {
return Response::json(array("message"=>"Request not authorized"),401);
}
});
Routes:
// Route group for API versioning
Route::group(array('prefix' => 'api/v1', 'before' => 'api_checkauth'), function()
{
Route::get('/pim/{user_id}/{sig}', 'MoreOrLessController@index');
});
So the question is, how can I still trigger the route which i defined in the group? Because what happens now is a that only a message is printed instead of a controller method that should be triggered.
Thanks