Nitesi::Account::Manager - Account Manager for Nitesi Shop Machine
$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');
Nitesi's account manager transparently handles multiple providers for authentication, account data and permissions checks.
Initializer called by instance class method.
List with account providers.
Reads user information through session routine.
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.
Perform logout.
Example:
$account->logout();
Creates account and returns uid for the new account in case of success.
$uid = $account->create(email => 'shopper@nitesi.biz');
The password is automatically generated unless you pass it to this method.
$uid = $account->create(email => 'shopper@nitesi.biz', password => 'nevairbe');
Delete account.
$account->delete('333');
Retrieve user identifier of the current user, returns 0 if current user isn't authenticated.
$account->uid();
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.
$account->username();
Retrieve roles of current user.
$account->roles();
Returns true if user is a member of the given role.
if ($account->has_role('admin') { print "Congratulations, you are the admin" };
Returns permissions as hash reference:
$perms = $account->permissions;
Returns permissions as list:
@perms = $account->permissions;
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');
Check whether account exists.
if ($account->exists('shopper@nitesi.biz')) { print "Account exists\n"; }
Returns account data for a given uid as hash.
$account->load('333');
Changes password for current account:
$account->password('nevairbe');
Changes password for other account:
$account->password(username => 'shopper@nitesi.biz', password => 'nevairbe');
ACL (Access list) check, see ACL::Lite for details.
if ( $account->acl( check => 'view_prices') { print "You can see prices"; }
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". }
Retrieve or set account data.
Example: Retrieve city
$city = $account->value( 'city');
Example: Set city
$city = $account->value( city => 'Ljubljana');
Returns time of last login (before the current one) in seconds since epoch or undef if provider doesn't supply this information.
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.
Stefan Hornburg (Racke), <racke@linuxia.de>
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.
To install Nitesi, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nitesi
CPAN shell
perl -MCPAN -e shell install Nitesi
For more information on module installation, please visit the detailed CPAN module installation guide.