Fully documented the filters

This commit is contained in:
Graham Campbell 2015-01-02 00:54:16 +00:00
parent deb4aae0d4
commit 4d6de70ba8
8 changed files with 93 additions and 6 deletions

View File

@ -9,6 +9,15 @@ use Symfony\Component\HttpFoundation\Response;
class AllowedDomainsFilter class AllowedDomainsFilter
{ {
/**
* Run the allowed domains filter.
*
* @param \Illuminate\Routing\Route $route
* @param \Illuminate\Http\Request $request
* @param \Symfony\Component\HttpFoundation\Response $response
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function filter(Route $route, Request $request, Response $response) public function filter(Route $route, Request $request, Response $response)
{ {
// Always allow our own domain. // Always allow our own domain.

View File

@ -8,6 +8,15 @@ use Symfony\Component\HttpFoundation\Response;
class CorsFilter class CorsFilter
{ {
/**
* Run the cors filter.
*
* @param \Illuminate\Routing\Route $route
* @param \Illuminate\Http\Request $request
* @param \Symfony\Component\HttpFoundation\Response $response
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function filter(Route $route, Request $request, Response $response) public function filter(Route $route, Request $request, Response $response)
{ {
$response->headers->set('Access-Control-Allow-Origin', '*'); $response->headers->set('Access-Control-Allow-Origin', '*');

View File

@ -10,6 +10,16 @@ use Illuminate\Support\Facades\Response;
class AuthFilter class AuthFilter
{ {
/**
* Run the auth filter.
*
* We're verifying that the current user is logged in to Cachet.
*
* @param \Illuminate\Routing\Route $route
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response|null
*/
public function filter(Route $route, Request $request) public function filter(Route $route, Request $request)
{ {
if (Auth::guest()) { if (Auth::guest()) {

View File

@ -8,6 +8,17 @@ use Illuminate\Support\Facades\Session;
class CsrfFilter class CsrfFilter
{ {
/**
* Run the csrf filter.
*
* We're protecting Cachet against cross-site request forgery attacks. If
* our csrf token in the session does not match the one given sent to us in
* this request, then we'll bail.
*
* @throws \Illuminate\Session\TokenMismatchException
*
* @return void
*/
public function filter() public function filter()
{ {
if (Session::token() !== Input::get('_token')) { if (Session::token() !== Input::get('_token')) {

View File

@ -7,6 +7,16 @@ use Illuminate\Support\Facades\Redirect;
class GuestFilter class GuestFilter
{ {
/**
* Run the guest filter.
*
* We're checking if the current user is logged in to Cachet, and if
* they're not, then we're redirecting them to the home page.
*
* @throws \Illuminate\Session\TokenMismatchException
*
* @return \Illuminate\Http\Response|null
*/
public function filter() public function filter()
{ {
if (Auth::check()) { if (Auth::check()) {

View File

@ -10,11 +10,24 @@ use Illuminate\Support\Facades\Redirect;
class HasSettingFilter class HasSettingFilter
{ {
/**
* Run the has setting filter.
*
* We're verifying that the given setting exists in our database. If it
* doesn't, then we're sending the user to the setup page so that they can
* complete the installation of Cachet on their server.
*
* @param \Illuminate\Routing\Route $route
* @param \Illuminate\Http\Request $request
* @param string $settingName
*
* @return \Illuminate\Http\Response|null
*/
public function filter(Route $route, Request $request, $settingName) public function filter(Route $route, Request $request, $settingName)
{ {
try { try {
$setting = Setting::where('name', $settingName)->first(); $setting = Setting::where('name', $settingName)->first();
if (!$setting->value) { if (!$setting || !$setting->value) {
return Redirect::to('setup'); return Redirect::to('setup');
} }
} catch (Exception $e) { } catch (Exception $e) {

View File

@ -10,11 +10,23 @@ use Illuminate\Support\Facades\Redirect;
class IsSetupFilter class IsSetupFilter
{ {
/**
* Run the is setup filter.
*
* We're verifying that Cachet is correctly setup. If it is, they we're
* sending the user to the dashboard so they can use Cachet.
*
* @param \Illuminate\Routing\Route $route
* @param \Illuminate\Http\Request $request
* @param string $settingName
*
* @return \Illuminate\Http\Response|null
*/
public function filter(Route $route, Request $request) public function filter(Route $route, Request $request)
{ {
try { try {
$setting = Setting::where('name', 'app_name')->first(); $setting = Setting::where('name', 'app_name')->first();
if ($setting->value) { if ($setting && $setting->value) {
return Redirect::to('/dashboard'); return Redirect::to('/dashboard');
} }
} catch (Exception $e) { } catch (Exception $e) {

View File

@ -9,13 +9,26 @@ use Illuminate\Support\Facades\Redirect;
class LoginThrottlingFilter class LoginThrottlingFilter
{ {
/**
* Run the login throttling filter.
*
* We're verifying that the user is not attempting to brute force Cachet's
* login system. If the user has reached the rate limit, then we're sending
* them away, otherwise, we do nothing, and allow them to continue.
*
* Note that this filter is not responsible for incrementing the hit count.
* Another part of Cachet will increment the hit count for the given route
* only if validation passes, and the user did not successfully login.
*
* @param \Illuminate\Routing\Route $route
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response|null
*/
public function filter(Route $route, Request $request) public function filter(Route $route, Request $request)
{ {
// check if we've reached the rate limit, but don't hit the throttle yet
// we can hit the throttle later on in the if validation passes
if (!Throttle::check($request, 10, 10)) { if (!Throttle::check($request, 10, 10)) {
return Redirect::back() return Redirect::back()->with('error', 'You have made too many login requests.');
->with('error', 'You have made too many login requests.');
} }
} }
} }