Skip to content

Commit

Permalink
Switch rest to new Authentication modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed Jul 11, 2024
1 parent 13b8324 commit 90afd82
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 183 deletions.
4 changes: 0 additions & 4 deletions src/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ function boot_error(string $message) {
->register(Bramus\Router\Router::class)
->setShared(true)
;
$container
->register(helpers\Authentication::class)
->setShared(true)
;

$container
->register(
Expand Down
9 changes: 5 additions & 4 deletions src/controllers/About.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
namespace controllers;

use helpers\Authentication;
use helpers\Authentication\AuthenticationService;
use helpers\Configuration;
use helpers\View;

/**
* Controller for instance information API
*/
class About {
private Authentication $authentication;
private bool $authenticationEnabled;
private Configuration $configuration;
private View $view;

public function __construct(Authentication $authentication, Configuration $configuration, View $view) {
$this->authentication = $authentication;
public function __construct(AuthenticationService $authenticationService, Configuration $configuration, View $view) {
$this->authenticationEnabled = !$authenticationService instanceof Authentication\Services\Trust;
$this->configuration = $configuration;
$this->view = $view;
}
Expand Down Expand Up @@ -54,7 +55,7 @@ public function about(): void {
'htmlTitle' => trim($this->configuration->htmlTitle), // string
'allowPublicUpdate' => $this->configuration->allowPublicUpdateAccess, // bool
'publicMode' => $this->configuration->public, // bool
'authEnabled' => $this->authentication->enabled() === true, // bool
'authEnabled' => $this->authenticationEnabled, // bool
'readingSpeed' => $this->configuration->readingSpeedWpm > 0 ? $this->configuration->readingSpeedWpm : null, // ?int
'language' => $this->configuration->language === '0' ? null : $this->configuration->language, // ?string
'userCss' => file_exists(BASEDIR . '/user.css') ? filemtime(BASEDIR . '/user.css') : null, // ?int
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/Helpers/HashPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

namespace controllers\Helpers;

use helpers\Authentication;
use helpers\Authentication\AuthenticationService;
use helpers\View;

/**
* Controller for user related tasks
*/
final class HashPassword {
private Authentication $authentication;
private AuthenticationService $authenticationService;
private View $view;

public function __construct(Authentication $authentication, View $view) {
$this->authentication = $authentication;
public function __construct(AuthenticationService $authenticationService, View $view) {
$this->authenticationService = $authenticationService;
$this->view = $view;
}

Expand All @@ -24,7 +24,7 @@ public function __construct(Authentication $authentication, View $view) {
* json
*/
public function hash(): void {
$this->authentication->needsLoggedIn();
$this->authenticationService->ensureIsPrivileged();

if (!isset($_POST['password'])) {
$this->view->jsonError([
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Bramus\Router\Router;
use daos\ItemOptions;
use helpers\Authentication;
use helpers\Authentication\AuthenticationService;
use helpers\StringKeyedArray;
use helpers\View;
use helpers\ViewHelper;
Expand All @@ -19,7 +19,7 @@
* @author Tobias Zeising <[email protected]>
*/
class Index {
private Authentication $authentication;
private AuthenticationService $authenticationService;
private \daos\Items $itemsDao;
private Router $router;
private \daos\Sources $sourcesDao;
Expand All @@ -28,8 +28,8 @@ class Index {
private View $view;
private ViewHelper $viewHelper;

public function __construct(Authentication $authentication, \daos\Items $itemsDao, Router $router, \daos\Sources $sourcesDao, Tags $tagsController, \daos\Tags $tagsDao, View $view, ViewHelper $viewHelper) {
$this->authentication = $authentication;
public function __construct(AuthenticationService $authenticationService, \daos\Items $itemsDao, Router $router, \daos\Sources $sourcesDao, Tags $tagsController, \daos\Tags $tagsDao, View $view, ViewHelper $viewHelper) {
$this->authenticationService = $authenticationService;
$this->itemsDao = $itemsDao;
$this->router = $router;
$this->sourcesDao = $sourcesDao;
Expand Down Expand Up @@ -60,7 +60,7 @@ public function home(): void {
return;
}

$this->authentication->needsLoggedInOrPublicMode();
$this->authenticationService->ensureCanRead();

// load tags
$tags = $this->tagsDao->getWithUnread();
Expand Down
18 changes: 9 additions & 9 deletions src/controllers/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use daos\ItemOptions;
use DateTimeInterface;
use helpers\Authentication;
use helpers\Authentication\AuthenticationService;
use helpers\Misc;
use helpers\Request;
use helpers\View;
Expand All @@ -20,18 +20,18 @@
* @author Tobias Zeising <[email protected]>
*/
class Items {
private Authentication $authentication;
private AuthenticationService $authenticationService;
private \daos\Items $itemsDao;
private Request $request;
private View $view;

public function __construct(
Authentication $authentication,
AuthenticationService $authenticationService,
\daos\Items $itemsDao,
Request $request,
View $view
) {
$this->authentication = $authentication;
$this->authenticationService = $authenticationService;
$this->itemsDao = $itemsDao;
$this->request = $request;
$this->view = $view;
Expand All @@ -44,7 +44,7 @@ public function __construct(
* @param ?string $itemId ID of item to mark as read
*/
public function mark(?string $itemId = null): void {
$this->authentication->needsLoggedIn();
$this->authenticationService->ensureIsPrivileged();

$ids = null;
if ($itemId !== null) {
Expand Down Expand Up @@ -84,7 +84,7 @@ public function mark(?string $itemId = null): void {
* @param string $itemId id of an item to mark as unread
*/
public function unmark(string $itemId): void {
$this->authentication->needsLoggedIn();
$this->authenticationService->ensureIsPrivileged();

try {
$itemId = Misc::forceId($itemId);
Expand All @@ -106,7 +106,7 @@ public function unmark(string $itemId): void {
* @param string $itemId id of an item to starr
*/
public function starr(string $itemId): void {
$this->authentication->needsLoggedIn();
$this->authenticationService->ensureIsPrivileged();

try {
$itemId = Misc::forceId($itemId);
Expand All @@ -127,7 +127,7 @@ public function starr(string $itemId): void {
* @param string $itemId id of an item to unstarr
*/
public function unstarr(string $itemId): void {
$this->authentication->needsLoggedIn();
$this->authenticationService->ensureIsPrivileged();

try {
$itemId = Misc::forceId($itemId);
Expand All @@ -146,7 +146,7 @@ public function unstarr(string $itemId): void {
* json
*/
public function listItems(): void {
$this->authentication->needsLoggedInOrPublicMode();
$this->authenticationService->ensureCanRead();

// parse params
$options = ItemOptions::fromUser($_GET);
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/Items/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

namespace controllers\Items;

use helpers\Authentication;
use helpers\Authentication\AuthenticationService;
use helpers\View;

/**
* Controller for viewing item statistics
*/
class Stats {
private Authentication $authentication;
private AuthenticationService $authenticationService;
private \daos\Items $itemsDao;
private \daos\Sources $sourcesDao;
private \daos\Tags $tagsDao;
private View $view;

public function __construct(Authentication $authentication, \daos\Items $itemsDao, \daos\Sources $sourcesDao, \daos\Tags $tagsDao, View $view) {
$this->authentication = $authentication;
public function __construct(AuthenticationService $authenticationService, \daos\Items $itemsDao, \daos\Sources $sourcesDao, \daos\Tags $tagsDao, View $view) {
$this->authenticationService = $authenticationService;
$this->itemsDao = $itemsDao;
$this->sourcesDao = $sourcesDao;
$this->tagsDao = $tagsDao;
Expand All @@ -30,7 +30,7 @@ public function __construct(Authentication $authentication, \daos\Items $itemsDa
* json
*/
public function stats(): void {
$this->authentication->needsLoggedInOrPublicMode();
$this->authenticationService->ensureCanRead();

$stats = $this->itemsDao->stats();

Expand Down
12 changes: 6 additions & 6 deletions src/controllers/Items/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace controllers\Items;

use helpers\Authentication;
use helpers\Authentication\AuthenticationService;
use helpers\Configuration;
use function helpers\json_response;
use helpers\View;
Expand All @@ -14,7 +14,7 @@
* Controller for synchronizing item statuses
*/
class Sync {
private Authentication $authentication;
private AuthenticationService $authenticationService;
private Configuration $configuration;
private \daos\Items $itemsDao;
private \daos\Sources $sourcesDao;
Expand All @@ -23,8 +23,8 @@ class Sync {
private View $view;
private ViewHelper $viewHelper;

public function __construct(Authentication $authentication, Configuration $configuration, \daos\Items $itemsDao, \daos\Sources $sourcesDao, \controllers\Tags $tagsController, \daos\Tags $tagsDao, View $view, ViewHelper $viewHelper) {
$this->authentication = $authentication;
public function __construct(AuthenticationService $authenticationService, Configuration $configuration, \daos\Items $itemsDao, \daos\Sources $sourcesDao, \controllers\Tags $tagsController, \daos\Tags $tagsDao, View $view, ViewHelper $viewHelper) {
$this->authenticationService = $authenticationService;
$this->configuration = $configuration;
$this->itemsDao = $itemsDao;
$this->sourcesDao = $sourcesDao;
Expand All @@ -39,7 +39,7 @@ public function __construct(Authentication $authentication, Configuration $confi
* json
*/
public function sync(): void {
$this->authentication->needsLoggedInOrPublicMode();
$this->authenticationService->ensureCanRead();

if (isset($_GET['since'])) {
$params = $_GET;
Expand Down Expand Up @@ -113,7 +113,7 @@ public function sync(): void {
* Items statuses bulk update.
*/
public function updateStatuses(): void {
$this->authentication->needsLoggedIn();
$this->authenticationService->ensureIsPrivileged();

if (isset($_POST['updatedStatuses'])
&& is_array($_POST['updatedStatuses'])) {
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/Opml/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace controllers\Opml;

use helpers\Authentication;
use helpers\Authentication\AuthenticationService;
use helpers\Configuration;
use helpers\SpoutLoader;
use helpers\StringKeyedArray;
Expand All @@ -19,16 +19,16 @@
* @author Sean Rand <[email protected]>
*/
class Export {
private Authentication $authentication;
private AuthenticationService $authenticationService;
private Configuration $configuration;
private Logger $logger;
private SpoutLoader $spoutLoader;
private \XMLWriter $writer;
private \daos\Sources $sourcesDao;
private \daos\Tags $tagsDao;

public function __construct(Authentication $authentication, Configuration $configuration, Logger $logger, \daos\Sources $sourcesDao, SpoutLoader $spoutLoader, \daos\Tags $tagsDao, \XMLWriter $writer) {
$this->authentication = $authentication;
public function __construct(AuthenticationService $authenticationService, Configuration $configuration, Logger $logger, \daos\Sources $sourcesDao, SpoutLoader $spoutLoader, \daos\Tags $tagsDao, \XMLWriter $writer) {
$this->authenticationService = $authenticationService;
$this->configuration = $configuration;
$this->logger = $logger;
$this->sourcesDao = $sourcesDao;
Expand Down Expand Up @@ -79,7 +79,7 @@ private function writeSource(array $source): void {
* @note Uses the selfoss namespace to store selfoss-specific information
*/
public function export(): void {
$this->authentication->needsLoggedIn();
$this->authenticationService->ensureIsPrivileged();

$this->logger->debug('start OPML export');
$this->writer->openMemory();
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/Opml/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace controllers\Opml;

use helpers\Authentication;
use helpers\Authentication\AuthenticationService;
use helpers\View;
use Monolog\Logger;
use SimpleXMLElement;
Expand All @@ -21,14 +21,14 @@ class Import {
/** @var array<string, array{id: int, tags: string[]}> Sources that have been imported from the OPML file */
private array $imported = [];

private Authentication $authentication;
private AuthenticationService $authenticationService;
private Logger $logger;
private \daos\Sources $sourcesDao;
private \daos\Tags $tagsDao;
private View $view;

public function __construct(Authentication $authentication, Logger $logger, \daos\Sources $sourcesDao, \daos\Tags $tagsDao, View $view) {
$this->authentication = $authentication;
public function __construct(AuthenticationService $authenticationService, Logger $logger, \daos\Sources $sourcesDao, \daos\Tags $tagsDao, View $view) {
$this->authenticationService = $authenticationService;
$this->logger = $logger;
$this->sourcesDao = $sourcesDao;
$this->tagsDao = $tagsDao;
Expand All @@ -42,7 +42,7 @@ public function __construct(Authentication $authentication, Logger $logger, \dao
* @note Borrows from controllers/Sources.php:write
*/
public function add(): void {
$this->authentication->needsLoggedIn();
$this->authenticationService->ensureIsPrivileged();

http_response_code(400);

Expand Down
10 changes: 5 additions & 5 deletions src/controllers/Rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use daos\ItemOptions;
use FeedWriter\RSS2;
use helpers\Authentication;
use helpers\Authentication\AuthenticationService;
use helpers\Configuration;
use helpers\View;

Expand All @@ -18,15 +18,15 @@
* @author Tobias Zeising <[email protected]>
*/
class Rss {
private Authentication $authentication;
private AuthenticationService $authenticationService;
private Configuration $configuration;
private RSS2 $feedWriter;
private \daos\Items $itemsDao;
private \daos\Sources $sourcesDao;
private View $view;

public function __construct(Authentication $authentication, Configuration $configuration, RSS2 $feedWriter, \daos\Items $itemsDao, \daos\Sources $sourcesDao, View $view) {
$this->authentication = $authentication;
public function __construct(AuthenticationService $authenticationService, Configuration $configuration, RSS2 $feedWriter, \daos\Items $itemsDao, \daos\Sources $sourcesDao, View $view) {
$this->authenticationService = $authenticationService;
$this->configuration = $configuration;
$this->feedWriter = $feedWriter;
$this->itemsDao = $itemsDao;
Expand All @@ -38,7 +38,7 @@ public function __construct(Authentication $authentication, Configuration $confi
* rss feed
*/
public function rss(): void {
$this->authentication->needsLoggedInOrPublicMode();
$this->authenticationService->ensureCanRead();

$this->feedWriter->setTitle($this->configuration->rssTitle);
$this->feedWriter->setChannelElement('description', '');
Expand Down
Loading

0 comments on commit 90afd82

Please sign in to comment.