Added the project's files to the repo
This commit is contained in:
31
app/filters.php
Executable file
31
app/filters.php
Executable file
@ -0,0 +1,31 @@
|
||||
<?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'));
|
||||
}
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user