Users Management
The LiveUser_Admin package allows you to manage users to be used within LiveUser, in both the authentication and permission containers. It provides a series of methods to interact with the «liveuser_users» table and the «liveuser_perm_users».
The example 1 provided with this PEAR package should help you starting quite quickly.
There are a few methods for users management:
- addUser: to add a user to the list of users
- updateUser: to modify a user in the list of users
- removeUser: to remove a user from the list of users
- getUsers: to retrieve a list of users
We'll start by adding a user, then updating it. We can then list all users in the table before deleting a user.
Here is the full example :
Add a user (addUser)
function addUser($data)
Parameter(s)
This method takes 1 parameter: an array with a pair key/value of all fields in the «liveuser_users» including a number representing the type of user:
LIVEUSER_ANONYMOUS_TYPE_ID :lowest user level: anonymousLIVEUSER_USER_TYPE_ID :highest user levelLIVEUSER_ADMIN_TYPE_ID :lowest admin levelLIVEUSER_AREAADMIN_TYPE_ID :area admin level (lookup area admin)LIVEUSER_SUPERADMIN_TYPE_ID :all rights grantedLIVEUSER_MASTERADMIN_TYPE_ID :highest admin level
In the easiest way, you may just provide the user data without user id. In this case, the method will automatically allocate a user id (using the «liveuser_users_seq» and «liveuser_perm_users» tables).
Otherwise, you may provide the user data including the ids.
Return value
This method returns:
- «false» in case of error
- the new perm_user_id in case of success
Example
To add a user:
...
$handle = 'test user';
$password = 'test';
$email = 'test.user@mycompany.com';
$is_active = '1';
$user_type = LIVEUSER_USER_TYPE_ID; // highest user level
$data = array('handle' => $handle,
'passwd' => $password,
'email' => $email,
'is_active' => $is_active,
'perm_type' => $user_type
);
$userId = $LUA->addUser($data);
...
This gives the following result:

Update a user (updateUser)
function updateUser($data, $perm_user_id)
Parameter(s)
This method takes 2 parameters:
- an array with key/value containing the new value(s), which may include the permission type (see above)
- the perm_user_id of the user to be modified
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
...
$new_email = 'updated.name@mycompany.com';
// search for the user based on handle
$handle = 'test user';
$filter = array('container' => 'auth',
'filters' => array('handle' => $handle));
$user_id = $LUA->getUsers($filter);
echo 'Update user «' . $handle . '» with a new email « ' . $new_email . '»';
// update data
$data = array('email' => $new_email);
$updatedUser = ->updateUser($data, $user_id[0]['perm_user_id']);
...
This gives the following result:

List users (getUsers)
function getUsers($filter = array())
Parameter(s)
This method takes 1 parameter:
- with at least the container: whether the authentication (= «auth») or the permission (= «perm») containers should be searched.
- then the search criteria
Return value
This method returns:
- «false» in case of error
- an array with data corresponding to the selection, in case of success. The array may be empty or not.
Example
Get the list of all (auth) users:
...
$users = $LUA->getUsers(array('container' => 'auth'));
...
Get a filtered list of users:
...
$filter = array('container' => 'auth',
'filters' => array('is_active' => 0));
$users = $LUA->getUsers($filter);
...
This gives the following result:

Remove a user (removeUser)
function removeUser($perm_user_id)
The user is removed from the authentication and permission containers. All rights that may have been granted to this user are deleted as well. Finally users are removed from the groups they belong to.
Parameter(s)
This method takes 1 parameter:
- the perm_user_id of the user to be deleted
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
...
// find the perm_user_id based on the handle
$handle = 'test user';
$filter = array('container' => 'auth',
'filters' => array('handle' => $handle));
$users = $LUA->getUsers($filter);
// delete the user
$removedUser = $LUA->removeUser($users[0]['perm_user_id']);
...
This gives the following result:

Getting Information on the last Error (getErrors)
function getErrors()
In case a function returns «false», it means that it has encountered a problem. You can get information on this error by calling this method.
Parameter(s)
This method takes no parameter.
Return value
This method returns:
- the error information
Example
...
$data = array('handle' => $handle,
'passwd' => $password,
'email' => $email,
'is_active' => $is_active,
'perm_type' => $user_type
);
$userId = $LUA->addUser($data);
if ($userId === false)
{
echo 'Add_user: error on line: '.__LINE__;
print_r($LUA->getErrors());
}
else
{
echo 'User with perm_user_id ' . $userId . ' created';
}
...



