if ($validate !== true) {
        return Api::error($validate->errors()->getMessages(), 401);
    }
});
/**
 * Authenticate valid auth token key
 */
Route::filter('auth.token', function () {
    // Validate api key
    $rules = ['token' => 'required'];
    $validate = Hyfn::validate($rules);
    // Invalid API key
    if ($validate !== true) {
        return Api::error($validate->errors()->getMessages(), 401);
    }
    $validToken = User::isValidToken(Input::get('token'));
    if ($validToken !== true) {
        return Api::error(Lang::get('errors.invalid_token'), 401);
    }
});
Route::filter('auth.basic', function () {
    return Auth::basic();
});
/*
|--------------------------------------------------------------------------
| Guest Filter
|--------------------------------------------------------------------------
|
| The "guest" filter is the counterpart of the authentication filters as
| it simply checks that the current user is not logged in. A redirect
| response will be issued if they are, which you may freely change.
Example #2
0
require 'vendor/autoload.php';
require 'model/db.php';
require 'model/User.php';
require 'model/Table.php';
require 'model/Movie.php';
$site_path = realpath(dirname(__FILE__));
define('__SITE_PATH', $site_path);
$configuration = ['settings' => ['displayErrorDetails' => true]];
$c = new \Slim\Container($configuration);
$app = new \Slim\App($c);
$auth_mw = function ($request, $response, $next) {
    if ($request->hasHeader('X-Auth')) {
        $token = $request->getHeader('X-Auth')[0];
        $user = new User(db::getInstance());
        $result = $user->isValidToken($token);
        if ($result === true) {
            $response = $next($request, $response);
            return $response;
        }
    }
    return $response->withStatus(401);
};
$app->get('/', function ($request, $response, $args) {
    $response->write("Welcome to Slim!");
    return $response;
});
$app->get('/register', function ($request, $response, $args) {
    render('views/registration.php');
    return $response;
});