Passed
Push — master ( 221005...26261c )
by Rubén
03:12
created

SimpleControllerBase::handleSessionTimeout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * sysPass
4
 *
5
 * @author    nuxsmin
6
 * @link      https://syspass.org
7
 * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
8
 *
9
 * This file is part of sysPass.
10
 *
11
 * sysPass is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * sysPass is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 *  along with sysPass.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace SP\Modules\Web\Controllers;
26
27
use DI\Container;
28
use Psr\Container\ContainerInterface;
29
use SP\Core\Acl\UnauthorizedPageException;
30
use SP\Core\Exceptions\SessionTimeout;
31
use SP\Modules\Web\Controllers\Traits\WebControllerTrait;
32
33
/**
34
 * Class SimpleControllerBase
35
 *
36
 * @package SP\Modules\Web\Controllers
37
 */
38
abstract class SimpleControllerBase
39
{
40
    use WebControllerTrait;
41
42
    /**
43
     * @var ContainerInterface
44
     */
45
    protected $dic;
46
    /**
47
     * @var string
48
     */
49
    protected $previousSk;
50
51
    /**
52
     * SimpleControllerBase constructor.
53
     *
54
     * @param Container $container
55
     * @param           $actionName
56
     *
57
     * @throws SessionTimeout
58
     */
59
    public function __construct(Container $container, $actionName)
60
    {
61
        $this->dic = $container;
62
        $this->actionName = $actionName;
63
64
        $this->setUp($container);
65
66
        $this->previousSk = $this->session->getSecurityKey();
67
68
        try {
69
            $this->initialize();
70
        } catch (SessionTimeout $sessionTimeout) {
71
            $this->handleSessionTimeout();
72
73
            throw $sessionTimeout;
74
        }
75
    }
76
77
    /**
78
     * @return void
79
     */
80
    protected abstract function initialize();
81
82
    /**
83
     * @return void
84
     */
85
    public function handleSessionTimeout()
86
    {
87
        $this->sessionLogout(
88
            $this->request,
89
            $this->configData,
90
            function ($redirect) {
91
                $this->router->response()
92
                    ->redirect($redirect)
93
                    ->send(true);
94
            }
95
        );
96
    }
97
98
    /**
99
     * Comprobaciones
100
     *
101
     * @throws SessionTimeout
102
     */
103
    protected function checks()
104
    {
105
        if ($this->session->isLoggedIn() === false
106
            || $this->session->getAuthCompleted() !== true
107
        ) {
108
            throw new SessionTimeout();
109
        }
110
111
//        $this->checkSecurityToken($this->session, $this->request);
112
    }
113
114
    /**
115
     * Comprobar si está permitido el acceso al módulo/página.
116
     *
117
     * @param null $action La acción a comprobar
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $action is correct as it would always require null to be passed?
Loading history...
118
     *
119
     * @throws UnauthorizedPageException
120
     */
121
    protected function checkAccess($action)
122
    {
123
        if (!$this->session->getUserData()->getIsAdminApp()
124
            && !$this->acl->checkUserAccess($action)
125
        ) {
126
            throw new UnauthorizedPageException(UnauthorizedPageException::INFO);
127
        }
128
    }
129
}