32 lines
		
	
	
		
			899 B
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			899 B
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
<?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'));
 | 
						|
		}
 | 
						|
	};
 | 
						|
};
 |