The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

CAS::User - Creates user objects for accessing and modifying user data.

SYNOPSIS

  use CAS::User;

  my $user = CAS::User->new(%userinfo);
  die "Couldn't create new user" if $user == ERROR;
  
  my $user = CAS::User->load({ID => 1234567654});
  die "Couldn't load user." if $user == ERROR;
  

Or even better error reporting where appropriate:

  if (! ref $user && $user == ERROR) {
    my @errors = warning_notes();
        die "Failed to load user:\n\t" . join("\n\t",@errors) . "\n";
  } # if error

ABSTRACT

  Generate user objects for either new or existing users. The object returned
  is used to manage that users data, such as Password, Username, address, etc.

DESCRIPTION

Generate user objects for either new or existing users. The object returned is used to manage that users data, such as Password, Username, address, etc.

Currently only the CAS core Users and UserInfo tables are handled. Some handling of client user tables will be added once this is core part is functional. Set, get and validate methods are provided for the core tables, for the client tables only set and get are provided - it is the clients responsibility to validate their specific user information.

EXPORT

None by default.

new

Creates user object for a user not yet registered in the CAS system. Invoking this contructer will generate an object to use for validating new user information and entering a user in the database. When invoked it requires a Username and Password for the user, which will be validated. If those pass validation the user is registered in the database and the object is returned.

This object can now be used to validate additional user data and add it to the users record. It is highly recommended that you require the users First and Last names and any contact information you want be provided with the Username, Password, etc. and that you record all those (that validate) immediately after getting the user object back.

Please note

PARAMETERS:

Username: The Username the user will use for logging into the system. Usernames are therefor unique in the database.

Password: The Password the user will use when logging in. It is highly recommended you verify the Password before set it by having a user enter it twice and compare the two entries.

Email: An Email address for the user. This Email address will be used by the system to send Emails to the user for important system notifications, such as registration notification, systemwide administrative messages, etc. Since Email addresses are required to be unique within the system, this also discourages users from registering multiple times.

CLIENT: The client the user is registering from.

OPTIONS:

GROUP: The default initial group for the user. If not provided the default group for the client will be used, or, if that is not defined, the general default group as set in the CAS config file will be used.

load

Returns a user object which can be used to access and update user data. Will emit errors if fields that are expected not to be null (such as First Name) are.

PARAMETERS:

ID: The ID of the user.

or

Username: The users unique Username.

save

Saves the current state of the user.

!! Currently does not handle client table data !!

disable

Mark a user as diabled. Authentication will be denied.

enable

Reset disabled flag to 'No'.

Accessor, Mutator and Validation methods

Methods in this catagory are provided to access and alter the user data. The following list describes the user attributes which these methods all work on. Altering the values of user attributes with the set_ methods does not change them in the database. Call $user->save; to make any changes permanant. Further, calling a set_ method automatically invokes the validate_ method, so there is no need to validate before setting, unless you want to just catch and handle errors yourself (to regenerate a form with failed fields highlightes for instance).

Username [A-Za-z0-9_'-.@]{5,50}

A textual key uniquely indicating one user. This value is supplied by the user when they register and will function as the name with which they log in to the system. This is usually a short login handle, such as the common first initial last name combination (squinlan), however certain sites may wish to require users to usa they're email address as a username. While the system allows the use of an email address as a username, it is up to the client to modify the user registration interface appropriately.

Once registered this field may not be altered via set_Username.

Password [^;\s|><]{6,16}

A text string containing almost any plain ASCII non-whitespace text characters. The system can optionally require however that the password contain at least one upper case, one lower case, one number and one non-alphanumeric character by setting the optional STRICT parameter to true.

Please note that the plain password string is not stored in the database. Passwords are encrypted before they are stored in the databas.

Firstname [\w-' ]{2,20}

The users first name.

Lastname [\w-' ]{2,30}

The users last name.

Email [\w-.@]{6,50}

A valid email address for the user. The validation measures only examine the email to see if it looks valid. However when a new user registers an email is sent to the address provided with the from and reply-to fields set to the client administrators email address, so they should recieve bounce notifications.

Phone [\d-. )(]{3,20}

A contact phone number for the user.

Address1 [\w-.# ]{6,100}

The first address line to be used if a physical letter or package is to be sent to the user.

Address2 [\w-.# ]{6,100}

The second address line to be used if a physical letter or package is to be sent to the user.

City [\w-. ]{2,30}

The city for the users mailing address.

State [\w-.]{2,20}

The state for the users mailing address.

Country [\w-. ]{2,30}

The country for the users mailing address.

Zip [0-9-]{5,10}

The users zip code.

validate_

These methods make sure that the suplied information meets system requirements most of which are not enforced by the database. Such as forbidding certain characters or requiring a minimum length. If the specific data is determined to be 'invalid' then the FORBIDDEN staus code is returned.

All the set_ methods call validation before setting, so there is generally no need to call the validation yourself unless you are setting multiple fields at the same time and want them all handled in an all-or-nothing manner so want to pre-validate them.

TO DO

If client id is provided data from the client table should also be loaded into the user object.

Determine what additional address fields might be advisable. And if addresses should be placed in a separate table to allow users to have multiple addresses.

HISTORY

0.01

Original version; created by h2xs 1.22 with options

  -AXC
        -n
        CAS::User
0.2

Base adaption.

0.21

new, load, validate, get an set methods in place as well as stub new user email notification. Next come the tests.

0.22

Added tests for user object and disable/enable methods. Small additions to docs.

SEE ALSO

CAS

The home page for this project is perl-cas.org.

The mailing list for Perl CAS can be found at: http://mail.perl-cas.org/mailman/listinfo/developers_perl-cas.org

AUTHOR

Sean Quinlan, <gilant@gmail.com>

COPYRIGHT AND LICENSE

Copyright 2004-2005 by Sean Quinlan

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.