StageFrontController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 64.71%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 7
dl 0
loc 47
ccs 11
cts 17
cp 0.6471
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 19 3
A store() 0 14 1
1
<?php
2
3
namespace CodeZero\StageFront\Controllers;
4
5
use CodeZero\StageFront\Rules\LoginAndPasswordMatch;
6
use Illuminate\Routing\Controller;
7
use Illuminate\Support\Facades\Config;
8
use Illuminate\Support\Facades\Lang;
9
use Illuminate\Support\Facades\Request;
10
use Illuminate\Support\Facades\Session;
11
12
class StageFrontController extends Controller
13
{
14
    /**
15
     * Show the StageFront login screen.
16
     *
17
     * @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse
18
     */
19 1
    public function create()
20
    {
21 1
        if (Session::get('stagefront.unlocked') === true) {
22 1
            return redirect('/');
23
        }
24
25
        $liveSite = Config::get('stagefront.live_site');
26
27
        if ($liveSite) {
28
            $liveSite = [
29
                'url' => $liveSite,
30
                'host' => parse_url($liveSite, PHP_URL_HOST),
31
            ];
32
        }
33
34
        Session::flash('url.intended', Session::previousUrl());
35
36
        return view('stagefront::login', compact('liveSite'));
37
    }
38
39
    /**
40
     * Attempt to log a user in to StageFront.
41
     *
42
     * @return \Illuminate\Http\RedirectResponse
43
     */
44 9
    public function store()
45
    {
46 9
        Request::validate([
47 9
            'login' => ['required'],
48 9
            'password' => ['required', new LoginAndPasswordMatch()],
49
        ], [
50 9
            'login.required' => Lang::get('stagefront::errors.login.required'),
51 9
            'password.required' => Lang::get('stagefront::errors.password.required'),
52
        ]);
53
54 6
        Session::put('stagefront.unlocked', true);
55
56 6
        return redirect()->intended('/');
57
    }
58
}
59