LoginHandler   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 41
rs 10
c 1
b 0
f 0
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B handle() 0 16 7
A signout() 0 5 1
A signin() 0 5 1
A redirect() 0 4 1
1
<?php
2
3
namespace App\Handlers;
4
5
use Pin\Libs\Session;
6
7
/**
8
 * LoginHandler
9
 * Handler para la autenticación
10
 */
11
class LoginHandler extends Handler
12
{
13
    public function handle(array $params = [])
14
    {
15
        $action = $_SERVER['REQUEST_METHOD'];
16
17
        if ($action === 'POST') {
18
            if (isset($params[0]) && $params[0] === 'signin') {
19
                $this->signin();
20
            } elseif (isset($params[0]) && $params[0] === 'signout') {
21
                $this->signout();
22
            }
23
        }
24
25
        if ($action === 'GET') {
26
            Session::set("is_logged_in", true);
27
            Session::set("flash", "Bienvenido!");
28
            $this->redirect("");
29
        }
30
    }
31
32
    
33
34
    private function signout()
35
    {
36
        Session::destroy();
37
        Session::set("flash", "Adios!");
38
        $this->redirect("");
39
    }
40
41
    private function signin()
42
    {
43
        Session::set("is_logged_in", true);
44
        Session::set("flash", "Bienvenido!");
45
        $this->redirect("");
46
    }
47
48
    private function redirect($path)
49
    {
50
        $url = PUBLIC_PATH . $path;
51
        header("Location: $url", true, 301);
52
    }
53
}
54