Issues (1868)

public/main/auth/tc.php (1 issue)

Severity
1
<?php
2
require_once __DIR__.'/../inc/global.inc.php';
3
4
use Chamilo\CoreBundle\Framework\Container;
5
use Chamilo\CoreBundle\Helpers\ChamiloHelper;
6
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
7
use ChamiloSession as Session;
8
9
$return = $_POST['return'] ?? $_GET['return'] ?? '/home';
10
11
if ($_SERVER['REQUEST_METHOD'] === 'POST'
12
    && !empty($_POST['legal_accept_type'])
13
    && (
14
        isset($_POST['legal_accept'])
15
        || api_get_setting('registration.hide_legal_accept_checkbox') === 'true'
16
    )
17
) {
18
    $userId = 0;
19
    $termData = Session::read('term_and_condition');
20
    if (!empty($termData['user_id'])) {
21
        $userId = (int)$termData['user_id'];
22
    } else {
23
        $userId = api_get_user_id();
24
    }
25
26
    if ($userId > 0) {
27
        ChamiloHelper::saveUserTermsAcceptance($userId, $_POST['legal_accept_type']);
28
29
        // Re-login in Symfony security
30
        $userEntity = api_get_user_entity($userId);
31
        if ($userEntity) {
32
            $token = new UsernamePasswordToken(
33
                $userEntity,
34
                'main',
35
                $userEntity->getRoles()
36
            );
37
38
            $tokenStorage = Container::getTokenStorage();
39
            $tokenStorage->setToken($token);
40
41
            // Save the token to session so the firewall recognizes it on the next request
42
            $session = Container::getSession();
43
            if ($session) {
0 ignored issues
show
$session is of type Symfony\Component\HttpFoundation\Session\Session, thus it always evaluated to true.
Loading history...
44
                $session->set('_security_main', serialize($token));
45
            }
46
        }
47
48
        Session::write('term_and_condition', null);
49
50
        ChamiloHelper::redirectTo($return);
51
    } else {
52
        die('Error: Unable to identify user accepting terms.');
53
    }
54
}
55
56
ChamiloHelper::displayLegalTermsPage($return);
57