| Conditions | 3 |
| Paths | 2 |
| Total Lines | 59 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 59 | public function callbackSubmit() |
||
| 60 | { |
||
| 61 | // $this->form->addOutput( |
||
| 62 | // "Trying to login as: " |
||
| 63 | // . $this->form->value("user") |
||
| 64 | // . "<br>Password is kept a secret..." |
||
| 65 | // //. $this->form->value("password") |
||
| 66 | // ); |
||
| 67 | // |
||
| 68 | // // Remember values during resubmit, useful when failing (return false) |
||
| 69 | // // and asking the user to resubmit the form. |
||
| 70 | // $this->form->rememberValues(); |
||
| 71 | // |
||
| 72 | // return true; |
||
| 73 | |||
| 74 | $res = new User(); |
||
| 75 | // Get values from the submitted form |
||
| 76 | |||
| 77 | $acronym = $res->changeCharacter($this->form->value("user")); |
||
| 78 | $password = $res->changeCharacter($this->form->value("password")); |
||
| 79 | |||
| 80 | |||
| 81 | // Try to login |
||
| 82 | $db = $this->di->get("dbqb"); |
||
| 83 | $db->connect(); |
||
| 84 | $user = $db->select("password") |
||
| 85 | ->from("User") |
||
| 86 | ->where("acronym = ?") |
||
| 87 | ->execute([$acronym]) |
||
| 88 | ->fetch(); |
||
| 89 | |||
| 90 | // $user is null if user is not found |
||
| 91 | if (!$user || !password_verify($password, $user->password)) { |
||
| 92 | var_dump($acronym); |
||
| 93 | var_dump($password); |
||
| 94 | $this->form->rememberValues(); |
||
| 95 | $this->form->addOutput("User $acronym or password $password did not match."); |
||
| 96 | return false; |
||
| 97 | } |
||
| 98 | |||
| 99 | // $_SESSION["status"] = "Logga ut"; |
||
| 100 | // $_SESSION["status_url"] = "user/logout"; |
||
| 101 | $_SESSION["status"] = [ |
||
| 102 | "text" => "Profil", |
||
| 103 | "url" => "user/profile", |
||
| 104 | "title" => "Profil", |
||
| 105 | "submenu" => [ |
||
| 106 | "items" => [ |
||
| 107 | [ |
||
| 108 | "text" => "Logga ut", |
||
| 109 | "url" => "user/logout", |
||
| 110 | "title" => "Logga ut", |
||
| 111 | ], |
||
| 112 | ], |
||
| 113 | ], |
||
| 114 | ]; |
||
| 115 | $_SESSION["acronym"] = $acronym; |
||
| 116 | // $this->form->addOutput("User logged in."); |
||
| 117 | return true; |
||
| 118 | } |
||
| 120 |