website/app/filters.php

32 lines
899 B
PHP
Raw Normal View History

2015-08-30 12:34:43 -04:00
<?php
$authenticationCheck = function($required) use ($app) {
return function() use ($required, $app) {
if ((!$app->auth && $required) || ($app->auth && !$required)) {
if (!$app->auth && $required) {
$app->flash('global', 'Hey buddy, you need to sign in first!');
} else if ($app->auth && !$required) {
$app->flash('global', 'Woah there, why do you want to do that?');
}
$app->redirect($app->urlFor('home'));
}
};
};
$authenticated = function() use ($authenticationCheck) {
return $authenticationCheck(true);
};
$guest = function() use ($authenticationCheck) {
return $authenticationCheck(false);
};
$admin = function() use ($app) {
return function() use ($app) {
if (!$app->auth || !$app->auth->isAdmin()) {
$app->flash('global', 'You don\'t have permissions for that, man.');
$app->redirect($app->urlFor('home'));
}
};
};