Login
in package
Use case for user login.
Handles authentication with username/email and password.
Tags
Table of Contents
Constants
- SESSION_TOKEN = 'LWT_SESSION_TOKEN'
- Session key for storing the session token (for CSRF protection).
- SESSION_USER_ID = 'LWT_USER_ID'
- Session key for storing the user ID.
Properties
- $passwordHasher : PasswordHasher
- Password hasher.
- $repository : UserRepositoryInterface
- User repository.
Methods
- __construct() : mixed
- Create a new Login use case.
- execute() : User
- Execute the login.
- createSession() : void
- Create a session for the authenticated user.
Constants
SESSION_TOKEN
Session key for storing the session token (for CSRF protection).
private
mixed
SESSION_TOKEN
= 'LWT_SESSION_TOKEN'
SESSION_USER_ID
Session key for storing the user ID.
private
mixed
SESSION_USER_ID
= 'LWT_USER_ID'
Properties
$passwordHasher
Password hasher.
private
PasswordHasher
$passwordHasher
$repository
User repository.
private
UserRepositoryInterface
$repository
Methods
__construct()
Create a new Login use case.
public
__construct(UserRepositoryInterface $repository[, PasswordHasher|null $passwordHasher = null ]) : mixed
Parameters
- $repository : UserRepositoryInterface
-
User repository
- $passwordHasher : PasswordHasher|null = null
-
Password hasher
execute()
Execute the login.
public
execute(string $usernameOrEmail, string $password) : User
Parameters
- $usernameOrEmail : string
-
Username or email
- $password : string
-
Plain-text password
Tags
Return values
User —The authenticated user
createSession()
Create a session for the authenticated user.
private
createSession(User $user) : void
Parameters
- $user : User
-
The authenticated user