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

Authenticate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 2 Features 1
Metric Value
wmc 3
c 5
b 2
f 1
lcom 1
cbo 5
dl 0
loc 25
ccs 3
cts 3
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 3
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