CoolCMS API

LoginUser
in package

FinalYes

Table of Contents

Properties

$jtiDenyList  : JtiDenyList
$jwtManager  : JwtManager
$passwordHasher  : PasswordHasher
$userManager  : UserManager

Methods

__construct()  : mixed
findUserByIdentifier()  : User|null
Finds the account by the login identifier: username or e-mail.
getLoggedUser()  : User|null
Returns the currently authenticated User entity.
isAuthenticated()  : bool
Returns whether the token is valid; use it where the result is directly an Api response for external clients (`is-auth-valid`), not just the internal `startup()` gate.
loadUserFromPayload()  : User|null
Loads a User entity from JWT payload.
login()  : LoginResult
Performs user login, returns token and payload.
validateToken()  : JwtPayload|null
Validates and decodes the JWT token (checks for expiration).

Properties

Methods

findUserByIdentifier()

Finds the account by the login identifier: username or e-mail.

public findUserByIdentifier(string $identifier) : User|null

The front login form offers "username / e-mail address", so both must work.

IMPORTANT: the order is a security rule. A username may contain @, and so another person's e-mail. An identifier shaped like an e-mail is therefore matched against email first and against username only without a match. The other way round an attacker could register a username equal to the victim e-mail and capture the victim's e-mail logins. The password is verified against the single account found.

Parameters
$identifier : string
Return values
User|null

getLoggedUser()

Returns the currently authenticated User entity.

public getLoggedUser(string|null $token) : User|null
Parameters
$token : string|null
Return values
User|null

isAuthenticated()

Returns whether the token is valid; use it where the result is directly an Api response for external clients (`is-auth-valid`), not just the internal `startup()` gate.

public isAuthenticated(string|null $token) : bool

IMPORTANT: it rests on the same two steps as the guard, otherwise a revoked (logged out) but unexpired token would be reported as valid while checkJwtAuth() in JwtAuthTrait rejects it. JwtManager::isValid() verifies signature and parsing and covers expiry in one call (JWT::decode() throws ExpiredException itself); JtiDenyList::isRevoked() rejects a token invalidated by logout.

Parameters
$token : string|null
Return values
bool

loadUserFromPayload()

Loads a User entity from JWT payload.

public loadUserFromPayload(JwtPayload|array<string, mixed> $payload) : User|null
Parameters
$payload : JwtPayload|array<string, mixed>
Return values
User|null

login()

Performs user login, returns token and payload.

public login(string $username, string $password) : LoginResult
Parameters
$username : string
$password : string
Return values
LoginResult

validateToken()

Validates and decodes the JWT token (checks for expiration).

public validateToken(string|null $token) : JwtPayload|null
Parameters
$token : string|null
Return values
JwtPayload|null
On this page

Search results