Search by

drago-ex / project-user

accgit

A small helper package for working with the authenticated user in Drago project.

Package info

github.com/drago-ex/project-user

Type:drago-tools-resource

pkg:composer/drago-ex/project-user

Statistics

Installs: 157

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-10-29 16:29 UTC

This package is auto-updated.

Last update: 2026-10-31 06:47:55 UTC


README

A small helper package for working with the authenticated user in Drago project. Provides type-safe access to identity data and a simple, extensible user identity object.

PHP version Coding Style

Requirements

Installation

composer require drago-ex/project-user

Files copied into the project

The files are copied into the project by drago-ex/project-tools, as set in extra.drago-tools of this package's composer.json.

Examples

Injecting the user service:

use App\Core\Security\CurrentUser;
use Nette\DI\Attributes\Inject;

final class SomePresenter extends Presenter
{
	#[Inject]
	public CurrentUser $currentUser;

	protected function beforeRender(): void
	{
		parent::beforeRender();
		$this->template->currentUser = $this->currentUser;
	}
}

Identity data in latte

{varType App\Core\Security\CurrentUser $currentUser}
{block content}
	<p>{$currentUser->getUserIdentity()->username}</p>
{/block}

User identity object

For common identity fields, use the typed UserIdentity object:

$identity = $currentUser->getUserIdentity();

echo $identity->username;
echo $identity->email;

The UserIdentity class is intentionally simple and can be extended with additional attributes (e.g. id, roles, permissions) as needed.

UserIdentityException is thrown when identity data is missing or invalid.

Any of several privileges

isAnyAllowed() is true when the user may do at least one of the privileges on a resource, e.g. to show a menu item that leads to several actions:

$currentUser->isAnyAllowed('Backend:Blog', 'default-read', 'comments-read');

Showing what the user may use

isPermitted() is isAnyAllowed() for menus and buttons: without an authorizator (no drago-ex/permission) it is always true, and a resource the ACL does not know is denied instead of throwing. Each role is asked on its own, so a role the ACL does not know (e.g. a stale one in the session) does not deny the others:

$currentUser->isPermitted('Backend:Blog', 'articles-write');

Notes

  • This package does not sign users in; it gives safe access to the identity data and the permission checks above (the ACL itself comes from drago-ex/permission).