Compare commits
8
Commits
1fc58b8c0c
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e06d5587f | ||
|
|
cee4f9944e | ||
|
|
5c8892e12f | ||
|
|
2e07b29941 | ||
|
|
49ac6f34bc | ||
|
|
918e435c59 | ||
|
|
ab74bddf09 | ||
|
|
79b3de19b9 |
No files matched your search
+2
-1
@@ -15,7 +15,8 @@ require_once __DIR__ . '/../src/dependencies.php';
|
|||||||
global $container;
|
global $container;
|
||||||
|
|
||||||
$commands = [
|
$commands = [
|
||||||
$container->get(TestFeed::class),
|
$container->get(TestFeed::class),
|
||||||
|
$container->get(\Lewisdale\App\Tools\Console\CreateUser::class),
|
||||||
];
|
];
|
||||||
|
|
||||||
ConsoleRunner::run(
|
ConsoleRunner::run(
|
||||||
|
|||||||
+2
-1
@@ -24,7 +24,8 @@
|
|||||||
"ext-simplexml": "*",
|
"ext-simplexml": "*",
|
||||||
"ext-curl": "*",
|
"ext-curl": "*",
|
||||||
"ext-dom": "*",
|
"ext-dom": "*",
|
||||||
"php": ">=8.3"
|
"php": ">=8.3",
|
||||||
|
"doctrine/migrations": "^3.8"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^10.0"
|
"phpunit/phpunit": "^10.0"
|
||||||
|
|||||||
Generated
+800
-622
File diff suppressed because it is too large.
Load diff
@@ -15,8 +15,8 @@ services:
|
|||||||
expose:
|
expose:
|
||||||
- 5432
|
- 5432
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: ${SERVICE_USER_POSTGRES}
|
||||||
POSTGRES_PASSWORD: password
|
POSTGRES_PASSWORD: ${SERVICE_PASSWORD_POSTGRES}
|
||||||
POSTGRES_DB: baleen
|
POSTGRES_DB: baleen
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "pg_isready", "-d", "baleen"]
|
test: ["CMD-SHELL", "pg_isready", "-d", "baleen"]
|
||||||
@@ -35,7 +35,7 @@ services:
|
|||||||
- ./views:/var/www/html/views
|
- ./views:/var/www/html/views
|
||||||
- ./bin:/var/www/html/bin
|
- ./bin:/var/www/html/bin
|
||||||
environment:
|
environment:
|
||||||
DB_CONNECTION: postgres://postgres:password@postgres:5432/baleen
|
DB_CONNECTION: postgres://${SERVICE_USER_POSTGRES}:${SERVICE_PASSWORD_POSTGRES}@postgres:5432/baleen
|
||||||
entrypoint: sh -c "php bin/doctrine orm:schema-tool:update --complete --force && php-fpm"
|
entrypoint: sh -c "php bin/doctrine orm:schema-tool:update --complete --force && php-fpm"
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
postgres:
|
||||||
@@ -5,6 +5,11 @@ declare(strict_types=1);
|
|||||||
namespace Lewisdale\App\Controllers;
|
namespace Lewisdale\App\Controllers;
|
||||||
|
|
||||||
use Doctrine\Persistence\ObjectRepository;
|
use Doctrine\Persistence\ObjectRepository;
|
||||||
|
use Lewisdale\App\Models\Data\Feed;
|
||||||
|
use Lewisdale\App\Models\Data\FeedFilter;
|
||||||
|
use Lewisdale\App\Models\Data\FilterTarget;
|
||||||
|
use Lewisdale\App\Models\Data\FilterType;
|
||||||
|
use Lewisdale\App\Models\Repositories\FeedFilterRepository;
|
||||||
use Lewisdale\App\Models\Repositories\FeedRepository;
|
use Lewisdale\App\Models\Repositories\FeedRepository;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
@@ -16,20 +21,26 @@ class FeedController
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Twig $view,
|
private readonly Twig $view,
|
||||||
private readonly LoggerInterface $logger,
|
private readonly LoggerInterface $logger,
|
||||||
private readonly FeedRepository $feedRepository
|
private readonly FeedRepository $feedRepository,
|
||||||
|
private readonly FeedFilterRepository $feedFilterRepository,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function get(ServerRequestInterface $request, ResponseInterface $response)
|
public function get(ServerRequestInterface $request, ResponseInterface $response)
|
||||||
{
|
{
|
||||||
$this->logger->info("FeedController::get() called");
|
$this->logger->info("FeedController::get() called");
|
||||||
$feeds = $this->feedRepository->findBy([], ['title' => 'ASC']);
|
$feeds = $this->feedRepository->findBy([], ['title' => 'ASC']);
|
||||||
return $this->view->render($response, 'index.twig.html', ['feeds' => $feeds]);
|
return $this->view->render($response, 'feed/index.twig.html', ['feeds' => $feeds]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_feed(ServerRequestInterface $request, ResponseInterface $response)
|
public function get_feed(ServerRequestInterface $request, ResponseInterface $response)
|
||||||
{
|
{
|
||||||
$this->logger->info("FeedController::get_feed() called");
|
$this->logger->info("FeedController::get_feed() called");
|
||||||
$feed = $this->feedRepository->find($request->getAttribute('id'));
|
$feed = $this->feedRepository->find($request->getAttribute('id'));
|
||||||
|
|
||||||
|
if (empty($feed)) {
|
||||||
|
return $response->withStatus(404);
|
||||||
|
}
|
||||||
|
|
||||||
$filtered = $feed->get_filtered_feed();
|
$filtered = $feed->get_filtered_feed();
|
||||||
|
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
@@ -45,8 +56,58 @@ class FeedController
|
|||||||
public function create(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
public function create(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||||
{
|
{
|
||||||
$this->logger->info("FeedController::create() called");
|
$this->logger->info("FeedController::create() called");
|
||||||
|
|
||||||
|
$feed = $this->feedRepository->find($request->getAttribute('id'));
|
||||||
|
|
||||||
|
return $this->view->render($response, 'feed/edit.twig.html', ['FilterTypes' => FilterType::cases(), 'FilterTargets' => FilterTarget::cases(), 'feed' => $feed ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||||
|
{
|
||||||
|
$this->logger->info("FeedController::save() called");
|
||||||
|
|
||||||
$body = $request->getParsedBody();
|
$body = $request->getParsedBody();
|
||||||
|
|
||||||
return $this->view->render($response, 'create.twig.html');
|
$id = $request->getAttribute('id');
|
||||||
|
|
||||||
|
$feed = $id ? $this->feedRepository->find($request->getAttribute('id')) : new Feed();
|
||||||
|
|
||||||
|
$feed->title = $body['title'];
|
||||||
|
$feed->url = $body['url'];
|
||||||
|
|
||||||
|
$this->feedRepository->save($feed);
|
||||||
|
|
||||||
|
foreach ($body['feedFilters'] as $filter) {
|
||||||
|
$this->logger->info("Creating filter", ['filter' => $filter, 'post' => $_POST]);
|
||||||
|
|
||||||
|
$f = $filter['id'] ? $this->feedFilterRepository->find($filter['id']) : new FeedFilter(
|
||||||
|
FilterTarget::from($filter['target']),
|
||||||
|
FilterType::from($filter['type']),
|
||||||
|
$filter['value'],
|
||||||
|
$feed
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($f !== null && $filter['id']) {
|
||||||
|
$f->filter = FilterType::from($filter['type']);
|
||||||
|
$f->target = FilterTarget::from($filter['target']);
|
||||||
|
$f->value = $filter['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->feedFilterRepository->save($f);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response->withStatus(302)->withHeader('Location', "/feed");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||||
|
{
|
||||||
|
$this->logger->info("FeedController::delete() called");
|
||||||
|
$feed = $this->feedRepository->find($request->getAttribute('id'));
|
||||||
|
if (empty($feed)) {
|
||||||
|
return $response->withStatus(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->feedRepository->delete($feed);
|
||||||
|
return $response->withStatus(302)->withHeader('Location', '/feed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ use Psr\Http\Message\ServerRequestInterface;
|
|||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Slim\Views\Twig;
|
use Slim\Views\Twig;
|
||||||
|
|
||||||
class SampleController
|
class HomeController
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Twig $view,
|
private readonly Twig $view,
|
||||||
@@ -17,7 +17,7 @@ class SampleController
|
|||||||
|
|
||||||
public function get(ServerRequestInterface $request, ResponseInterface $response)
|
public function get(ServerRequestInterface $request, ResponseInterface $response)
|
||||||
{
|
{
|
||||||
$this->logger->info("SampleController::get() called");
|
$this->logger->info("HomeController::get() called");
|
||||||
return $this->view->render($response, 'index.twig.html');
|
return $this->view->render($response, 'index.twig.html');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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, 'account/login.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, 'account/login.twig.html', ['error' => 'Invalid email or password']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$_SESSION['user'] = $user->id;
|
||||||
|
|
||||||
|
return $response->withStatus(302)->withHeader('Location', '/feed');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,6 +48,10 @@ class Feed
|
|||||||
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE, nullable: true)]
|
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE, nullable: true)]
|
||||||
public \DateTimeInterface|null $lastFetched;
|
public \DateTimeInterface|null $lastFetched;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: User::class, cascade: ['persist', 'remove'], inversedBy: 'feeds')]
|
||||||
|
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id')]
|
||||||
|
public User|null $user;
|
||||||
|
|
||||||
public function fetch(): void
|
public function fetch(): void
|
||||||
{
|
{
|
||||||
if (Robots::allowed($this->url)) {
|
if (Robots::allowed($this->url)) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Lewisdale\App\Models\Data;
|
namespace Lewisdale\App\Models\Data;
|
||||||
|
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Lewisdale\App\Models\Traits\AutoUpdate;
|
use Lewisdale\App\Models\Traits\AutoUpdate;
|
||||||
use Lewisdale\App\Models\View;
|
use Lewisdale\App\Models\View;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
@@ -18,7 +19,7 @@ class User
|
|||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\Column(type: 'integer')]
|
#[ORM\Column(type: 'integer')]
|
||||||
#[ORM\GeneratedValue]
|
#[ORM\GeneratedValue]
|
||||||
private ?int $id;
|
public ?int $id;
|
||||||
#[ORM\Column(type: 'string')]
|
#[ORM\Column(type: 'string')]
|
||||||
private string $password;
|
private string $password;
|
||||||
#[ORM\Column(type: 'string')]
|
#[ORM\Column(type: 'string')]
|
||||||
@@ -26,6 +27,12 @@ class User
|
|||||||
#[ORM\Column(type: 'string')]
|
#[ORM\Column(type: 'string')]
|
||||||
private string $salt;
|
private string $salt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Collection<Feed>
|
||||||
|
*/
|
||||||
|
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Feed::class, cascade: ['persist', 'remove'])]
|
||||||
|
public Collection $feeds;
|
||||||
|
|
||||||
function __construct(
|
function __construct(
|
||||||
string $password,
|
string $password,
|
||||||
string $email,
|
string $email,
|
||||||
|
|||||||
@@ -15,4 +15,10 @@ class FeedFilterRepository extends EntityRepository
|
|||||||
{
|
{
|
||||||
parent::__construct($em, $em->getClassMetadata(FeedFilter::class));
|
parent::__construct($em, $em->getClassMetadata(FeedFilter::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function save(FeedFilter $filter): void
|
||||||
|
{
|
||||||
|
$this->getEntityManager()->persist($filter);
|
||||||
|
$this->getEntityManager()->flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,4 +21,10 @@ class FeedRepository extends EntityRepository
|
|||||||
$this->_em->persist($feed);
|
$this->_em->persist($feed);
|
||||||
$this->_em->flush();
|
$this->_em->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function delete(Feed $feed): void
|
||||||
|
{
|
||||||
|
$this->_em->remove($feed);
|
||||||
|
$this->_em->flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
|
namespace Lewisdale\App\Models\Repositories;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
use Lewisdale\App\Models\Data\User;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use function DI\string;
|
||||||
|
|
||||||
|
/** @extends EntityRepository<User> */
|
||||||
|
class UserRepository extends EntityRepository {
|
||||||
|
private readonly LoggerInterface $logger;
|
||||||
|
|
||||||
|
public function __construct(EntityManager $em, LoggerInterface $logger)
|
||||||
|
{
|
||||||
|
parent::__construct($em, $em->getClassMetadata(User::class));
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findByEmail(string $email): ?User {
|
||||||
|
return $this->findOneBy(['email' => $email]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateCredentials(string $email, string $password): ?User {
|
||||||
|
$user = $this->findByEmail($email);
|
||||||
|
if (!$user || !$user->validate($password)) {
|
||||||
|
$this->logger->warning('Invalid credentials.', ['email' => $email, 'password' => $password, 'user' => $user, 'valid' => $user?->validate($password)]);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(User $user): void {
|
||||||
|
$this->_em->persist($user);
|
||||||
|
$this->_em->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lewisdale\App\Session;
|
||||||
|
|
||||||
|
use Lewisdale\App\Models\Repositories\UserRepository;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Psr\Http\Server\MiddlewareInterface;
|
||||||
|
use Psr\Http\Server\RequestHandlerInterface;
|
||||||
|
use Slim\Psr7\Response;
|
||||||
|
|
||||||
|
class LoginMiddleware implements MiddlewareInterface {
|
||||||
|
|
||||||
|
function __construct(
|
||||||
|
private readonly UserRepository $users,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
private function redirectToLogin(): ResponseInterface {
|
||||||
|
$response = new Response(302);
|
||||||
|
return $response->withHeader('Location', '/account/login');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||||
|
{
|
||||||
|
if (!isset($_SESSION['user'])) {
|
||||||
|
return $this->redirectToLogin();
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->users->find($_SESSION['user']);
|
||||||
|
|
||||||
|
if (!$user) {
|
||||||
|
return $this->redirectToLogin();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $handler->handle($request->withAttribute('user', $user));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
|
namespace Lewisdale\App\Tools\Console;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand;
|
||||||
|
use Lewisdale\App\Models\Data\User;
|
||||||
|
use Lewisdale\App\Models\Repositories\FeedRepository;
|
||||||
|
use Lewisdale\App\Models\Repositories\UserRepository;
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
#[AsCommand(name: 'user:create', description: 'Create a user')]
|
||||||
|
class CreateUser extends Command {
|
||||||
|
public function __construct(private readonly EntityManager $em,
|
||||||
|
private readonly UserRepository $userRepository)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configure(): void {
|
||||||
|
$this->addArgument('email', InputArgument::REQUIRED, "The user's email address")
|
||||||
|
->addArgument('password', InputArgument::REQUIRED, "The user's password");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||||
|
$email = $input->getArgument('email');
|
||||||
|
$password = $input->getArgument('password');
|
||||||
|
|
||||||
|
$user = $this->userRepository->findOneBy(['email' => $email]);
|
||||||
|
if ($user !== null) {
|
||||||
|
$output->writeln('<error>User with email ' . $email . ' already exists.</error>');
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = new User('', $email);
|
||||||
|
$user->updatePassword($password);
|
||||||
|
|
||||||
|
$this->userRepository->save($user);
|
||||||
|
$output->writeln("<info>User $email created!</info>");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
+24
-5
@@ -1,10 +1,15 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
use Lewisdale\App\Controllers\FeedController;
|
use Lewisdale\App\Controllers\FeedController;
|
||||||
use Lewisdale\App\Controllers\SampleController;
|
use Lewisdale\App\Controllers\HomeController;
|
||||||
|
use Lewisdale\App\Controllers\LoginController;
|
||||||
|
use Lewisdale\App\Session\LoginMiddleware;
|
||||||
|
use Slim\Routing\RouteCollectorProxy;
|
||||||
use Slim\Views\TwigMiddleware;
|
use Slim\Views\TwigMiddleware;
|
||||||
|
|
||||||
ini_set('user_agent', 'Baleen/1.0 (https://lewisdale.dev)');
|
ini_set('user_agent', 'Baleen/1.0 (https://baleen.lewisdale.dev)');
|
||||||
|
ini_set('session.name', 'sessid');
|
||||||
|
ini_set('session.cookie_samesite', 'Lax');
|
||||||
|
|
||||||
require_once __DIR__ . "/dependencies.php";
|
require_once __DIR__ . "/dependencies.php";
|
||||||
|
|
||||||
@@ -19,11 +24,25 @@ require_once __DIR__ . "/session.php";
|
|||||||
$app->add(TwigMiddleware::createFromContainer($app));
|
$app->add(TwigMiddleware::createFromContainer($app));
|
||||||
$app->add('csrf');
|
$app->add('csrf');
|
||||||
|
|
||||||
$app->get("/", [SampleController::class, 'get']);
|
$app->get("/", [HomeController::class, 'get']);
|
||||||
|
|
||||||
$app->get('/feed', [FeedController::class, 'get']);
|
$app->group('/feed', function (RouteCollectorProxy $group) use ($app) {
|
||||||
|
$group->get('[/]', [FeedController::class, 'get'])->add(LoginMiddleware::class);
|
||||||
|
$group->post('[/]', [FeedController::class, 'save'])->add(LoginMiddleware::class);
|
||||||
|
|
||||||
$app->get('/feed/{id}', [FeedController::class, 'get_feed']);
|
$group->get('/new', [FeedController::class, 'create'])->add(LoginMiddleware::class);
|
||||||
|
|
||||||
|
$group->get('/{id}', [FeedController::class, 'get_feed']);
|
||||||
|
$group->post('/{id}', [FeedController::class, 'save'])->add(LoginMiddleware::class);
|
||||||
|
|
||||||
|
$group->get('/{id}/delete', [FeedController::class, 'delete'])->add(LoginMiddleware::class);
|
||||||
|
$group->get('/{id}/edit', [FeedController::class, 'create'])->add(LoginMiddleware::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
$app->group('/account', function (RouteCollectorProxy $group) use ($app, $container) {
|
||||||
|
$group->get('/login', [LoginController::class, 'index']);
|
||||||
|
$group->post('/login', [LoginController::class, 'login']);
|
||||||
|
});
|
||||||
|
|
||||||
$app->addErrorMiddleware(true, true, true);
|
$app->addErrorMiddleware(true, true, true);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{% macro filterBlock(ctx, idx, type, target, value, id) %}
|
||||||
|
<fieldset>
|
||||||
|
<legend>Filter</legend>
|
||||||
|
<input type="hidden" name="feedFilters[{{ idx }}][id]" value="{{ id }}"/>
|
||||||
|
|
||||||
|
<label for="target">Filter target:</label>
|
||||||
|
<select name="feedFilters[{{ idx }}][target]" id="target">
|
||||||
|
{% for filterTarget in ctx.FilterTargets %}
|
||||||
|
<option value="{{ filterTarget.value }}" {% if filterTarget.value is same as(target) %}selected{% endif %}>{{ filterTarget.name | capitalize }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label for="type">Filter type: </label>
|
||||||
|
<select name="feedFilters[{{ idx }}][type]" id="type">
|
||||||
|
{% for filterType in ctx.FilterTypes %}
|
||||||
|
<option value="{{ filterType.value }}" {% if filterType is same as(type) %}selected{% endif %}>{{ filterType.name | capitalize }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label for="value">Filter value:</label>
|
||||||
|
<input type="text" name="feedFilters[{{ idx }}][value]" id="value" value="{{ value }}" />
|
||||||
|
</fieldset>
|
||||||
|
{% endmacro %}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<h1>Login</h1>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
{{ csrf() | raw }}
|
||||||
|
|
||||||
|
{% if error %}
|
||||||
|
<div class="alert alert-danger">{{ error }}</div>
|
||||||
|
{% endif %}
|
||||||
|
<label for="email">Email address</label>
|
||||||
|
<input id="email" type="email" name="email" placeholder="Email" required />
|
||||||
|
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input id="password" type="password" name="password" placeholder="Password" required minlength="8" />
|
||||||
|
|
||||||
|
<button type="submit">Login</button>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
{% from "_includes/filterBlock.twig.html" import filterBlock %}
|
||||||
|
|
||||||
|
<h1>Create feed</h1>
|
||||||
|
|
||||||
|
<form method="POST" action="/feed/{{ feed.id }}">
|
||||||
|
{{ csrf() | raw }}
|
||||||
|
|
||||||
|
<input type="hidden" name="id" value="{{ feed.id }}"/>
|
||||||
|
|
||||||
|
<label for="url">
|
||||||
|
Feed URL
|
||||||
|
</label>
|
||||||
|
<input type="text" inputmode="url" name="url" value="{{ feed.url }}" id="url"/>
|
||||||
|
|
||||||
|
<label for="title">
|
||||||
|
Title
|
||||||
|
</label>
|
||||||
|
<input type="text" inputmode="title" name="title" value="{{ feed.title }}" id="title"/>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<legend>Filters</legend>
|
||||||
|
|
||||||
|
{% for filter in feed.feedFilters %}
|
||||||
|
{{ filterBlock(_context, loop.index0, filter.filter, filter.target, filter.value, filter.id) }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{{ filterBlock(_context, (feed.feedFilters | length)) }}
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<button type="submit">Save feed</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<h1>Your feeds</h1>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<th>Title</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for feed in feeds %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ feed.title }}</td>
|
||||||
|
<td>
|
||||||
|
<a href="/feed/{{ feed.id }}">Link to feed</a>
|
||||||
|
<a href="/feed/{{ feed.id }}/edit">Edit feed</a>
|
||||||
|
<a href="/feed/{{ feed.id }}/delete">Delete</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
<h1>Hello, world.</h1>
|
<h1>Baleen</h1>
|
||||||
|
|
||||||
<p>This is a boilerplate PHP app. You should start by adding some routes, controllers, and maybe making me look
|
<p>This is Baleen, an RSS and Podcast feed filtering application. If you're here because you've spotted the user agent in your logs, it's because someone is using this application to produce a filtered RSS feed.</p>
|
||||||
good.</p>
|
|
||||||
|
<p>Baleen will always use the user agent <code>Baleen/1.0 (https://baleen.lewisdale.dev)</code>, and should respect robots.txt.</p>
|
||||||
|
|
||||||
|
<p>If you're blocking Baleen, but we're still appearing in your logs, please get in touch with <a href="https://lewisdale.dev/links/">the developer</a>, as this is likely a bug in the software.</p>
|
||||||
Reference in new issue
Block a user