⚠️ Warning! This package does not have active support, it exists only for the historical needs of the author.
The package adds support for a database-backed user system for Nette. It provides a user management that aims to handle common tasks such as user registration, login, password retrieval and much more.
The best way to install 68publishers/user is using Composer:
composer require 68publishers/userRequirements: PHP ^8.3, doctrine/orm ^2.10 || ^3.0, nette/security ^3.1.8.
The entities are mapped with PHP attributes and registered through 68publishers/doctrine-bridge with the attribute driver (EntityMapping::DRIVER_ATTRIBUTE), so a mapping driver service of the type Doctrine\ORM\Mapping\Driver\AttributeDriver must exist in the container. Applications that map their own entities with annotations (doctrine/orm 2) only need to register it next to the annotation driver, e.g.:
services:
attributeDriver:
factory: Doctrine\ORM\Mapping\Driver\AttributeDriver([], true)
autowired: falseor use Nettrine\ORM\DI\OrmAttributesExtension of nettrine/orm (the bridge option 68publishers.doctrine_bridge.services.drivers.attribute selects the driver service if there are more of them). Create the driver with reportFieldsWhereDeclared: true (the second argument, the only mode of doctrine/orm 3, false is deprecated since doctrine/orm 2.16). Annotation-mapped application entities can still relate to the package entities (PasswordRequest relates to your user entity through the resolved UserInterface).
- Every signed-in user is signed out once after the upgrade: the session keeps the fingerprint of the credentials now (see Sessions and access), sessions without it are not accepted.
DeviceInfoof password requests stores the remote address of the request (Nette\Http\IRequest::getRemoteAddress()), notClient-IPor the first address ofX-Forwarded-For. Set the trusted proxies (http: proxy:) to store the address of the client behind a proxy.PasswordRequestFactory,PasswordRequestManagerandAuthenticatorhave new optional constructor arguments (the HTTP request, the password hash strategy), they are autowired.
- The minimal PHP version is 8.3.
- The package requires
68publishers/doctrine-bridge^2.0,68publishers/doctrine-persistence^0.4,68publishers/doctrine-query-objects^0.3,68publishers/smart-nette-component^2.0and68publishers/translation-bridge^3.0. - The class
SixtyEightPublishers\User\Common\EventSubscriber\HashUserPasswordSubscriberwas removed. It was never registered by the bundle, passwords are hashed by thePasswordvalue object and thePasswordType. - The entities (
PasswordRequest,DeviceInfo) are mapped with PHP attributes instead of annotations (the database schema is the same) anddoctrine/orm3 is supported. Register a service of the typeDoctrine\ORM\Mapping\Driver\AttributeDriver(see Installation), otherwise the container compilation fails with "Can't resolve service definition ... services.drivers.attribute". doctrine/annotationsis no longer required.- The authenticator service is registered with the type
Nette\Security\Authenticator(previously the deprecatedIAuthenticator), so it is autowired for both interfaces.
// @todoThe session keeps the ID of the user and a fingerprint of the credentials (the username and the hash of the password). The user is loaded on every request
and signed out if they don't exist anymore, have no access or the credentials changed since the sign-in: a reset or a change of the password
signs out the other sessions of the user. ResetPasswordControl with the auto login signs in the current session again.
Two optional interfaces of the user entity:
SixtyEightPublishers\User\Common\Entity\AccessRestrictedUserInterface::hasAccess(), e.g. a deactivated user or a user without a role with access. A user without access can't sign in (Authenticator::NotApproved, checked after the password), their sessions are signed out on the next request and they can't request or complete the reset of the password (answered as if the account didn't exist).SixtyEightPublishers\User\Common\Entity\CredentialsFingerprintInterface::getCredentialsFingerprint()replaces the default fingerprint, e.g. with a "security stamp" column that changes with the credentials (also the e-mail if it is not the username).
final class User implements AuthenticationUserInterface, ForgotPasswordUserInterface, AccessRestrictedUserInterface
{
public function hasAccess(): bool
{
return $this->active && [] !== array_intersect($this->roles, self::ROLES_WITH_ACCESS);
}
}- 1 PR per feature
- PR with tests are more likely to be merged
- tests and coding standard must pass
vendor/bin/tester ./tests -s
vendor/bin/php-cs-fixer fix -v --dry-run