Completed
Push — master ( 10405b...259f27 )
by wen
13:10
created

Authenticate::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Sco\Admin\Http\Middleware;
4
5
use Closure;
6
use Auth;
7
use Sco\Admin\Exceptions\AuthenticationException;
8
9
class Authenticate
10
{
11
    public function __construct()
12
    {
13
    }
14
15
    /**
16
     * Handle an incoming request.
17
     *
18
     * @param  \Illuminate\Http\Request $request
19
     * @param  \Closure $next
20
     *
21
     * @return mixed
22
     * @throws \Sco\Admin\Exceptions\AuthenticationException
23
     */
24
    public function handle($request, Closure $next)
25
    {
26
        $this->authenticate();
27
28
        return $next($request);
29
    }
30
31
    /**
32
     * Determine if the user is logged in to any of the given guards.
33
     *
34
     * @return mixed
35
     * @throws \Sco\Admin\Exceptions\AuthenticationException
36
     */
37
    protected function authenticate()
38
    {
39
        if (Auth::check()) {
40
            return Auth::user();
41
        }
42
43
        throw new AuthenticationException();
44
    }
45
}
46