diff --git a/app/src/Controller/User/LoginUserAction.php b/app/src/Controller/User/LoginUserAction.php new file mode 100644 index 0000000..c3f41cb --- /dev/null +++ b/app/src/Controller/User/LoginUserAction.php @@ -0,0 +1,40 @@ +request->getParsedBody(); + + try { + $user = $this->userRepository->getFromEmail($credentials['email']); + } catch (EntityNotFoundException $e) { + $this->session->getFlash()->add('error', "Unable to login user."); + return $this->response->withStatus(400); + } + + if (!$this->auth->verify($credentials['password'], $user->getPassword())) { + $this->session->getFlash()->add('error', 'Unable to login.'); + return $this->response->withStatus(400); + } + + // start the session + $this->session->set('user', [ 'id' => $user->getId() ]); + return $this->response; + } +}