aboutsummaryrefslogtreecommitdiff
path: root/app/Http/Middleware/Authenticate.php
diff options
context:
space:
mode:
authorCamil Staps2016-09-04 23:30:15 +0200
committerCamil Staps2016-09-04 23:30:15 +0200
commitc61b156f1bd93ec4aadd8adc78523b42b0232918 (patch)
treecd9bcb6f889dcf554818246957bed54eb14c9fbe /app/Http/Middleware/Authenticate.php
parentUse blade templates (diff)
User creation and authentication
Diffstat (limited to 'app/Http/Middleware/Authenticate.php')
-rw-r--r--app/Http/Middleware/Authenticate.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php
new file mode 100644
index 0000000..6db8bb0
--- /dev/null
+++ b/app/Http/Middleware/Authenticate.php
@@ -0,0 +1,45 @@
+<?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);
+ }
+}