Andrew Maltsev > XAO-Web-1.07 > XAO::DO::Web::IdentifyUser

Download:
XAO-Web-1.07.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 2.001   Source  

NAME ^

XAO::DO::Web::IdentifyUser - class for user identification and verification

SYNOPSYS ^

Currently is only useful in XAO::Web site context.

DESCRIPTION ^

!!XXX!!TODO!! - document key_list_uri and multi-key logons in general!

IdentifyUser class is used for user identification and verification purposes. In 'login' mode it logs a user in while in 'logout' mode, it logs a user out. In 'check' mode it determines the identification status of the user using cookies.

Possible user identification status are:

The 'IdentifyUser' class takes the following parameters:

The 'IdentifyUser' class relies on some site configuration values. These values are available in the form of a reference to a hash obtained as follows:

 my $config=$page->siteconfig->get('identify_user');

where $page is a 'Page' object. The keys of such a hash correspond to the 'type' parameter of the 'IdentifyUser' class. An example of a $config hash with all required parameters is presented below:

 customer => { 
    list_uri            => '/Customers', 
    id_cookie           => 'id_customer',    
    id_cookie_expire    => 126230400,       # (seconds) optional,
                                            # default is 10 years
    id_cookie_type      => 'name',          # optional, see below
    user_prop           => 'email',         # optional, see below    
    pass_prop           => 'password', 
    pass_encrypt        =>  'md5',          # optional, see below
    vf_key_prop         => 'verify_key',    # optional, see below 
    vf_key_cookie       => 'key_customer',  # optional, see below
    vf_time_prop        => 'verify_time',   # time of last verification
    vf_expire_time      => '600',           # seconds
    cb_uri              => 'IdentifyUser/customer' # optional
 }
list_uri

URI of users list (see XAO::FS and XAO::DO::FS::List).

id_cookie

Name of cookie that IdentifyUser sets to identificate the user in the future

id_cookie_expire

Expiration time for the identification cookie (default is 4 years).

id_cookie_type

Can be either 'name' (default) or 'id'. Determines what is stored in the cookie on the client browser's side -- in 'name' mode it stores user name, just the way it is entered in the login form, in 'id' mode the internal id (container_key) of the user object is stored.

Downside to storing names is that some browsers fail to return exactly the stored value if it had international characters in the name. Downside to storing IDs is that you expose a bit of internal structure to the outside world, usually its harmless though.

If 'user_prop' is not used then it does not matter, as the name and id are the same thing.

user_prop

Name attribute of a user object. If there is no 'user_prop' parameter in the configuration it is assumed that user ID is the key for the given list.

An interesting capability is to specify name as a URI style path, for instance if a member has many alternative names that all can be used to log-in and these names are stored in a list called Nicknames on each member object, then the following might be used:

 user_prop => 'Nicknames/nickname'

See below for how to access deeper objects and ids (the object in 'Nicknames' list in that case).

pass_prop

Password attribute of user object.

pass_encrypt

Encryption method for the password. Available values are 'plaintext' (not encrypted at all, default) and 'md5' (MD5 one way hash encryption).

vf_key_prop

The purpose of two optional parameters 'vf_key_cookie' and 'vf_key_prop' is to limit verification to just one computer at a time. When these parameters are present in the configuration on login success 'IdentifyUser' object generates random key and store it into user's profile anf create a cookie named according to 'vf_key_cookie' with the value of the generated key.

vf_key_cookie

Temporary verifiction key cookie.

vf_time_prop

Attribute of user object which stores the time of latest verified access.

vf_expire_time

Time period for which user remains verified.

Please note, that the cookie with the customer key will be set to expire in 10 years and actual expiration will only be checked using the content of 'vf_time_prop' field value. The reason for such behavior is that many (if not all) versions of Microsoft IE have what can be considered a serious bug -- they compare the cookie expiration time to the local time on the computer. And therefore if customer computer is accidentally set to some future date the cookie might expire immediately and prevent this customer from logging into the system at all. Most (if not all) versions of Netscape and Mozilla do not have this problem.

Therefore, when possible we do not trust customer's computer to measure time for us and do that ourselves.

cb_uri

URI of clipboard where IdentifyUser stores identification and verification information about user and makes it globally available.

RESULTS ^

In addition to displaying the correct template, results of user verification or identification are stored in the clipboard. Base clipboard location is determined by 'cb_uri' configuration parameter and defaults to '/IdentifyUser/TYPE', where TYPE is the type of user.

Parameters that are stored into the clipboard are:

id

The internal ID of the use object (same as returned by container_key() method on the object).

name

Name as used in the 'login' mode. If 'user_prop' configuration parameter is not used then it is always the same as 'id'.

object

Reference to the user object loaded from the database.

verified

This is only set when user has 'verified' status.

Additional information will also be stored if 'user_prop' refers to deeper objects. For example, if user_prop is equal to 'Nicknames/nickname' then it is assumed that there is a list inside of user objects called Nicknames and there is a property in that list called 'nickname'. It is also implied that the 'nickname' is unique throughout all objects of its class.

Information that gets stored in the clipboard in that case is:

list_prop

Name of the list property of the user object that is used in 'user_prop'. In our example it will be 'Nicknames'.

Nicknames (only for the example above)

Name of the list property is used to store a hash containing 'id', 'object' and probably 'list_prop' for the next object in the 'user_prop' path (although in practice it is hard to imagine a situation where more then one level is required).

EXAMPLES ^

Now, let us look at some examples that show how each mode works.

LOGIN MODE

 <%IdentifyUser mode="login"
   type="customer"
   username="<%CgiParam param="username" %>
   password="<%CgiParam param="password" %>
   anonymous.path="/bits/login.html"
   verified.path="/bits/thankyou.html"
 %>

LOGOUT MODE

 <%IdentifyUser mode="logout"
   type="customer"
   anonymous.path="/bits/thankyou.html"
   identified.path="/bits/thankyou.html"
   hard_logout="<%CgiParam param="hard_logout" %>"
 %>

CHECK MODE

 <%IdentifyUser mode="check"
   type="customer"
   anonymous.path="/bits/login.html"
   identified.path="/bits/order.html"
   verified.path="/bits/order.html"
 %>

METHODS ^

check_mode (%)

Checks operation mode and redirects to a method accordingly.

check ()

Checks identification/verification status of the user.

To determine identification status, first check clipboard to determine if there is such object present. If so, then that object identifies the user.

If not, then depending on 'id_cookie_type' parameter (that defaults to 'name') check whether there is an identification cookie or key cookie and if so, perform a search for object in database. If this search yields a positive result, the user's status is 'identified' and an attempt to verify user is made, otherwise the status is 'anonymous'.

Identification by key only works when keys are stored in a separate list.

Once identity is established, to determine verification status, first check the clipboard to determine if there is a 'verified' flag set. If so, then the user's status is 'verified'. If not, check whether the difference between the current time and the time of the latest visit is less than vf_expire_time property. If so, the user status considered 'verified', a new time is stored.

If optional 'vf_key_prop' and 'vf_key_cookie' parameters are present in the configuration then one additional check must be performed before changing status to 'verified' - the content of the key cookie and apropriate field in the user profile must match.

display_results ($$;$)

Displays template according to the given status. Third optinal parameter may include the content of 'ERRSTR'.

find_user ($;$)

Searches for the user in the list according to the configuration:

 my $data=$self->find_user($config,$username);

Sets the same parameters in the returned hash as stored in the clipboard except 'verified'.

login ()

Logs in user. Saves current time to vf_time_prop database field. Generates pseudo unique key and saves its value into either vf_key_prop or creates a record in key_list_uri. Sets identification cookies accordingly.

There is a parameter named 'force' that allows to log in a user without checking the password. One should be very careful not to abuse this possibility! For security reasons 'force' will only have effect when there is no 'password' parameter at all.

login_check ()

A method that can be overriden in a derived object to check additional conditions for letting a user in. Gets the following arguments as its input:

 name       => name of user object
 password   => password
 object     => reference to a database object containing user info
 type       => user type

This method is called after all standard checks - it is guaranteed that user object exists and password matches its database record.

Must return empty string on success or suggested error message on failure. That error message will be passed in ERRSTR argument to the templates.

logout ()

Logs out user. Resetting vf_time_prop database field and clearing identification cookie (for hard logout mode). Set user status to 'anonymous' (hard logout mode) or 'identified'.

Will install data into clipboard in soft logout mode just the same way as mode='check' does.

verify_check (%)

Overridable method that is called from check() after user is identified and verified. May check for additional conditions, such as privilege level or something similar.

Gets the following arguments as its input:

 args       => arguments as passed to the check() method
 object     => reference to a database object containing user info
 type       => user type

Must return empty string on success.

EXPORTS ^

Nothing

AUTHOR ^

Copyright (c) 2005 Andrew Maltsev

<am@ejelta.com> -- http://ejelta.com/xao/

Copyright (c) 2001-2004 XAO Inc.

Andrew Maltsev <am@ejelta.com>, Marcos Alves <alves@xao.com>, Ilya Lityuga <ilya@boksoft.com>.

SEE ALSO ^

Recommended reading:

XAO::Web, XAO::DO::Web::Page, XAO::FS.

syntax highlighting: