aboutsummaryrefslogtreecommitdiff
path: root/app/Http/Middleware
diff options
context:
space:
mode:
authorCamil Staps2016-09-25 23:56:46 +0200
committerCamil Staps2016-09-26 01:02:05 +0200
commit33ad0c14d168d36a4e7ad42dc6aa6a37a7335849 (patch)
tree0543b7d92f7f0b7706f4313ba10b18483f747798 /app/Http/Middleware
parentAdded unique visitors to statistics (diff)
Change from lumen 5.2 to laravel 5.3 (Resolves #1)
Diffstat (limited to 'app/Http/Middleware')
-rw-r--r--app/Http/Middleware/Authenticate.php45
-rw-r--r--app/Http/Middleware/EncryptCookies.php17
-rw-r--r--app/Http/Middleware/Login.php34
-rw-r--r--app/Http/Middleware/RedirectIfAuthenticated.php (renamed from app/Http/Middleware/ExampleMiddleware.php)10
-rw-r--r--app/Http/Middleware/VerifyCsrfToken.php17
5 files changed, 42 insertions, 81 deletions
diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php
deleted file mode 100644
index 6db8bb0..0000000
--- a/app/Http/Middleware/Authenticate.php
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-
-namespace App\Http\Middleware;
-
-use Closure;
-use Illuminate\Contracts\Auth\Factory as Auth;
-
-class Authenticate
-{
- /**
- * The authentication guard factory instance.
- *
- * @var \Illuminate\Contracts\Auth\Factory
- */
- protected $auth;
-
- /**
- * Create a new middleware instance.
- *
- * @param \Illuminate\Contracts\Auth\Factory $auth
- * @return void
- */
- public function __construct(Auth $auth)
- {
- $this->auth = $auth;
- }
-
- /**
- * Handle an incoming request.
- *
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
- * @param string|null $guard
- * @return mixed
- */
- public function handle($request, Closure $next, $guard = null)
- {
- if ($this->auth->guard($guard)->guest()) {
- return response('Unauthorized.', 401)
- ->header('WWW-Authenticate', 'Basic realm="Please enter your email and password"');
- }
-
- return $next($request);
- }
-}
diff --git a/app/Http/Middleware/EncryptCookies.php b/app/Http/Middleware/EncryptCookies.php
new file mode 100644
index 0000000..3aa15f8
--- /dev/null
+++ b/app/Http/Middleware/EncryptCookies.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Illuminate\Cookie\Middleware\EncryptCookies as BaseEncrypter;
+
+class EncryptCookies extends BaseEncrypter
+{
+ /**
+ * The names of the cookies that should not be encrypted.
+ *
+ * @var array
+ */
+ protected $except = [
+ //
+ ];
+}
diff --git a/app/Http/Middleware/Login.php b/app/Http/Middleware/Login.php
deleted file mode 100644
index 8a71104..0000000
--- a/app/Http/Middleware/Login.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-
-namespace App\Http\Middleware;
-
-use Closure;
-use Illuminate\Support\Facades\Auth;
-
-class Login {
- /**
- * Create a new middleware instance.
- *
- * @param \Illuminate\Contracts\Auth\Factory $auth
- * @return void
- */
- public function __construct() {
- }
-
- /**
- * Handle an incoming request.
- *
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
- * @param string|null $guard
- * @return mixed
- */
- public function handle($request, Closure $next, $guard = null) {
- if ($request->has('login') && !Auth::check()) {
- return response('Unauthorized.', 401)
- ->header('WWW-Authenticate', 'Basic realm="Please enter your email and password"');
- }
-
- return $next($request);
- }
-}
diff --git a/app/Http/Middleware/ExampleMiddleware.php b/app/Http/Middleware/RedirectIfAuthenticated.php
index 166581c..e27860e 100644
--- a/app/Http/Middleware/ExampleMiddleware.php
+++ b/app/Http/Middleware/RedirectIfAuthenticated.php
@@ -3,18 +3,24 @@
namespace App\Http\Middleware;
use Closure;
+use Illuminate\Support\Facades\Auth;
-class ExampleMiddleware
+class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
+ * @param string|null $guard
* @return mixed
*/
- public function handle($request, Closure $next)
+ public function handle($request, Closure $next, $guard = null)
{
+ if (Auth::guard($guard)->check()) {
+ return redirect('/');
+ }
+
return $next($request);
}
}
diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php
new file mode 100644
index 0000000..a2c3541
--- /dev/null
+++ b/app/Http/Middleware/VerifyCsrfToken.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
+
+class VerifyCsrfToken extends BaseVerifier
+{
+ /**
+ * The URIs that should be excluded from CSRF verification.
+ *
+ * @var array
+ */
+ protected $except = [
+ //
+ ];
+}