Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Auth\Middleware;
4
 
5
use Closure;
6
use Illuminate\Auth\AuthenticationException;
7
use Illuminate\Contracts\Auth\Factory as Auth;
8
use Illuminate\Contracts\Auth\Middleware\AuthenticatesRequests;
9
 
10
class Authenticate implements AuthenticatesRequests
11
{
12
    /**
13
     * The authentication factory instance.
14
     *
15
     * @var \Illuminate\Contracts\Auth\Factory
16
     */
17
    protected $auth;
18
 
19
    /**
20
     * Create a new middleware instance.
21
     *
22
     * @param  \Illuminate\Contracts\Auth\Factory  $auth
23
     * @return void
24
     */
25
    public function __construct(Auth $auth)
26
    {
27
        $this->auth = $auth;
28
    }
29
 
30
    /**
31
     * Handle an incoming request.
32
     *
33
     * @param  \Illuminate\Http\Request  $request
34
     * @param  \Closure  $next
35
     * @param  string[]  ...$guards
36
     * @return mixed
37
     *
38
     * @throws \Illuminate\Auth\AuthenticationException
39
     */
40
    public function handle($request, Closure $next, ...$guards)
41
    {
42
        $this->authenticate($request, $guards);
43
 
44
        return $next($request);
45
    }
46
 
47
    /**
48
     * Determine if the user is logged in to any of the given guards.
49
     *
50
     * @param  \Illuminate\Http\Request  $request
51
     * @param  array  $guards
52
     * @return void
53
     *
54
     * @throws \Illuminate\Auth\AuthenticationException
55
     */
56
    protected function authenticate($request, array $guards)
57
    {
58
        if (empty($guards)) {
59
            $guards = [null];
60
        }
61
 
62
        foreach ($guards as $guard) {
63
            if ($this->auth->guard($guard)->check()) {
64
                return $this->auth->shouldUse($guard);
65
            }
66
        }
67
 
68
        $this->unauthenticated($request, $guards);
69
    }
70
 
71
    /**
72
     * Handle an unauthenticated user.
73
     *
74
     * @param  \Illuminate\Http\Request  $request
75
     * @param  array  $guards
76
     * @return void
77
     *
78
     * @throws \Illuminate\Auth\AuthenticationException
79
     */
80
    protected function unauthenticated($request, array $guards)
81
    {
82
        throw new AuthenticationException(
83
            'Unauthenticated.', $guards, $this->redirectTo($request)
84
        );
85
    }
86
 
87
    /**
88
     * Get the path the user should be redirected to when they are not authenticated.
89
     *
90
     * @param  \Illuminate\Http\Request  $request
91
     * @return string|null
92
     */
93
    protected function redirectTo($request)
94
    {
95
        //
96
    }
97
}