Skip to content

Commit

Permalink
Replace TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
battis committed Oct 28, 2022
1 parent 2b3af20 commit 324537d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
1 change: 1 addition & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ build:
tests:
override:
- php-scrutinizer-run
# TODO enable tests (when created)
# tests-and-coverage:
# tests:
# override:
Expand Down
69 changes: 35 additions & 34 deletions src/Actions/HandleLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,43 @@

class HandleLogin
{
private $manager;
private $userRepository;
private $renderer;
private $usernameFieldName;
private $passwordFieldName;
private $manager;
private $userRepository;
private $renderer;
private $usernameFieldName;
private $passwordFieldName;

public function __construct(
Manager $manager,
UserRepositoryInterface $userRepository,
PhpRenderer $renderer,
string $usernameFieldName = "username",
string $passwordFiledName = "password"
public function __construct(
Manager $manager,
UserRepositoryInterface $userRepository,
PhpRenderer $renderer,
string $usernameFieldName = "username",
string $passwordFiledName = "password"
) {
$this->manager = $manager;
$this->userRepository = $userRepository;
$this->renderer = $renderer;
$this->usernameFieldName = $usernameFieldName;
$this->passwordFieldName = $passwordFiledName;
}

public function __invoke(ServerRequest $request, Response $response)
{
if (
($user = $this->userRepository->getUserEntityByUsername(
$request->getParsedBodyParam($this->usernameFieldName)
)) &&
$user->passwordVerify(
$request->getParsedBodyParam($this->passwordFieldName)
)
) {
$this->manager = $manager;
$this->userRepository = $userRepository;
$this->renderer = $renderer;
$this->usernameFieldName = $usernameFieldName;
$this->passwordFieldName = $passwordFiledName;
return $this->manager->startUserSession($user);
}

public function __invoke(ServerRequest $request, Response $response)
{
if (
($user = $this->userRepository->getUserEntityByUsername(
$request->getParsedBodyParam($this->usernameFieldName)
)) &&
$user->passwordVerify(
$request->getParsedBodyParam($this->passwordFieldName)
)
) {
return $this->manager->startUserSession($user);
}

return $this->renderer->render($response, "login.php", [
"message" => "bad credentials",
"message_type" => "error",
]);
}
// TODO add timeout
return $this->renderer->render($response, "login.php", [
"message" => "bad credentials",
"message_type" => "error",
]);
}
}

0 comments on commit 324537d

Please sign in to comment.