Advertisement
Guest User

Untitled

a guest
Jan 10th, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.48 KB | None | 0 0
  1. <?php
  2.  
  3. Route::controller(Controller::detect());
  4. Route::get('/', function()
  5. {
  6.     #return View::of('layout')->nest('content', 'home.index');
  7.     return Redirect::to('home');
  8. });
  9.  
  10. Event::listen('404', function()
  11. {
  12.     return Response::error('404');
  13. });
  14.  
  15. Event::listen('500', function()
  16. {
  17.     return Response::error('500');
  18. });
  19.  
  20. Route::filter('before', function()
  21. {
  22.     // Do stuff before every request to your application...
  23. });
  24.  
  25. Route::filter('after', function($response)
  26. {
  27.     // Do stuff after every request to your application...
  28. });
  29.  
  30. Route::filter('csrf', function()
  31. {
  32.     if (Request::forged()) return Response::error('500');
  33. });
  34.  
  35. Route::filter('auth', function()
  36. {
  37.     if (Auth::guest()) return Redirect::to('login');
  38. });
  39.  
  40. Route::get('login', array('uses' => 'login@index'));
  41.  
  42. Route::post('login', function() {
  43.     //return "login form sent";
  44.  
  45.     //Get the person data from login
  46.     $credentials = array(
  47.         'username' => Input::get('username'),
  48.         'password' => Input::get('password')
  49.     );
  50.     if(Auth::attempt($credentials)):
  51.         //We are logged in and sending the user to home
  52.         return Redirect::to('admin');
  53.     else:
  54.         //Auth fail and we are sending user back so he can log in
  55.         return Redirect::to('login')
  56.             ->with('login_errors', true);
  57.     endif;
  58. });
  59.  
  60. //validate_admin filter
  61. Route::filter('validate_admin', function ()
  62. {
  63.     //get the admin check closure that should be supplied in the config
  64.     $authCheck = Config::get('administrator.auth_check');
  65.  
  66.     if (!$authCheck())
  67.     {
  68.         $loginUrl = URL::to(Config::get('administrator.login_path', 'user/login'));
  69.         $redirectKey = Config::get('administrator.login_redirect_key', 'redirect');
  70.         $redirectUri = URL::to_route('admin_dashboard');
  71.  
  72.         return Redirect::to($loginUrl)->with($redirectKey, $redirectUri);
  73.     }
  74. });
  75.  
  76. /**
  77.  * Admin Routes
  78.  */
  79. Route::group(array('before' => 'validate_admin'), function()
  80. {
  81.     Route::get('admin', array(
  82.         'as' => 'admin_dashboard',
  83.         'uses' => 'admin.dashboard@index',
  84.     ));
  85.  
  86.     Route::any('admin/images', array(
  87.         'as' => 'admin_images',
  88.         'uses' => 'admin.images@index',
  89.     ));
  90.  
  91.     Route::any('admin/images/id/(:any)', array(
  92.         'as' => 'admin_id_image',
  93.         'uses' => 'admin.images@id',
  94.     )); //doesn't work
  95.  
  96.     Route::get('admin/news', array(
  97.         'as' => 'admin_news',
  98.         'uses' => 'admin.news@index',
  99.     ));
  100.  
  101.     Route::get('admin/news/new', array(
  102.         'as' => 'admin_form_news',
  103.         'uses' => 'admin.news@new',
  104.     ));
  105. });
  106.  
  107. Route::get('logout', function() {
  108.     Auth::logout();
  109.     return Redirect::to('login');
  110. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement