final class UserService

Provides functions for managing users.

Methods

static void
deleteIfAllowed(int $id, bool $unlink = false)

Deletes user if not admin and unlinks profile images if $unlink is set to true.

static array
deleteProfileImage(Input $request)

Deletes profile image

static void
ensureAuthenticatedUser(Users $user)

Acts as safeguard to ensure incorrect user is not updated.

static void
handleProfileImages(Users $user, Uploads|null $uploads, string|null $sortedImages)

Uploads and sorts profile images.

static void
sendWhenSetToInactive(Users $user, bool $shouldSendEmail = false)

Sends E-mail to user when account is deactivated as appropriate.

static void
sendWhenSetToResetPW(Users $user, bool $shouldSendEmail = false)

Sends E-mail to user when reset_password flag is set as appropriate.

static bool
toggleAccountStatus(Users $user, Input $request, int|null $currentInactive = null)

Assist in toggling inactive field. Returns boolean value to determine if E-mail should be sent. To properly test if E-mail should be sent get value of $user->inactive before post.

static bool
toggleResetPassword(Users $user, Input $request, int|null $currentReset = null)

Assist in toggling reset_password field.

static Users|bool
updatePassword(Users $user, Input $request)

Updates user's password

Details

at line 29
static void deleteIfAllowed(int $id, bool $unlink = false)

Deletes user if not admin and unlinks profile images if $unlink is set to true.

Parameters

int $id

The id for user we want to delete.

bool $unlink

Determines if profile images are deleted.

Return Value

void

at line 46
static array deleteProfileImage(Input $request)

Deletes profile image

Parameters

Input $request

The request for deleting image.

Return Value

array

JSON response array.

at line 62
static void ensureAuthenticatedUser(Users $user)

Acts as safeguard to ensure incorrect user is not updated.

Parameters

Users $user

The user object to test.

Return Value

void

at line 79
static void handleProfileImages(Users $user, Uploads|null $uploads, string|null $sortedImages)

Uploads and sorts profile images.

Parameters

Users $user

The user whose profile images we want to manage.

Uploads|null $uploads

The Uploads object or profile image upload.

string|null $sortedImages

Order of sorted images.

Return Value

void

at line 96
static void sendWhenSetToInactive(Users $user, bool $shouldSendEmail = false)

Sends E-mail to user when account is deactivated as appropriate.

Parameters

Users $user

The user we will send E-mail to.

bool $shouldSendEmail

Sends E-mail when true.

Return Value

void

at line 111
static void sendWhenSetToResetPW(Users $user, bool $shouldSendEmail = false)

Sends E-mail to user when reset_password flag is set as appropriate.

Parameters

Users $user

The user we will send E-mail to.

bool $shouldSendEmail

Sends E-mail when true.

Return Value

void

at line 129
static bool toggleAccountStatus(Users $user, Input $request, int|null $currentInactive = null)

Assist in toggling inactive field. Returns boolean value to determine if E-mail should be sent. To properly test if E-mail should be sent get value of $user->inactive before post.

Parameters

Users $user

The user whose status we want to set.

Input $request

The request.

int|null $currentInactive

Value of $user->inactive before post.

Return Value

bool

true if we want to send mail and otherwise false.

at line 144
static bool toggleResetPassword(Users $user, Input $request, int|null $currentReset = null)

Assist in toggling reset_password field.

Parameters

Users $user

The user whose status we want to set.

Input $request

The request.

int|null $currentReset

Value of $user->reset_password before post.

Return Value

bool

1 if reset_password is 'on', otherwise we return 0.

at line 156
static Users|bool updatePassword(Users $user, Input $request)

Updates user's password

Parameters

Users $user

The user whose password we want to update.

Input $request

The request.

Return Value

Users|bool

True if password is updated, otherwise false