InloggController::loggainActionPost()   B
last analyzed

Complexity

Conditions 7
Paths 5

Size

Total Lines 37
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 18
nc 5
nop 0
dl 0
loc 37
c 0
b 0
f 0
cc 7
rs 8.8333
1
<?php
2
3
namespace KW\Inlagg;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
class InloggController implements ContainerInjectableInterface
9
{
10
    use ContainerInjectableTrait;
11
12
    public function loggainActionPost()
13
    {
14
        $inloggaren     = new Inloggaren($this->di);
15
        $anvandarnamn   = $this->di->get("request")->getPost("anvandarnamn");
16
        $losen          = $this->di->get("request")->getPost("losen");
17
        $email          = $this->di->get("request")->getPost("email");
18
        $loggain        = $this->di->get("request")->getPost("loggain");
19
20
        //Att man vill logga in och inte skapa nytt
21
        if ($loggain != null) {
22
            //försök logga in
23
            $res = $inloggaren->loggain($anvandarnamn, $losen);
24
25
            //om felaktiga uppgifter matats in
26
            if (!$res) {
27
                return $this->di->get("response")->redirect("inlogg/felinlogg")->send(); //denna funkar inte
28
            } else {
29
                return $this->di->get("response")->redirect("minsida")->send();
30
            }
31
        }
32
33
        //ny användare  MD5
34
35
        //om användarnamnet upptaget
36
        if ($inloggaren->anvandarnamnUpptaget($anvandarnamn)) {
37
            return $this->di->get("response")->redirect("inlogg/finnsredan")->send();
38
        }
39
40
        if ($email=="" || $losen=="" || $anvandarnamn =="") {
41
            return $this->di->get("response")->redirect("inlogg/felaktigauppgifter")->send();
42
        }
43
44
        //skapa ny användare
45
        $inloggaren->skapaNyanvandare($anvandarnamn, $losen, $email);
46
        //logga in ny användare därefter
47
        $inloggaren->loggain($anvandarnamn, $losen);
48
        return $this->di->get("response")->redirect("minsida")->send();
49
    }
50
51
52
    public function felinloggActionGet()
53
    {
54
        $page = $this->di->get("page");
55
                $page->add("anax/v2/inlogg/felinlogg", [
56
                    ]);
57
                return $page->render([
58
                    "title"=>"Felinlogg"
59
                ]);
60
    }
61
62
    public function finnsredanActionGet()
63
    {
64
        $page = $this->di->get("page");
65
                $page->add("anax/v2/inlogg/finnsredan", [
66
                    ]);
67
                return $page->render([
68
                    "title"=>"Felinlogg"
69
                ]);
70
    }
71
72
    public function felaktigauppgifterActionGet()
73
    {
74
        $page = $this->di->get("page");
75
                $page->add("anax/v2/inlogg/felaktigauppgifter", [
76
                    ]);
77
                return $page->render([
78
                    "title"=>"Felaktiga uppgifter"
79
                ]);
80
    }
81
82
    public function loggautActionGet()
83
    {
84
        $this->di->session->destroy();
0 ignored issues
show
Bug introduced by
Accessing session on the interface Psr\Container\ContainerInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
85
        return $this->di->get("response")->redirect("")->send();
86
    }
87
}
88