From d7e113be4a56fa5aac3680fb5363168f545e5bce Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 16 Feb 2015 23:48:05 +0100 Subject: Added PHP API framework --- .../trunk/app/Http/Middleware/Authenticate.php | 50 ++++++++++++++++++++++ .../Http/Middleware/RedirectIfAuthenticated.php | 44 +++++++++++++++++++ .../trunk/app/Http/Middleware/VerifyCsrfToken.php | 20 +++++++++ 3 files changed, 114 insertions(+) create mode 100644 backyard/php-api/trunk/app/Http/Middleware/Authenticate.php create mode 100644 backyard/php-api/trunk/app/Http/Middleware/RedirectIfAuthenticated.php create mode 100644 backyard/php-api/trunk/app/Http/Middleware/VerifyCsrfToken.php (limited to 'backyard/php-api/trunk/app/Http/Middleware') diff --git a/backyard/php-api/trunk/app/Http/Middleware/Authenticate.php b/backyard/php-api/trunk/app/Http/Middleware/Authenticate.php new file mode 100644 index 0000000..72a7613 --- /dev/null +++ b/backyard/php-api/trunk/app/Http/Middleware/Authenticate.php @@ -0,0 +1,50 @@ +auth = $auth; + } + + /** + * Handle an incoming request. + * + * @param \Illuminate\Http\Request $request + * @param \Closure $next + * @return mixed + */ + public function handle($request, Closure $next) + { + if ($this->auth->guest()) + { + if ($request->ajax()) + { + return response('Unauthorized.', 401); + } + else + { + return redirect()->guest('auth/login'); + } + } + + return $next($request); + } + +} diff --git a/backyard/php-api/trunk/app/Http/Middleware/RedirectIfAuthenticated.php b/backyard/php-api/trunk/app/Http/Middleware/RedirectIfAuthenticated.php new file mode 100644 index 0000000..dd5a867 --- /dev/null +++ b/backyard/php-api/trunk/app/Http/Middleware/RedirectIfAuthenticated.php @@ -0,0 +1,44 @@ +auth = $auth; + } + + /** + * Handle an incoming request. + * + * @param \Illuminate\Http\Request $request + * @param \Closure $next + * @return mixed + */ + public function handle($request, Closure $next) + { + if ($this->auth->check()) + { + return new RedirectResponse(url('/home')); + } + + return $next($request); + } + +} diff --git a/backyard/php-api/trunk/app/Http/Middleware/VerifyCsrfToken.php b/backyard/php-api/trunk/app/Http/Middleware/VerifyCsrfToken.php new file mode 100644 index 0000000..750a39b --- /dev/null +++ b/backyard/php-api/trunk/app/Http/Middleware/VerifyCsrfToken.php @@ -0,0 +1,20 @@ +