User Functions

User Functions

The user functions allow you to interact with your site's users and user accounts.

User Class File:

The User Class File is located in the inc directory. The user class functions are located in the class.user.php file.


Function: logUserIn

Logs a user in to the Rusnak CMS

Parameters:

  • (string) Username
  • (string) Password
  • (string) Remember user by setting cookies. User will be remembered if this is passed yes, all other values will not remember user. This field is required, even if you pass in a blank string.

Return Value:

Returns true on successful login, false on failure.

Example Usage:

$loginSuccess = $this->db->logUserIn("Admin", "Admin123", ""); if($loginSuccess == true){ echo "User Logged In!"; } else { echo "Wrong username or password!; }

Function: registerUser

Registers a user in the database

Parameters:

  • (string) Username
  • (string) Password
  • (string) Password Confirmation
  • (string) Email Address

Return Value:

Returns string value of success on successful registration, or an array of errors on failure.


Function: checkUserLoggedIn

Checks if there is a user currently logged in

Parameters:

  • NONE

Return Value:

Returns string value of the current logged in user on success, or false if there is no logged in user.

Example Usage:

$user = $this->user->checkUserLoggedIn(); if($user != false){ echo "Username: ".$user; }

Function: logout

Logs the current user out by clearing session and cookies

Parameters:

  • NONE

Return Value:

This function does not return a value.


Function: generateRandomString

Generates a random string of letters and numbers, suitable for making a password salt

Parameters:

  • (int) Length of string

Return Value:

Returns a string of given length.


Function: hasPermission

Checks if the given user has permission to perform a given action

Parameters:

  • (string) Permission user wishes to perform
  • (string) Username of user attempting action

Return Value:

Returns true if the user has permission to perform the action, false otherwise.

Example Usage:

// Check if a user has access to the Admin Control Panel $permissionStatus = $this->user->hasPermission("canAdmin", "Admin"); if($permissionStatus == true){ // Something that only admins can do } else { echo "You do not have permission to perform this action."; }

Function: getUsergroupIDs

Gets the usergroup ids of all of the usergroups that the user belongs to.

Parameters:

  • (int) User ID of user to check
  • (bool) (optional) Whether or not to run database secure function on user id.

Return Value:

Returns an array of the usergroups the user is in.


Function: getGroupNameFromID

Gets the name of a usergroup given a group id

Parameters:

  • (int) Group ID to check

Return Value:

Returns string of usergroup name, or a blank string if group does not exist.

Example Usage:

// Returns "Administrator" $group = $this->user->getGroupNameFromID(1);

Function: makePassword

Given a password and a salt, makes a password that can be used for a user account

Parameters:

  • (string) Password
  • (string) Salt

Return Value:

Returns string of a hashed password.