Completed
Pull Request — develop (#51)
by Patrick
02:38
created

SessionsAPI::validateIsAdmin()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
class SessionsAPI extends ProfilesAdminAPI
3
{
4
    public function setup($app)
5
    {
6
        $app->get('[/]', array($this, 'getSessions'));
7
        $app->delete('/{id}', array($this, 'endSession'));
8
    }
9
10
    public function getSessions($request, $response)
11
    {
12
        $this->validateIsAdmin($request);
13
        $sessions = FlipSession::getAllSessions();
14
        if($sessions !== false)
15
        {
16
            $count = count($sessions);
17
            $sid = session_id();
18
            for($i = 0; $i < $count; $i++)
19
            {
20
                if(strcasecmp($sessions[$i]['sid'], $sid) === 0)
21
                {
22
                    $sessions[$i]['current'] = true;
23
                }
24
            }
25
        }
26
        return $response->withJson($sessions);
27
    }
28
29
    public function endSession($request, $response, $args)
30
    {
31
        $this->validateIsAdmin($request);
32
        $ret = FlipSession::deleteSessionById($args['id']);
33
        return $response->withJson($ret);
34
    }
35
}
36
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
37