Documentation

UserFacade

Facade providing unified interface to User module.

This facade wraps the use cases to provide a similar interface to the original AuthService for gradual migration.

Tags
since
3.0.0

Table of Contents

Properties

$completePasswordResetUseCase  : CompletePasswordReset|null
$generateApiTokenUseCase  : GenerateApiToken|null
$getCurrentUserUseCase  : GetCurrentUser|null
$loginUseCase  : Login|null
$logoutUseCase  : Logout|null
$passwordHasher  : PasswordHasher
Password hasher.
$registerUseCase  : Register|null
$repository  : UserRepositoryInterface
User repository.
$requestPasswordResetUseCase  : RequestPasswordReset|null
$tokenHasher  : TokenHasher
Token hasher for API and remember tokens.
$validateApiTokenUseCase  : ValidateApiToken|null
$validateSessionUseCase  : ValidateSession|null

Methods

__construct()  : mixed
Constructor.
completePasswordReset()  : bool
Complete a password reset with token and new password.
findByEmail()  : User|null
Find a user by email.
findByGoogleId()  : User|null
Find a user by Google ID.
findById()  : User|null
Find a user by ID.
findByMicrosoftId()  : User|null
Find a user by Microsoft ID.
findByUsername()  : User|null
Find a user by username.
findOrCreateGoogleUser()  : User
Find or create a user from Google OAuth.
findOrCreateMicrosoftUser()  : User
Find or create a user from Microsoft OAuth.
findOrCreateWordPressUser()  : User
Find or create a user from WordPress integration.
generateApiToken()  : string
Generate a new API token for a user.
generateToken()  : string
Generate a secure random token.
getCurrentUser()  : User|null
Get the currently authenticated user.
invalidateApiToken()  : void
Invalidate a user's API token.
invalidateRememberToken()  : void
Invalidate a user's remember-me token.
login()  : User
Authenticate a user with username/email and password.
logout()  : void
Log out the current user.
register()  : User
Register a new user.
requestPasswordReset()  : bool
Request a password reset for an email address.
save()  : void
Save a user entity.
setCurrentUser()  : void
Set the current user (for session restoration).
setRememberToken()  : string
Set a remember-me token for a user.
validateApiToken()  : User|null
Validate an API token and return the associated user.
validatePasswordResetToken()  : bool
Validate a password reset token without using it.
validatePasswordStrength()  : array{valid: bool, errors: string[]}
Validate password strength.
validateRememberToken()  : User|null
Validate a remember-me token and return the associated user.
validateSession()  : bool
Validate the current session.
getCompletePasswordResetUseCase()  : CompletePasswordReset
getGenerateApiTokenUseCase()  : GenerateApiToken
getGetCurrentUserUseCase()  : GetCurrentUser
getLoginUseCase()  : Login
getLogoutUseCase()  : Logout
getRegisterUseCase()  : Register
getRequestPasswordResetUseCase()  : RequestPasswordReset
getValidateApiTokenUseCase()  : ValidateApiToken
getValidateSessionUseCase()  : ValidateSession

Properties

Methods

completePasswordReset()

Complete a password reset with token and new password.

public completePasswordReset(string $token, string $newPassword) : bool
Parameters
$token : string

The reset token from email

$newPassword : string

The new password

Tags
throws
InvalidArgumentException

If password validation fails

Return values
bool

True if password was reset

findByEmail()

Find a user by email.

public findByEmail(string $email) : User|null
Parameters
$email : string

Email address

Return values
User|null

findByGoogleId()

Find a user by Google ID.

public findByGoogleId(string $googleId) : User|null
Parameters
$googleId : string

Google user ID

Return values
User|null

findById()

Find a user by ID.

public findById(int $id) : User|null
Parameters
$id : int

User ID

Return values
User|null

findByMicrosoftId()

Find a user by Microsoft ID.

public findByMicrosoftId(string $microsoftId) : User|null
Parameters
$microsoftId : string

Microsoft user ID

Return values
User|null

findByUsername()

Find a user by username.

public findByUsername(string $username) : User|null
Parameters
$username : string

Username

Return values
User|null

findOrCreateGoogleUser()

Find or create a user from Google OAuth.

public findOrCreateGoogleUser(string $googleId, string $username, string $email) : User
Parameters
$googleId : string

Google user ID

$username : string

Generated username

$email : string

Google email

Return values
User

The found or created user

findOrCreateMicrosoftUser()

Find or create a user from Microsoft OAuth.

public findOrCreateMicrosoftUser(string $microsoftId, string $username, string $email) : User
Parameters
$microsoftId : string

Microsoft user ID

$username : string

Generated username

$email : string

Microsoft email

Return values
User

The found or created user

findOrCreateWordPressUser()

Find or create a user from WordPress integration.

public findOrCreateWordPressUser(int $wpUserId, string $username, string $email) : User
Parameters
$wpUserId : int

WordPress user ID

$username : string

WordPress username

$email : string

WordPress email

Return values
User

The found or created user

generateApiToken()

Generate a new API token for a user.

public generateApiToken(int $userId) : string
Parameters
$userId : int

The user ID

Tags
throws
InvalidArgumentException

If user not found

Return values
string

The generated API token

generateToken()

Generate a secure random token.

public generateToken([int<1, max> $length = 32 ]) : string
Parameters
$length : int<1, max> = 32

Token length in bytes

Return values
string

The generated token

getCurrentUser()

Get the currently authenticated user.

public getCurrentUser() : User|null
Return values
User|null

The current user or null if not authenticated

invalidateApiToken()

Invalidate a user's API token.

public invalidateApiToken(int $userId) : void
Parameters
$userId : int

The user ID

invalidateRememberToken()

Invalidate a user's remember-me token.

public invalidateRememberToken(int $userId) : void
Parameters
$userId : int

The user ID

login()

Authenticate a user with username/email and password.

public login(string $usernameOrEmail, string $password) : User
Parameters
$usernameOrEmail : string

Username or email

$password : string

Plain-text password

Tags
throws
AuthException

If authentication fails

Return values
User

The authenticated user

logout()

Log out the current user.

public logout() : void

register()

Register a new user.

public register(string $username, string $email, string $password) : User
Parameters
$username : string

Username

$email : string

Email address

$password : string

Plain-text password

Tags
throws
InvalidArgumentException

If validation fails

throws
RuntimeException

If registration fails

Return values
User

The created user

requestPasswordReset()

Request a password reset for an email address.

public requestPasswordReset(string $email) : bool

Always returns true to prevent email enumeration attacks. If the email doesn't exist, we silently succeed.

Parameters
$email : string

The email address

Return values
bool

Always true (silent fail for security)

save()

Save a user entity.

public save(User $user) : void
Parameters
$user : User

The user to save

setCurrentUser()

Set the current user (for session restoration).

public setCurrentUser(User $user) : void
Parameters
$user : User

The user to set as current

setRememberToken()

Set a remember-me token for a user.

public setRememberToken(int $userId[, int $days = 30 ]) : string

Returns the plaintext token but stores only the hash for security.

Parameters
$userId : int

The user ID

$days : int = 30

Number of days until expiration (default: 30)

Tags
throws
InvalidArgumentException

If user not found

Return values
string

The generated remember token (plaintext)

validateApiToken()

Validate an API token and return the associated user.

public validateApiToken(string $token) : User|null
Parameters
$token : string

The API token to validate

Return values
User|null

The user if token is valid, null otherwise

validatePasswordResetToken()

Validate a password reset token without using it.

public validatePasswordResetToken(string $token) : bool
Parameters
$token : string

The reset token

Return values
bool

True if token is valid

validatePasswordStrength()

Validate password strength.

public validatePasswordStrength(string $password) : array{valid: bool, errors: string[]}
Parameters
$password : string

Password to validate

Return values
array{valid: bool, errors: string[]}

Validation result

validateRememberToken()

Validate a remember-me token and return the associated user.

public validateRememberToken(string $token) : User|null

The provided plaintext token is hashed before lookup.

Parameters
$token : string

The remember token to validate (plaintext)

Return values
User|null

The user if token is valid, null otherwise

validateSession()

Validate the current session.

public validateSession() : bool
Return values
bool

True if the session is valid


        
On this page

Search results