User
LnBlogObject
User

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

Inherits

LnBlogObject

Functions
exists
public function exists(
$unamefalse
)

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
url

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

getProfileUrl
public function getProfileUrl()

Get the configured or default URL for the user's profile.

exportVars
public 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
tpl

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

checkPassword
private function checkPassword(
$pass
)

Checks if a password is valid for the current user.

Parameters
pass

The password to check.

Returns

True if the password is correct, false owtherwise.

createPasswordReset
public function createPasswordReset()

Create a passoword reset code for the user.

Returns

String containing the reset code.

verifyPasswordReset
public function verifyPasswordReset(
$code
)

Checks that a supplied password reset code is valid.

Parameters
code

String containing the reset code to validate

Returns

True if the code is acceptable, false otherwise.

invalidatePasswordReset
public function invalidatePasswordReset(
$code
)

Deletes the record of a particular password reset code.  This is intended to be called after a code is used successfully.

Parameters
code

String containing the code to invalidate.

save
public function save()

Save changes to user data.

Returns

True if the changes were successfully saved, false otherwise.

password
public function password(
$pwdfalse
)

Set or return the user's password>

Parameters
pwd

Optional 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
public function username(
$uidfalse
)

Set or return the username.

Parameters
uid

Optional username to set.

Returns

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

name
public function name(
$nmfalse
)

Set or return the user's long name.

Parameters
nm

Optional 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
public 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
public function email(
$mailfalse
)

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

Parameters
mail

Optional 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
public function homepage(
$urlfalse
)

Set or return the user's homepage.

Parameters
url

Optional 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.

addToGroup
public function addToGroup(
$groupname
)

Adds the user to the specified group.

Parameters
groupname

The name of the group.

Returns

True on success, false on failure.

login
public 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
pwd

The password used to log in.

time

Current time, injectable for testing purposes.

Returns

False if the authentication fails, true otherwise.

logout
public function logout()

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

checkLogin
public function checkLogin(
$unamefalse
)

Checks tokens to determine if the user is logged in.

Parameters
uname

Optional username to check.

Returns

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

isAdministrator
public 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.

enableCookies
public function enableCookies(
$enabled
)

Used primarily for testing, sets whether cookies actually get set.

loadUserCredentials
private function loadUserCredentials()

Load the user's password and any metadata.