SYNOPSIS

  $ua = User::Simple::Admin->new($db, $user_table);

  $ua = User::Simple::Admin->create_rdbms_db_structure($db, $user_table,
      [$extra_sql]);
  $ua = User::Simple::Admin->create_plain_db_structure($db, $user_table,
      [$extra_sql]);
  $ok = User::Simple::Admin->has_db_structure($db, $user_table);

  %users = $ua->dump_users;

  $id = $ua->id($login);
  $login = $ua->login($id);

  $otherattrib = $user->otherattrib($id);

  $ok = $usr->set_login($id, $login);
  $ok = $usr->set_passwd($id, $passwd);
  $ok = $usr->set_otherattrib($id, $value);
  $ok = $usr->clear_session($id);

  $id = $ua->new_user(login => $login, passwd => $passwd,
        [otherattribute => $otherattribute]);

  $ok = $ua->remove_user($id);

DESCRIPTION

User::Simple::Admin manages the administrative part of the User::Simple modules - Please check User::Simple for a general overview of these modules and an explanation on what-goes-where.

User::Simple::Admin works as a regular administrator would: The module should be instantiated only once for all of your users' administration, if possible, and not instantiated once for each user (in contraposition to User::Simple, as it works from each of the users' perspective in independent instantiations).

Note also that User::Simple::Admin does b<not> perform the administrative user checks - It is meant to be integrated to your system, and it is your system which should carry out all of the needed authentication checks.

\s-1CONSTRUCTOR\s0

Administrative actions for User::Simple modules are handled through this Admin object. To instantiate it:

$ua = User::Simple::Admin->new($db, $user_table);

$db is an open connection to the database where the user data is stored.

$user_table is the name of the table that holds the users' data.

If we do not yet have the needed \s-1DB\s0 structure to store the user information, we can use this class method as a constructor as well:

$ua = User::Simple::Admin->create_rdbms_db_structure($db, $user_table, [$extra_sql]);

$ua = User::Simple::Admin->create_plain_db_structure($db, $user_table, [$extra_sql]);

The first one should be used if your \s-1DBI\s0 handle ($db) points to a real \s-1RDBMS\s0, such as PostgreSQL or MySQL. In case you are using a file-based \s-1DBD\s0 (such as DBD::XBase, \s-1DBD::DBM\s0, \s-1DBD::CVS\s0 or any other which does not use a real \s-1RDBMS\s0 for storage), use \*(C`User::Simple::Admin->create_plain_db_structure\*(C' instead. What is the difference? In the first case, we will create a table that has internal consistency checks - Some fields are declared \s-1NOT\s0 \s-1NULL\s0, some fields are declared \s-1UNIQUE\s0, and the user \s-1ID\s0 is used as a \s-1PRIMARY\s0 \s-1KEY\s0. This cannot, of course, be achieved using file-based structures, so the integrity can only be maintained from within our scripts.

This module does not provide the functionality to modify the created tables by adding columns to it, although methods do exist to access and modify the values stored in those columns (see the \*(L"\s-1CREATING\s0, \s-1QUERYING\s0 \s-1AND\s0 \s-1MODIFYING\s0 \s-1USERS\s0\*(R" section below), as many DBDs do not implement the \s-1ALTER\s0 \s-1TABLE\s0 \s-1SQL\s0 commands. It does, however, allow you to specify extra fields in the tables at creation time - If you specify a third extra parameter, it will be included as part of the table creation - i.e., you can create a User::Simple table with fields for the user's first and family names and a \s-1UNIQUE\s0 constraint over them this way:

$ua = User::Simple::Admin->create_rdbms_db_structure($db, $user_table, 'firstname varchar(30) NOT NULL, famname varchar(30) NOT NULL, UNIQUE (firstname,famname)');

Keep in mind that the internal fields are \*(C`id\*(C', \*(C`login\*(C', \*(C`passwd\*(C', \*(C`session\*(C' and \*(C`session_exp\*(C'. Don't mess with them ;-) Avoid adding any fields starting with \*(C`set_\*(C' or called as any method defined here, as they will become unreachable. And, of course, keep in mind what \s-1SQL\s0 construct does your \s-1DBD\s0 support.

If you add any fields with names starting with \*(C`adm_\*(C', they will be visible but not modifiable from within User::Simple - You will only be able to modify them from User::Simple::Admin.

\s-1QUERYING\s0 \s-1FOR\s0 \s-1DATABASE\s0 \s-1READINESS\s0

In order to check if the database is ready to be used by this module with the specified table name, use the \*(C`has_db_structure\*(C' class method:

$ok = User::Simple::Admin->has_db_structure($db, $user_table);

\s-1RETRIEVING\s0 \s-1THE\s0 \s-1SET\s0 \s-1OF\s0 \s-1USERS\s0

%users = $ua->dump_users;

Will return a hash with the data regarding the registered users with all of the existing \s-1DB\s0 fields, in the following form:

( $id1 => { login=>$login1, firstname=>$firstname1, famname=>$famname1 }, $id2 => { login=>$login2, firstname=>$firstname2, famname=>$famname2 }, (...) )

Of course, with the appropriate attributes. The internal attributes \*(C`id\*(C', \*(C`session\*(C' and \*(C`session_exp\*(C' will not be included in the resulting hashes (you have the \*(C`id\*(C' as the hash keys).

\s-1CREATING\s0, \s-1QUERYING\s0 \s-1AND\s0 \s-1MODIFYING\s0 \s-1USERS\s0

$id = $ua->new_user(login => $login, passwd => $passwd, [otherattribute => $otherattribute]);

Creates a new user with the specified data. Returns the new user's \s-1ID\s0. Only the login is mandatory (as it uniquely identifies the user), unless you have specified extra \s-1NOT\s0 \s-1NULL\s0 fields or constraints in the \s-1DB\s0. If no password is supplied, the account will be created, but no login will be allowed until one is supplied.

$ok = $ua->remove_user($id);

Removes the user specified by the \s-1ID\s0.

$id = $ua->id($login); $login = $ua->login($id);

$otherattrib = $user->otherattrib($id);

Get the value of each of the mentioned attributes. Note that in order to get the \s-1ID\s0 you can supply the login, every other method answers only to the \s-1ID\s0. In case you have the login and want to get the firstname, you can use \*(C`$ua-\*(C'firstname($ua->id($login));>

Of course, beware: if you request for a field which does not exist in your table, User::Simple will raise an error and die just as if an unknown method had been called.

$ok = $usr->set_login($id, $login); $ok = $usr->set_passwd($id, $passwd);

Modifies the requested attribute of the specified user, setting it to the new value. Except for the login, they can all be set to null values - If the password is set to a null or empty value, the account will be locked (that is, no password will be accepted). The internal attributes \*(C`id\*(C', \*(C`session\*(C' and \*(C`session_exp\*(C' cannot be directly modified (you have the \*(C`id\*(C' as the hash keys).

Just as with the accessors, if you have extra columns, you can modify them the same way:

$ok = $usr->set_otherattrib($id, $value);

i.e.

$ok = $usr->set_name($id, $name);

\s-1SESSIONS\s0

$ok = $usr->clear_session($id);

Removes the session which the current user had open, if any.

Note that you cannot create a new session through this module - The only way of creating a session is through the \*(C`ck_login\*(C' method of User::Simple.

DEPENDS ON

Digest::MD5

RELATED TO User::Simple::Admin…

User::Simple for the regular user authentication routines (that is, to use the functionality this module adimisters)

AUTHOR

Gunnar Wolf <[email protected]>

COPYRIGHT

Copyright 2005-2009 Gunnar Wolf / Instituto de Investigaciones Econo\*'micas \s-1UNAM\s0

This module is Free Software; it can be redistributed under the same terms as Perl.