本文整理汇总了PHP中Route::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::filter方法的具体用法?PHP Route::filter怎么用?PHP Route::filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Route
的用法示例。
在下文中一共展示了Route::filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['mobiledetect'] = $this->app->share(function ($app) {
return new \Mobile_Detect();
});
$this->app['facebook'] = $this->app->share(function ($app) {
return new Facebook();
});
\Route::filter('facebook-scope', 'L4FacebookToolsFilter');
}
示例2: routes
public function routes()
{
\Route::filter('NewsLetter', function () {
$permission = module("UserManagement");
if (!$permission->hasPermission('NewsLetter')) {
return \Redirect::route('dashboard');
}
});
Route::pattern('id', '[0-9]+');
$this->NewsLetter();
}
示例3: boot
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
// Add package
$this->package('leitom/role');
// Register the role manager filter
// This filter is used to trigger the protection of routes.
// It will also contain the auth before filter so that it does not have to
// be implemented at the same time.
\Route::filter($this->app['config']->get('role::role.control.identifier'), 'Leitom\\Role\\Filters\\Role');
// Bind the implementation for use in controllers
$this->app->bind('Leitom\\Role\\Contracts\\RoleRepositoryInterface', 'Leitom\\Role\\Repositories\\EloquentRoleRepository');
$this->app->bind('Leitom\\Role\\Contracts\\RouteRepositoryInterface', 'Leitom\\Role\\Repositories\\EloquentRouteRepository');
$this->app->bind('Leitom\\Role\\Contracts\\RouteScannerInterface', 'Leitom\\Role\\RouteScanner');
}
示例4: testPermissionsCanBeSetForRoutes
public function testPermissionsCanBeSetForRoutes()
{
$user = $this->createUserWithRoles();
\ACL::setUser($user);
$controller = Mockery::mock('\\ApiController');
$controller->shouldReceive('tests')->once()->andReturn(\Response::json(['success' => 'great']));
$controller->shouldReceive('getActionPermissions')->once()->andReturn(['tests' => 'job.apply']);
\Route::enableFilters();
\Route::filter('test.permissions.filter', function ($route) {
require 'app/acl.php';
$permissions = $route->getAction()['uses'][0]->getActionPermissions();
$perm = $permissions[$route->getAction()['uses'][1]];
$this->assertTrue(ACL::permits('job.apply', $route->parameters()));
});
\Route::get('/test/perms/{id}', [$controller, 'tests'])->after('test.permissions.filter');
$this->call('GET', '/test/perms/3');
$this->assertResponseOk();
}
示例5: function
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function () {
if (Session::token() != Input::get('_token')) {
throw new Illuminate\Session\TokenMismatchException();
}
});
Route::filter('checkInstalled', function ($route, $request) {
$installed = false;
try {
$installed = Setting::get('faxbox.installed', true);
} catch (PDOException $e) {
if ($request->getRequestUri() == '/install') {
return;
} else {
return Redirect::to('install');
}
}
if (!$installed && $request->getRequestUri() == '/install') {
return;
}
if (!$installed) {
return Redirect::to('install');
}
// If we've gotten here, then the app is installed. send them to the dashboard
if ($request->getRequestUri() == '/install' && $installed) {
return Redirect::route('home');
}
});
示例6: foreach
return Response::make('Unauthorized', 401);
}
return Redirect::guest('/');
}
$return = 0;
foreach (Auth::user()->groups as $group) {
foreach ($group->resources as $resource) {
if ($resource->pattern == "/" . Route::getCurrentRoute()->getPath()) {
$return = 1;
}
}
}
if ($return == 0) {
return Redirect::to('/profile');
} else {
return;
}
});
Route::filter("guest", function () {
if (Auth::check()) {
if (Route::getCurrentRoute()->getPath() == "login") {
return Redirect::route("user/profile");
}
//
}
});
Route::filter("csrf", function () {
if (Session::token() != Input::get("_token")) {
throw new Illuminate\Session\TokenMismatchException();
}
});
示例7: array
Route::get('/', array('as' => 'inicio', 'uses' => 'HomeController@getInicio'));
Route::get('/nosotros', array('as' => 'nosotros', 'uses' => 'HomeController@getNosotros'));
Route::get('/servicios', array('as' => 'servicios', 'uses' => 'HomeController@getServicios'));
Route::get('/galeria', array('as' => 'galeria', 'uses' => 'HomeController@getGaleria'));
Route::get('/transparencia', array('as' => 'transparencia', 'uses' => 'HomeController@getTransparencia'));
Route::get('/contacto', array('as' => 'contacto', 'uses' => 'HomeController@getContacto'));
Route::post('/contacto', array('as' => 'contacto', 'uses' => 'HomeController@postContacto'));
// rutas agrupadas para admin
// filtro para auth
Route::group(array('before' => 'auth.admin'), function () {
Route::get('/admin', array('as' => 'admin.index', 'uses' => 'AdminController@getIndex'));
Route::get('/admin/salir', array('as' => 'logout', 'uses' => 'AdminController@getLogOut'));
Route::get('/admin/perfil-usuario', array('as' => 'perfil', 'uses' => 'AdminController@getPerfil'));
Route::get('/admin/usuarios', array('as' => 'usuarios', 'uses' => 'AdminController@getUsuarios'));
Route::get('/admin/usuarios/nuevo', array('as' => 'usuariosNuevo', 'uses' => 'AdminController@getUsuariosNuevo'));
Route::post('/admin/usuarios/nuevo', array('uses' => 'AdminController@postUsuariosNuevo'));
Route::get('/admin/usuarios/editar/{id}', array('uses' => 'AdminController@getUsuariosEditar'));
Route::post('/admin/usuarios/editar', array('uses' => 'AdminController@postUsuariosEditar'));
Route::get('/admin/usuarios/bloquear/{id}', array('uses' => 'AdminController@getUsuariosBloquear'));
Route::get('/admin/usuarios/activar/{id}', array('uses' => 'AdminController@getUsuariosActivar'));
Route::get('/admin/listar-pedidos', array('as' => 'pedidos', 'uses' => 'PedidosController@getPedidos'));
Route::get('/admin/paginas/inicio', array('uses' => 'AdminController@getPaginasInicio'));
Route::get('/admin/importar-datos', array('as' => 'stock', 'uses' => 'ProductosController@getStock'));
Route::post('/admin/stock', array('uses' => 'ProductosController@postStock'));
});
// filtro auth
Route::filter('auth.admin', function () {
if (!Sentry::check()) {
return Redirect::route('login');
}
});
示例8: function
if (!$request->ajax()) {
return Redirect::guest('login');
} else {
return Response::make('Unauthorized Access', 403);
}
}
});
Route::filter('auth.basic', function () {
return Auth::basic();
});
Route::filter('guest', function ($route, $request) {
if (Auth::guest()) {
//
} else {
if (!$request->ajax()) {
return Redirect::guest('admin/dashboard');
} else {
return Response::make('Unauthorized Access', 403);
}
}
});
// Role-based Authorization Filter.
Route::filter('roles', function ($route, $request, $response, $roles = null) {
if (!is_null($roles) && Auth::check()) {
$user = Auth::user();
if (!$user->hasRole($roles)) {
$status = __('You are not authorized to access this resource.');
return Redirect::to('admin/dashboard')->withStatus($status, 'warning');
}
}
});
示例9: function
| Route::filter('filter', function()
| {
| return 'Filtered!';
| });
|
| Next, attach the filter to a route:
|
| Router::register('GET /', array('before' => 'filter', function()
| {
| return 'Hello World!';
| }));
|
*/
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 for User_Controller
Route::controller('user');
示例10: function
<?php
Route::filter('auth_check', function () {
// check method move to config file
if (Auth::guest()) {
$login_url = URL::to(Config::get('rpc::auth.login_path'), 'login');
return Redirect::to($login_url);
}
});
示例11: function
<?php
Route::filter('MultilinguaSwapFilter', function () {
$lista_lingue = L::get_lista();
$lingua = array_values(explode('/', Request::path()))[0];
if (in_array($lingua, array_keys($lista_lingue))) {
// if not blocked
if (!Session::get('noswap')) {
// updates the language
L::set($lingua);
L::updateLocale();
}
} else {
// not found
app::abort('404');
}
});
示例12: function
<?php
Route::filter('admin.auth', function () {
if (AdminAuth::guest()) {
if (Request::ajax()) {
return Response::make('Unauthorized', 401);
} else {
return Redirect::guest(Admin::instance()->router->routeToAuth('login'));
}
}
});
示例13: function
<?php
Route::filter('csrf-ajax', function () {
if (Session::token() != Request::header('x-csrf-token')) {
throw new Illuminate\Session\TokenMismatchException();
}
});
Route::get('/', 'IndexController@index');
Route::post('show', ['before' => 'csrf-ajax', 'as' => 'show', 'uses' => 'IndexController@show']);
Route::post('create', ['before' => 'csrf-ajax', 'as' => 'create', 'uses' => 'IndexController@create']);
Route::get('article/{id}/{title}', ['as' => 'read', 'uses' => 'IndexController@read']);
示例14: function
if (Auth::check()) {
return Redirect::to('/user/profile');
}
});
/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function () {
if (Session::token() !== Input::get('_token')) {
throw new Illuminate\Session\TokenMismatchException();
}
});
Route::filter('admin', function () {
if (Auth::guest()) {
if (Request::ajax()) {
return Response::make('Unauthorized', 401);
}
return Redirect::guest('user/login');
} else {
if (Auth::check() && Auth::user()->role != 1) {
return Redirect::to('/user/profile');
}
}
});
示例15: function
<?php
Route::filter('ulogin-guest', function () {
if (Auth::check()) {
$uri = Config::get('ulogin-laravel::config.redirect_after_login');
return Redirect::to($uri);
}
});