drago-ex / project-auth
Authentication and user access package for the Drago project.
Package info
github.com/drago-ex/project-auth
Type:drago-tools-resource
pkg:composer/drago-ex/project-auth
Requires
- php: >=8.3 <9
- drago-ex/application: ^3.0
- drago-ex/database: ^3.0
- drago-ex/form: ^2.0
- drago-ex/migration: ^2.3
- drago-ex/project-backend: ^2.0
- drago-ex/project-front: ^2.0
- drago-ex/translator: ^4.0
- drago-ex/utils: ^2.0
- nette/caching: ^3.3
- nette/http: ^3.0
- nette/mail: ^4.0
- nette/security: ^3.2
Requires (Dev)
- drago-ex/project-tools: ^1.1
- nette/tester: ^2.5
- phpstan/phpstan-nette: ^2.0
Suggests
- drago-ex/permission: Enables generation of the authentication permission provider.
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v2.7.0
- v2.6.0
- v2.5.0
- v2.4.0
- v2.3.0
- v2.2.1
- v2.2.0
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.20
- v2.0.19
- v2.0.18
- v2.0.17
- v2.0.16
- v2.0.15
- v2.0.14
- v2.0.13
- v2.0.12
- v2.0.11
- v2.0.10
- 2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
This package is auto-updated.
Last update: 2026-10-25 08:49:07 UTC
README
English | Čeština
Authentication and user access package for the Drago project. This package provides a complete authentication layer including user login, registration, password recovery and access control. It is designed as a modular extension for projects built on top of the Drago ecosystem and Nette Framework.
Requirements
- PHP >= 8.3, < 9
- Nette Framework
- Composer
- Bootstrap
- Naja
- Node.js
- Drago Project core packages
Installation
composer require drago-ex/project-auth
npm Installation
The authentication UI requires the theme switcher and Font Awesome icons:
npm install theme-switcher-compostrap @fortawesome/fontawesome-free
Project files
File copying is handled automatically by drago-ex/project-tools,
which must be installed in your project. Without it, copy the files manually according to the copy section
in this package's composer.json. To skip this package, set "skip": true under
extra.drago-tools.packages.<package-name> in your root composer.json.
Features
- User authentication (sign in / sign out)
- User registration (sign up)
- Password recovery and reset
- Email address verification (after registration and when the address changes)
- Rate limiting of sign-in, registration and password recovery
- User identity handling
- Integration with Nette Security and DI
- Ready-to-use authentication UI components
Configuration
Parameters in app/Presentation/Sign/conf.neon:
authMailFrom- sender of the account emails, use an address of your domainauthRequireEmailVerification- a new account confirms its email address by a link (defaulttrue)mailsection - SMTP connection
After signing in, the user goes to the administration (:Backend:Admin:), or to the front page (:Front:Home:)
when the ACL does not allow the administration to them. To change it, edit the SignedInDestination and
FallbackDestination constants in app/Presentation/Sign/SignPresenter.php.
Behind a reverse proxy, set http: proxy:, otherwise the per-IP limits apply to the proxy address.
Rate limiting
Attempts are counted in the application cache; clearing temp/cache resets them.
| Action | Limit |
|---|---|
| Sign-in | 10 failed attempts per email and 30 per IP address in 15 minutes |
| Registration | 10 attempts per IP address in an hour |
| Password recovery | 5 requests per email and 20 per IP address in an hour, 10 wrong codes in 15 minutes |
| New confirmation link | 3 requests per email and 10 per IP address in an hour |
Security
- Passwords are hashed by
Nette\Security\Passwords; rules inSign/PasswordPolicy(at least 12 characters). - Sign-in and password recovery do not reveal whether an email has an account.
- Changing or recovering the password signs the user out of all other sessions.
- Recovery codes and confirmation links are stored hashed, expire and work only once.
- With email verification on, registration answers the same for a registered address and only emails its owner; without verification it says that the address is already used (the new account would be usable at once).
- The link for a new confirmation email is shown only after the right password of an unconfirmed account.
- Two-factor authentication is not included.
Emails
The email templates are in Sign/Email/ (shared layout @email.latte, also used by Sign/Recovery/email.latte).
To catch emails locally, add Mailpit to docker-compose.override.yaml:
mailpit: image: axllent/mailpit:v1.27 restart: always ports: - '8025:8025'
and point the mailer to it in Sign/conf.neon:
mail: smtp: true host: mailpit port: 1025
Emails are shown at http://localhost:8025.
Adds a new user to the database
Validates the email and the password (PasswordPolicy), hashes the password, generates a token, and ensures the email is unique.
php vendor/bin/create-user <username> <email> <password>
Secure access to the section
use App\Presentation\Accessory\RequireLogged; use Nette\Application\UI\Presenter; final class SecurePresenter extends Presenter { use RequireLogged; }
A visitor who is not signed in goes to the sign-in page and, after signing in, back to the requested page.
Permissions
The package works without permissions and without drago-ex/permission.
For basic permissions, install drago-ex/permission and generate the access rules from permission.php:
php vendor/bin/create-permission --packages
Users have no roles of their own until getRolesByUser() in app/Model/User/UserRepository.php returns them.
To load them from the database of drago-ex/project-permission,
implement it (in a project composed by netis, project-preset does it for you):
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]; }
Database migration
php vendor/bin/migration db:migrate --packages
The package has migration-priority 10, so the users table exists before the packages that use it.