Completed
Push — master ( 10b5af...f94c01 )
by Patrick
06:53
created

SecureAPI::logout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
1
<?php
2
class SecureAPI extends Http\Rest\RestAPI
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
3
{
4
    public function setup($app)
5
    {
6
        $app->post('/login[/]', array($this, 'login'));
7
        $app->post('/logout[/]', array($this, 'logout'));
8
    }
9
10
    public function login($request, $response, $args)
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
11
    {
12
        $params = $request->getParams();
13
        if(!isset($params['username']) || !isset($params['password']))
14
        {
15
            return $response->withStatus(400);
16
        }
17
        $auth = AuthProvider::getInstance();
18
        $res = $auth->login($params['username'], $params['password']);
19
        if($res === false)
20
        {
21
            return $response->withStatus(403);
22
        }
23
        else
24
        {
25
            return $response->withJson($res);
26
        }
27
    }
28
29
    public function logout($request, $response, $args)
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        FlipSession::end();
32
        return $response->withJson(true);
33
    }
34
}
35
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
36