Add incredibly simple authentication to the app.
TODO: Manage feeds
This commit is contained in:
1 parent
49ac6f34bc
commit
2e07b29941
9 files changed
+197
-3
No files matched your search
@@ -30,6 +30,11 @@ class FeedController
|
||||
{
|
||||
$this->logger->info("FeedController::get_feed() called");
|
||||
$feed = $this->feedRepository->find($request->getAttribute('id'));
|
||||
|
||||
if (empty($feed)) {
|
||||
return $response->withStatus(404);
|
||||
}
|
||||
|
||||
$filtered = $feed->get_filtered_feed();
|
||||
|
||||
$body = $response->getBody();
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Lewisdale\App\Controllers;
|
||||
|
||||
use Lewisdale\App\Models\Repositories\UserRepository;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Slim\Views\Twig;
|
||||
|
||||
class LoginController {
|
||||
function __construct(
|
||||
private readonly Twig $view,
|
||||
private readonly UserRepository $users,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function index(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface {
|
||||
return $this->view->render($response, 'login/index.twig.html', []);
|
||||
}
|
||||
|
||||
public function login(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface {
|
||||
$body = $request->getParsedBody();
|
||||
$email = $body['email'];
|
||||
$password = $body['password'];
|
||||
|
||||
$user = $this->users->validateCredentials($email, $password);
|
||||
|
||||
if (!$user) {
|
||||
return $this->view->render($response, 'login/index.twig.html', ['error' => 'Invalid email or password']);
|
||||
}
|
||||
|
||||
$_SESSION['user'] = $user->id;
|
||||
|
||||
return $response->withStatus(302)->withHeader('Location', '/feed');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user