aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/terms.php
blob: 679a34774774e7b20ff40c69dd0451da03cf1341 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
 * show terms on first login and check if user accept them
 *
 * @author  Jan-Hendrik Willms <tleilax+studip@gmail.com>
 * @license GPL2 or any later version
 * @since   Stud.IP 4.2
 */
class TermsController extends AuthenticatedController
{
    public function before_filter(&$action, &$args)
    {
        parent::before_filter($action, $args);

        if ($GLOBALS['user']->cfg->TERMS_ACCEPTED) {
            $this->redirectUser();
        }
    }

    public function index_action()
    {
        PageLayout::setTitle(_('Nutzungsbedingungen'));

        $this->return_to = Request::get('return_to');
        $this->redirect_token = Request::get('redirect_token');

        $this->compulsory = Config::get()->TERMS_CONFIG['compulsory'];
        $this->denial_message = '';
        if (Request::isPost()) {
            CSRFProtection::verifyUnsafeRequest();
            if (Request::submitted('accept')) {
                $GLOBALS['user']->cfg->store('TERMS_ACCEPTED', 1);
                $this->redirectUser();
            } else {
                $_SESSION['logout_ticket'] = get_ticket();
                $this->redirectUser('logout.php');
            }
        } elseif (Request::get('action') === 'denied') {
            if (trim(Config::get()->TERMS_CONFIG['denial_message'])) {
                $this->denial_message = trim(Config::get()->TERMS_CONFIG['denial_message']);
            } else {
                $this->denial_message = sprintf(
                    _('Sie haben den Nutzungsbedingungen nicht zugestimmt und können '
                    . 'damit das System nicht nutzen. Bitte kontaktieren Sie Ihren '
                    . 'Support über folgende Adresse, um die nächsten Schritte '
                    . 'abzustimmen: %s'),
                    '<a href="mailto:' . $GLOBALS['UNI_CONTACT'] . '">' . $GLOBALS['UNI_CONTACT'] . '</a>'
                );
            }
        }
    }

    private function redirectUser($target = null)
    {
        if (Token::isValid(Request::option('redirect_token')) && Request::get('return_to')) {
            $target = Request::get('return_to') ;
        } else {
            $target = $target ?: 'dispatch.php/start';
        }
        $this->redirect(URLHelper::getURL($target));
    }
}