UserLoginForm::createUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Radchasay\User\HTMLForm;
4
5
use \Anax\HTMLForm\FormModel;
6
use \Anax\DI\DIInterface;
7
use \Radchasay\User\User;
8
9
/**
10
 * Example of FormModel implementation.
11
 */
12
class UserLoginForm extends FormModel
13
{
14
    /**
15
     * Constructor injects with DI container.
16
     *
17
     * @param Anax\DI\DIInterface $di a service container
18
     */
19
    public function __construct(DIInterface $di)
20
    {
21
        parent::__construct($di);
22
23
        $this->form->create(
24
            [
25
                "id"     => __CLASS__,
26
                "legend" => "User Login",
27
            ],
28
            [
29
                "email" => [
30
                    "type" => "email",
31
                    //"description" => "Here you can place a description.",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
32
                    //"placeholder" => "Here is a placeholder",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33
                ],
34
35
                "password" => [
36
                    "type" => "password",
37
                    //"description" => "Here you can place a description.",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38
                    //"placeholder" => "Here is a placeholder",
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39
                ],
40
41
                "submit" => [
42
                    "type"     => "submit",
43
                    "value"    => "Login",
44
                    "callback" => [$this, "callbackSubmit"],
45
                ],
46
47
                "create" => [
48
                    "type"     => "submit",
49
                    "value"    => "Create User",
50
                    "callback" => [$this, "createUser"],
51
                ],
52
            ]
53
        );
54
    }
55
56
57
    /**
58
     * Callback for submit-button which should return true if it could
59
     * carry out its work and false if something failed.
60
     *
61
     * @return boolean true if okey, false if something went wrong.
62
     */
63
    public function callbackSubmit()
64
    {
65
        // Get values from the submitted form
66
        $email = htmlentities($this->form->value("email"));
67
        $password = htmlentities($this->form->value("password"));
68
69
        $user = new User();
70
        $user->setDB($this->di->get("db"));
71
        $res = $user->verifyPassword($email, $password);
72
73
        if (!$res) {
74
            //$this->form->remeberValues();
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
            $this->form->addOutput("User or password did not match");
76
            return false;
77
        }
78
79
80
        $this->di->get("session")->set("email", $user->email);
81
        $url = $this->di->get("url")->create("user/profile");
82
        $this->di->get("response")->redirect($url);
83
        $this->form->addOutput("User " . $user->email . " logged in.");
84
        return true;
85
    }
86
87
    public function createUser()
88
    {
89
        $this->di->get("session")->set("create", "true");
90
        $url = $this->di->get("url")->create("user/create");
91
        $this->di->get("response")->redirect($url);
92
    }
93
}
94