Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- Route::controller('home');
- Route::get('/', function()
- {
- return Redirect::to('home');
- });
- Event::listen('404', function()
- {
- return Response::error('404');
- });
- Event::listen('500', function()
- {
- return Response::error('500');
- });
- Route::filter('before', function()
- {
- // Do stuff before every request to your application...
- });
- Route::filter('after', function($response)
- {
- // Do stuff after every request to your application...
- });
- Route::filter('csrf', function()
- {
- if (Request::forged()) return Response::error('500');
- });
- Route::filter('auth', function()
- {
- if (Auth::guest()) return Redirect::to('login');
- });
- Route::get('login', array('uses' => 'login@index'));
- Route::post('login', function() {
- //return "login form sent";
- //Get the person data from login
- $credentials = array(
- 'username' => Input::get('username'),
- 'password' => Input::get('password')
- );
- if(Auth::attempt($credentials)):
- //We are logged in and sending the user to home
- return Redirect::to('admin');
- else:
- //Auth fail and we are sending user back so he can log in
- return Redirect::to('login')
- ->with('login_errors', true);
- endif;
- });
- use Admin\Libraries\ModelHelper;
- //validate_admin filter
- Route::filter('validate_admin', function ()
- {
- //get the admin check closure that should be supplied in the config
- $authCheck = Config::get('administrator.auth_check');
- if (!$authCheck())
- {
- $loginUrl = URL::to(Config::get('administrator.login_path', 'user/login'));
- $redirectKey = Config::get('administrator.login_redirect_key', 'redirect');
- $redirectUri = URL::to_route('admin_dashboard');
- return Redirect::to($loginUrl)->with($redirectKey, $redirectUri);
- }
- });
- //validate_model filter
- Route::filter('validate_model', function ()
- {
- $modelName = URI::segment(2);
- $model = ModelHelper::getModelInstance($modelName);
- //if the model doesn't exist at all, redirect to 404
- if (!$model)
- {
- return Response::error('404');
- }
- //if the model does exist, check if this user has permission to access it
- if (!ModelHelper::checkPermission($modelName))
- {
- Redirect::to_route('admin_dashboard');
- }
- });
- /**
- * Admin Routes
- */
- Route::get('admin', array(
- 'as' => 'admin_dashboard',
- 'uses' => 'admin@dashboard',
- 'before' => 'validate_admin', //only needs to validate admin and add assets
- ));
- //The route group for all other requests needs to validate admin, model, and add assets
- Route::group(array('before' => 'validate_admin|validate_model'), function()
- {
- //Model Index
- Route::get('admin/(:any)', array(
- 'as' => 'admin_index',
- 'uses' => 'admin@index'
- ));
- //Get Item
- Route::get('admin/(:any)/(:num)', array(
- 'as' => 'admin_get_item',
- 'uses' => 'admin@item'
- ));
- //New Item
- Route::get('admin/(:any)/new', array(
- 'as' => 'admin_new_item',
- 'uses' => 'admin@item'
- ));
- //Upload Item
- Route::any('admin/(:any)/upload', array(
- 'as' => 'admin_upload_item',
- 'uses' => 'admin@upload'
- ));
- //Model Images
- Route::get('admin/(:any)', array(
- 'as' => 'admin_images_manager',
- 'uses' => 'admin@images_manager'
- ));
- //Search Relationship Items
- Route::get('admin/(:any)/search_relation/(:any)/(:any)', array(
- 'as' => 'admin_search_relation',
- 'uses' => 'admin@search_relation'
- ));
- //CSRF protection in forms
- Route::group(array('before' => 'csrf'), function()
- {
- //Save Item
- Route::post('admin/(:any)/(:num?)/(:num?)/save', array(
- 'as' => 'admin_save_item',
- 'uses' => 'admin@save'
- ));
- //Delete Item
- Route::post('admin/(:any)/(:num)/delete', array(
- 'as' => 'admin_delete_item',
- 'uses' => 'admin@delete'
- ));
- //Get results
- Route::post('admin/(:any)/results', array(
- 'as' => 'admin_get_results',
- 'uses' => 'admin@results'
- ));
- });
- });
- Route::get('logout', function() {
- Auth::logout();
- return Redirect::to('login');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement