Documentation

Application

Table of Contents

Classes

Repository
Poll
Class Poll
PollOption
Class PollOption
Role
Class Role
User
Class User
Vote
Class Vote

Functions

continueSession()  : void
Continues the current session, optionally authenticating the user and checking for admin privileges.
login()  : bool
Logs in a user by verifying the provided username and password.
resizeImage()  : string
Resizes an image to the specified width and height.
saveFile()  : string
Saves an image file to the specified path with an optional prefix.
register()  : bool|string
Registers a new user in the system.
logout()  : void
Logs out the current user by clearing session variables and destroying the session.
shortenString()  : string
Shortens a given string to a specified maximum length, appending an ellipsis if the string is truncated.
registerValidation()  : array<string|int, mixed>|string
Validates the registration form input.
loginValidation()  : string
Validates the login process by checking CSRF token, input fields, and attempting login.
validateProfileUpdate()  : bool|User
Validates and updates the user's profile information.

Functions

continueSession()

Continues the current session, optionally authenticating the user and checking for admin privileges.

continueSession(bool $authenticate, string $redirect, bool $adminOnly) : void
Parameters
$authenticate : bool

If true, the function will check if the user is authenticated.

$redirect : string

The URL to redirect to after successful login if authentication is required.

$adminOnly : bool

If true, the function will check if the user has admin privileges.

Tags
throws
void

This function does not throw any exceptions.

example

// Continue session with authentication and admin check continueSession(true, '/dashboard', true);

// Continue session with authentication only continueSession(true, '/dashboard', false);

// Continue session without authentication or admin check continueSession(false, '', false);

login()

Logs in a user by verifying the provided username and password.

login(string $username, string $password) : bool
Parameters
$username : string

The username of the user attempting to log in.

$password : string

The password of the user attempting to log in.

Return values
bool

Returns true if the login is successful, otherwise false.

resizeImage()

Resizes an image to the specified width and height.

resizeImage(array<string|int, mixed> $image, int $width, int $height) : string
Parameters
$image : array<string|int, mixed>

An associative array containing the image file information. The array should have a "tmp_name" key with the path to the temporary file.

$width : int

The desired width of the resized image.

$height : int

The desired height of the resized image.

Return values
string

The resized image in PNG format as a binary string.

saveFile()

Saves an image file to the specified path with an optional prefix.

saveFile(string $image, string $filename[, string $prefix = "" ]) : string
Parameters
$image : string

The image data to be saved.

$filename : string

The name of the file to save the image as.

$prefix : string = ""

Optional. A prefix to add to the filename. Default is an empty string.

Return values
string

The path where the image file was saved.

register()

Registers a new user in the system.

register(string $username, string $password[, array<string|int, mixed>|bool $image = false ]) : bool|string
Parameters
$username : string

The username of the new user.

$password : string

The password of the new user.

$image : array<string|int, mixed>|bool = false

Optional. The image file for the user's avatar. Default is false.

Tags
throws
Exception

If there is an error during the user registration process.

Return values
bool|string

Returns true if the user was successfully registered, error message otherwise.

logout()

Logs out the current user by clearing session variables and destroying the session.

logout() : void

Redirects the user to the homepage after logging out.

shortenString()

Shortens a given string to a specified maximum length, appending an ellipsis if the string is truncated.

shortenString(string $inputString, int $maxLength) : string
Parameters
$inputString : string

The string to be shortened.

$maxLength : int

The maximum length of the returned string, including the ellipsis.

Return values
string

The shortened string, with an ellipsis appended if it was truncated.

registerValidation()

Validates the registration form input.

registerValidation(string $username, string $password, string $confpassword) : array<string|int, mixed>|string
Parameters
$username : string

The username input from the registration form.

$password : string

The password input from the registration form.

$confpassword : string

The confirmation password input from the registration form.

Return values
array<string|int, mixed>|string

An array with an error message if validation fails, or an empty string if validation passes.

loginValidation()

Validates the login process by checking CSRF token, input fields, and attempting login.

loginValidation(string $username, string $password) : string
Parameters
$username : string

The username provided by the user.

$password : string

The password provided by the user.

Return values
string

Returns an error message if validation fails, otherwise returns an empty string.

validateProfileUpdate()

Validates and updates the user's profile information.

validateProfileUpdate(User $user[, string|null $username = null ][, string|null $pw = null ][, string|null $confpw = null ][, array<string|int, mixed>|null $avatar = null ]) : bool|User
Parameters
$user : User

The user object to be updated.

$username : string|null = null

The new username, or null to keep the current username.

$pw : string|null = null

The new password, or null to keep the current password.

$confpw : string|null = null

The confirmation of the new password, or null to keep the current password.

$avatar : array<string|int, mixed>|null = null

The new avatar image data, or null to keep the current avatar.

Return values
bool|User

Returns false if no updates are provided, otherwise returns the updated user object.


        
On this page

Search results