Passed
Push — main ( 30e650...8f48f2 )
by Rafael
03:20
created

ConfigController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 23
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A doLogout() 0 4 1
A doSave() 0 6 1
A doLogin() 0 18 3
A doIndex() 0 13 3
1
<?php
2
3
/* Copyright (C) 2024       Rafael San José         <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace CoreModules\Admin\Controller;
20
21
use Alxarafe\Base\Controller\ViewController;
22
23
class ConfigController extends ViewController
24
{
25
26
    public function doIndex(): bool
27
    {
28
        /**
29
         * TODO: The value of this variable will be filled in when the roles
30
         *       are correctly implemented.
31
         */
32
        $restricted_access = false;
33
34
        $this->template = 'page/config';
35
        if (isset($this->config) && $restricted_access) {
0 ignored issues
show
introduced by
The condition $restricted_access is always false.
Loading history...
36
            $this->template = 'page/forbidden';
37
        }
38
        return true;
39
    }
40
41
    public function doLogin()
42
    {
43
        $this->template = 'page/admin/login';
44
        $login = filter_input(INPUT_POST, 'login');
45
        if (!$login) {
46
            return true;
47
        }
48
49
        $username = filter_input(INPUT_POST, 'username');
50
        $password = filter_input(INPUT_POST, 'password');
51
        if (!Auth::login($username, $password)) {
52
            $this->advice[] = $this->langs->trans('ErrorBadLoginPassword');
0 ignored issues
show
Bug introduced by
The property langs does not exist on CoreModules\Admin\Controller\ConfigController. Did you mean lang?
Loading history...
Bug Best Practice introduced by
The property advice does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
53
            dump([
0 ignored issues
show
Bug introduced by
The function dump was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
            /** @scrutinizer ignore-call */ 
54
            dump([
Loading history...
54
                'ConfigController' => $this
55
            ]);
56
            return true;
57
        }
58
        $this->template = 'page/admin/info';
59
    }
60
61
    public function doLogout()
62
    {
63
        Auth::logout(true);
64
        return true;
65
    }
66
67
    public function doSave(): bool
68
    {
69
        dump([
0 ignored issues
show
Bug introduced by
The function dump was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
        /** @scrutinizer ignore-call */ 
70
        dump([
Loading history...
70
            'ConfigController save' => $_POST,
71
        ]);
72
        return false;
73
    }
74
}
75