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

NAME

Nitesi::Account::Manager - Account Manager for Nitesi Shop Machine

SYNOPSIS

    $account = Nitesi::Account::Manager->new(provider_sub => \&account_providers, 
                                               session_sub => \&session);

    $account->init_from_session;

    $account->status(login_info => 'Please login before checkout',
                  login_continue => 'checkout');

    $account->login(username => 'shopper@nitesi.biz', password => 'nevairbe');

    $account->logout();

    if ($account->exists('shopper@nitesi.biz')) {
        $account->password(username => 'shopper@nitesi.biz', password => 'nevairbe');
    }

    $account->create(email => 'shopper@nitesi.biz');

    # use this with caution!
    $account->become('shopper@nitesi.biz');

DESCRIPTION

Nitesi's account manager transparently handles multiple providers for authentication, account data and permissions checks.

METHODS

init

Initializer called by instance class method.

providers

List with account providers.

init_from_session

Reads user information through session routine.

login

Perform login. Returns 1 in case of success and 0 in case of failure.

Leading and trailing spaces will be removed from username and password in advance.

logout

Perform logout.

Example:

        $account->logout();

create

Creates account and returns uid for the new account in case of success.

Example:

    $uid = $account->create(email => 'shopper@nitesi.biz');

The password is automatically generated unless you pass it to this method.

Example:

    $uid = $account->create(email => 'shopper@nitesi.biz',
                  password => 'nevairbe');

delete

Delete account.

Example:

        $account->delete('333');

uid

Retrieve user identifier of the current user, returns 0 if current user isn't authenticated.

Example:

        $account->uid();

username

Retrieve username of the current user. Returns empty string if current user isn't authenticated. If you want to retrieve other user username, use $account->load.

Example:

        $account->username();

roles

Retrieve roles of current user.

Example:

        $account->roles();

has_role

Returns true if user is a member of the given role.

Example:

        if ($account->has_role('admin') { print "Congratulations, you are the admin" };

permissions

Returns permissions as hash reference:

    $perms = $account->permissions;

Returns permissions as list:

    @perms = $account->permissions;

status

Helps you to redirect users properly on pages available only to authenticated users.

Example: Before login - Page available only if you are logged in (Step 1)

You are not logged in. You are on a page which is available only to those logged in. You set the message for users not logged in and url of the page where you send them after successful login.

        $account->status(login_info => 'Please login before checkout', login_continue => 'checkout');

Example: At Login page (Step 2)

You retrieve the login message to make clear to user why they need to login (to access the page from step 1)

        $account->status('login_info');

Example: After login (Step 3)

Retrieve the login_continue URL and send user to that URL (using redirect or something similar).

        $account->status('login_continue');

exists

Check whether account exists.

Example:

  if ($account->exists('shopper@nitesi.biz')) {
        print "Account exists\n";
  }

load

Returns account data for a given uid as hash.

Example:

        $account->load('333');

password

Changes password for current account:

    $account->password('nevairbe');

Changes password for other account:

    $account->password(username => 'shopper@nitesi.biz',
                    password => 'nevairbe');

acl

ACL (Access list) check, see ACL::Lite for details.

Example:

        if ( $account->acl( check => 'view_prices') {
                print "You can see prices";
        }

Example:

If you check multiple permissions at once, only one has to granted. The check will return the name of the first granted one in the list (left to right).

        if ( $account->acl( check => [ qw/admin luka/ ] ) {
                print "This is Luka's account. Only Luka and administrators can see it".
        }

value

Retrieve or set account data.

Example: Retrieve city

        $city = $account->value( 'city');

Example: Set city

        $city = $account->value( city => 'Ljubljana');

last_login

Returns time of last login (before the current one) in seconds since epoch or undef if provider doesn't supply this information.

become

Become any user you want:

    $acct->become('shopper@nitesi.biz');

Please use this method with caution.

Some parts of the system (DBI, LDAP,...) may choose not to support this method.

AUTHOR

Stefan Hornburg (Racke), <racke@linuxia.de>

LICENSE AND COPYRIGHT

Copyright 2011-2013 Stefan Hornburg (Racke) <racke@linuxia.de>.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.