User

Class to manipulate and authenticate users.  All details of user management, including checking authentication, should be done through this class.

Inherits

LnBlogObject

Summary
UserClass to manipulate and authenticate users.
Functions
existsDetermines if the object represents an existing, registered user.
profileUrlGet the URL to the user’s profile page.
exportVarsConvenience function to export relevant user data to a template.
checkPasswordChecks if a password is valid for the current user.
saveSave changes to user data.
passwordSet or return the user’s password>
usernameSet or return the username.
nameSet or return the user’s long name.
displayNameReturns a name to display.
emailSet or return the user’s e-mail address.
homepageSet or return the user’s homepage.
groupsLists the groups to which the user belongs.
defaultGroupGets or sets the default group for this user.
addToGroupAdds the user to the specified group.
loginLogs the user in.
logoutLogs the user out and destroys login tokens.
checkLoginChecks tokens to determine if the user is logged in.
isAdministratorDetermines if the user is the system administrator.

Functions

exists

function exists($uname = false)

Determines if the object represents an existing, registered user.

Returns

True if the user exists, false otherwise.

profileUrl

public function profileUrl($url =  null)

Get the URL to the user’s profile page.

Parameters

urlThe new value to set.  If missing, just return current value.

exportVars

function exportVars($tpl)

Convenience function to export relevant user data to a template.  Sets the username, full name, e-mail, homepage, and display name in template variables USER_ID, USER_NAME, USER_EMAIL, USER_HOMEPAGE, and USER_DISPLAY_NAME respectively.

Parameters

tplThe template to put the data in, passed by reference.

checkPassword

function checkPassword($pass)

Checks if a password is valid for the current user.

Parameters

passThe password to check.

Returns

True if the password is correct, false owtherwise.

save

function save()

Save changes to user data.

Returns

True if the changes were successfully saved, false otherwise.

password

function password($pwd = false)

Set or return the user’s password>

Parameters

pwdOptional password to set.

Returns

If pwd is false, return the user’s password hash.  Otherwise, a new password is set and there is no return value.

username

function username($uid = false)

Set or return the username.

Parameters

uidOptional username to set.

Returns

The username if uid is false, otherwise the username is set and there is no return value.

name

function name($nm = false)

Set or return the user’s long name.

Parameters

nmOptional name to set.

Returns

The user’s full name if nm is false, otherwise the name is set and there is no return value.

displayName

function displayName()

Returns a name to display.  If a full name is defined, it uses that.  Otherwise, it reverts to the username.

Returns

A string contianing either the username or full name.

email

function email($mail = false)

Set or return the user’s e-mail address.

Parameters

mailOptional e-mail to set.

Returns

The user’s e-mail address if mail is false, otherwise the address is set and there is no return value.

homepage

function homepage($url = false)

Set or return the user’s homepage.

Parameters

urlOptional URL to set as the homepage.

Returns

The user’s homepage URL if url is false, otherwise the homepage is set and there is no return value.

groups

function groups()

Lists the groups to which the user belongs.

Returns

An array of group names to which the user belongs.

defaultGroup

function defaultGroup($val = false)

Gets or sets the default group for this user.  This is the group to which all of the user’s creations will belong by default.

Parameters

ValIf set, the value to which the default group should be changed.

Returns

A string with the name of the group.

addToGroup

function addToGroup($groupname)

Adds the user to the specified group.

Parameters

groupnameThe name of the group.

Returns

True on success, false on failure.

login

function login($pwd)

Logs the user in.  Note that there are two login methods available, with the one used being determined by the AUTH_USE_SESSION configuration constant.

Parameters

pwdThe password used to log in.

Returns

False if the authentication fails, true otherwise.

logout

function logout()

Logs the user out and destroys login tokens.  Note that this is also subject to AUTH_USE_SESSION

checkLogin

function checkLogin($uname = false)

Checks tokens to determine if the user is logged in.

Parameters

unameOptional username to check.

Returns

True if the user has valid login tokens, false otherwise.

isAdministrator

function isAdministrator()

Determines if the user is the system administrator.

Returns

True if the username is the same as that of the system administrator, false otherwise.  Note that the system administrator’s username is controlled by the ADMIN_USER configuration constant.

function exists($uname = false)
Determines if the object represents an existing, registered user.
public function profileUrl($url =  null)
Get the URL to the user’s profile page.
function exportVars($tpl)
Convenience function to export relevant user data to a template.
function checkPassword($pass)
Checks if a password is valid for the current user.
function save()
Save changes to user data.
function password($pwd = false)
Set or return the user’s password>
function username($uid = false)
Set or return the username.
function name($nm = false)
Set or return the user’s long name.
function displayName()
Returns a name to display.
function email($mail = false)
Set or return the user’s e-mail address.
function homepage($url = false)
Set or return the user’s homepage.
function groups()
Lists the groups to which the user belongs.
function defaultGroup($val = false)
Gets or sets the default group for this user.
function addToGroup($groupname)
Adds the user to the specified group.
function login($pwd)
Logs the user in.
function logout()
Logs the user out and destroys login tokens.
function checkLogin($uname = false)
Checks tokens to determine if the user is logged in.
function isAdministrator()
Determines if the user is the system administrator.
A base object which is event-aware, i.e.
Use sessions in authentication instead of just cookies.
Username of site administrator.
Close