User
extends Auth
in package
Class User
Represents a user entity and provides methods for user management such as adding users, verifying login status, retrieving user details, resetting passwords, and checking user registration. Extends the Auth class to leverage authentication functionalities.
Table of Contents
Properties
- $db : MySql
- $enc : Encryption
- $request : Request
- $role : string
- $session : Session
- $userData : UserData
Methods
- __construct() : mixed
- addUser() : array<string|int, mixed>
- Adds a new user
- cleanAuthTable() : void
- Deletes redundant validator tokens
- createUser() : array<string|int, mixed>
- Creates user
- get() : array<string|int, mixed>
- getByUsername() : type
- getUserRoles() : array<string|int, mixed>
- Returns array with user's roles
- hasRole() : bool
- Returns boolean indicating whether a use has particular role
- isLogged() : bool|array<string|int, mixed>
- isRegistered() : type
- logIn() : bool
- Logs in a user
- logOut() : bool
- Logs out the user
- resetOwnPassword() : bool
- resetUserPassword() : bool
- Resets user's password
- isAuth() : bool|int
- Checks whether the user is logged On success, SESSION is always closed for performance reasons
- resetPasword() : bool
Properties
$db
protected
MySql
$db
$enc
protected
Encryption
$enc
$request
protected
Request
$request
$role
protected
string
$role
= 'user'
$session
protected
Session
$session
$userData
private
UserData
$userData
Methods
__construct()
public
__construct(MySql $db, Encryption $enc, Session $session, Request $request, UserData $userData) : mixed
Parameters
- $db : MySql
- $enc : Encryption
- $session : Session
- $request : Request
- $userData : UserData
addUser()
Adds a new user
public
addUser(string $name, string $lastName, string $username, string $pwd, int $status) : array<string|int, mixed>
Parameters
- $name : string
- $lastName : string
- $username : string
- $pwd : string
- $status : int
Return values
array<string|int, mixed>cleanAuthTable()
Deletes redundant validator tokens
public
cleanAuthTable(int $userId) : void
Parameters
- $userId : int
createUser()
Creates user
public
createUser(string $firstName, string $lastName, string $username, string $pwd[, int $status = 1 ]) : array<string|int, mixed>
Parameters
- $firstName : string
- $lastName : string
- $username : string
- $pwd : string
- $status : int = 1
Return values
array<string|int, mixed>get()
public
get(int $userId) : array<string|int, mixed>
Parameters
- $userId : int
Return values
array<string|int, mixed>getByUsername()
public
getByUsername(string $username) : type
Parameters
- $username : string
Tags
Return values
typegetUserRoles()
Returns array with user's roles
public
getUserRoles(int $userId) : array<string|int, mixed>
Parameters
- $userId : int
Return values
array<string|int, mixed>hasRole()
Returns boolean indicating whether a use has particular role
public
hasRole(int $userId, string $role) : bool
Parameters
- $userId : int
- $role : string
Return values
boolisLogged()
public
isLogged() : bool|array<string|int, mixed>
Return values
bool|array<string|int, mixed>isRegistered()
public
isRegistered(string $username) : type
Parameters
- $username : string
Return values
typelogIn()
Logs in a user
public
logIn(string $username, string $pwd[, bool $remember = false ]) : bool
Parameters
- $username : string
- $pwd : string
- $remember : bool = false
Return values
boollogOut()
Logs out the user
public
logOut() : bool
Return values
boolresetOwnPassword()
public
resetOwnPassword(int $userId, string $pwd[, bool $login = false ]) : bool
Parameters
- $userId : int
- $pwd : string
- $login : bool = false
Return values
boolresetUserPassword()
Resets user's password
public
resetUserPassword(int $userId, string $pwd[, bool $login = false ]) : bool
Parameters
- $userId : int
- $pwd : string
- $login : bool = false
Return values
boolisAuth()
Checks whether the user is logged On success, SESSION is always closed for performance reasons
protected
isAuth() : bool|int
Return values
bool|intresetPasword()
protected
resetPasword(int $userId, string $pwd[, bool $login = false ]) : bool
Parameters
- $userId : int
- $pwd : string
- $login : bool = false