Skip to content
68publishersPublic

About

👤 User registration, login, password retrieval and much more

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

⚠️ Warning! This package does not have active support, it exists only for the historical needs of the author.

User

Total Downloads Latest Version on Packagist

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.

Installation

The best way to install 68publishers/user is using Composer:

composer require 68publishers/user

Requirements: 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: false

or 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).

Upgrade

From 0.6 to 0.7

  • 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.
  • DeviceInfo of password requests stores the remote address of the request (Nette\Http\IRequest::getRemoteAddress()), not Client-IP or the first address of X-Forwarded-For. Set the trusted proxies (http: proxy:) to store the address of the client behind a proxy.
  • PasswordRequestFactory, PasswordRequestManager and Authenticator have new optional constructor arguments (the HTTP request, the password hash strategy), they are autowired.

From 0.5 to 0.6

  • 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.0 and 68publishers/translation-bridge ^3.0.
  • The class SixtyEightPublishers\User\Common\EventSubscriber\HashUserPasswordSubscriber was removed. It was never registered by the bundle, passwords are hashed by the Password value object and the PasswordType.
  • The entities (PasswordRequest, DeviceInfo) are mapped with PHP attributes instead of annotations (the database schema is the same) and doctrine/orm 3 is supported. Register a service of the type Doctrine\ORM\Mapping\Driver\AttributeDriver (see Installation), otherwise the container compilation fails with "Can't resolve service definition ... services.drivers.attribute".
  • doctrine/annotations is no longer required.
  • The authenticator service is registered with the type Nette\Security\Authenticator (previously the deprecated IAuthenticator), so it is autowired for both interfaces.

Usage

// @todo

Sessions and access

The 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);
    }
}

Rules for contributing

  • 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

About

👤 User registration, login, password retrieval and much more

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages