Completed
Branch develop (82845d)
by Mohamed
03:11
created

Authenticate::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Http\Middleware;
13
14
use Closure;
15
use Illuminate\Contracts\Auth\Guard;
16
use Illuminate\Http\Request;
17
18
/**
19
 * Authenticate is a Middleware class to for checking if current user is logged in.
20
 *
21
 * @author Mohamed Alsharaf <[email protected]>
22
 */
23
class Authenticate extends MiddlewareAbstract
24
{
25
    /**
26
     * Handle an incoming request.
27
     *
28
     * @param Request  $request
29
     * @param \Closure $next
30
     *
31
     * @return mixed
32
     */
33
    public function handle(Request $request, Closure $next)
34
    {
35
        if ($this->auth->guest()) {
36
            if ($request->ajax()) {
37 57
                abort(401);
38
            }
39 57
40 57
            return redirect()->guest('/');
41
        }
42
43
        app()->setLocale($this->getLoggedUser()->language);
44
45
        return $next($request);
46
    }
47
}
48