castopod/app/Helpers/auth_helper.php
Yassine Doghri 5c5c6da4be
refactor: add rector to enforce type declarations, code quality + style and remove dead code
- update CI process to include quality stage (tests + code review)
- add captainhook to install git pre-commit & pre-push hooks
- remove .devcontainer Dockerfile to use project's docker-compose services: all
services can now be started automatically using vscode
- update docs/setup-development.md
2021-05-12 10:48:30 +00:00

83 lines
1.9 KiB
PHP

<?php
/**
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
use ActivityPub\Entities\Actor;
use CodeIgniter\Database\Exceptions\DataException;
use Config\Services;
if (!function_exists('set_interact_as_actor')) {
/**
* Sets the actor id of which the user is acting as
*/
function set_interact_as_actor($actorId): void
{
$authenticate = Services::authentication();
$authenticate->check();
$session = session();
$session->set('interact_as_actor_id', $actorId);
}
}
if (!function_exists('remove_interact_as_actor')) {
/**
* Removes the actor id of which the user is acting as
*/
function remove_interact_as_actor(): void
{
$session = session();
$session->remove('interact_as_actor_id');
}
}
if (!function_exists('interact_as_actor_id')) {
/**
* Sets the podcast id of which the user is acting as
*/
function interact_as_actor_id(): int
{
$authenticate = Services::authentication();
$authenticate->check();
$session = session();
return $session->get('interact_as_actor_id');
}
}
if (!function_exists('interact_as_actor')) {
/**
* Get the actor the user is currently interacting as
*
* @return Actor|false
*/
function interact_as_actor()
{
$authenticate = Services::authentication();
$authenticate->check();
$session = session();
if ($session->has('interact_as_actor_id')) {
return model('ActorModel')->getActorById(
$session->get('interact_as_actor_id'),
);
}
return false;
}
}
if (!function_exists('can_user_interact')) {
/**
* @throws DataException
*/
function can_user_interact(): bool
{
return (bool) interact_as_actor();
}
}