Passed
Push — main ( 131f20...c1d479 )
by Rafael
51:37
created

ConfigController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A doIndex() 0 13 3
A doLogin() 0 16 3
A doLogout() 0 4 1
A doSave() 0 4 1
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 Modules\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) {
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[] = 'Usuario o contraseña incorrectos';
53
            dump($this);
54
            return true;
55
        }
56
        $this->template = 'page/admin/info';
57
    }
58
59
    public function doLogout()
60
    {
61
        Auth::logout(true);
62
        return true;
63
    }
64
65
    public function doSave(): bool
66
    {
67
        dump($_POST);
68
        return false;
69
    }
70
}
71