1. Go to this page and download the library: Download drago-ex/project-auth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
drago-ex / project-auth example snippets
use App\Presentation\Accessory\RequireLogged;
use Nette\Application\UI\Presenter;
final class SecurePresenter extends Presenter
{
use RequireLogged;
}
use App\Presentation\Backend\Permission\Component\Roles\RolesEntity;
use App\Presentation\Backend\Permission\Component\Users\UsersRolesEntity;
use Drago\Permission\Role;
public function getRolesByUser(int $userId): array
{
$roles = $this->getConnection()
->select('r.*')->from(RolesEntity::Table)->as('r')
->innerJoin(UsersRolesEntity::Table)->as('ur')->on('ur.role_id = r.id')
->where('ur.%n = ?', UsersRolesEntity::ColumnUserId, $userId)
->fetchPairs(value: RolesEntity::ColumnName);
$roles = array_values($roles);
return $roles ?: [Role::RoleUser];
}