aboutsummaryrefslogtreecommitdiff
path: root/routes/logout.php
blob: 07290618a948a34865cfee965f89ba929e1f4d82 (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
<?php

function nextTarget(array $config) {
    if (isset($_GET['next']) && Psso\isValidRedirect($_GET['next'], $config)) {
        return $_GET['next'];
    }
    return '/';
}

function GET(array $config) {
    $session = Psso\Session::get();
    if ($session->getIdentity() === null) {
        // not actually logged in anyway
        header('Location: ' . nextTarget($config));
        return;
    }

    $resp = new Psso\XMLResponse;
    $resp->doc->addAttribute('title', L('logout.title'));
    $resp->doc->addAttribute('kind', 'challenges');
    $form = $resp->doc->addChild('form');
    $form->addChild('p', L('logout.warning'));
    $form->addAttribute('method', 'post');
    $form->addChild('button', L('logout.confirm'));
    $resp->send();
}

function POST(array $config) {
    $session = Psso\Session::get();
    $session->setIdentity(null);
    header('Location: ' . nextTarget($config));
}