Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mohan@ialeia:~/adwar/trunk/Adwar$ cat lib/Catalyst/Plugin/Authentication/Store/StylesApp/Backend.pm
- package Catalyst::Plugin::Authentication::Store::StylesApp::Backend;
- use File::Spec;
- use XBase;
- use strict;
- use warnings;
- use Catalyst::Plugin::Authentication::Store::StylesApp::User;
- use Scalar::Util ();
- sub new {
- my ($class, $db_path) = @_;
- bless { db_path => $db_path }, $class;
- }
- sub from_session {
- my ($self, $c, $id) = @_;
- return $id if ref $id;
- $self->get_user($id);
- }
- sub get_user {
- my ($self, $id) = @_;
- my $mtable = XBase->new("name" =>
- File::Spec->catfile($self->{db_path}, "arcust01.DBF"))
- or die XBase->errstr;
- my $cursor = $mtable->prepare_select_with_index(
- [File::Spec->catfile($self->{db_path}, "ARCUST01.CDX"),'CUSTNO',],
- "w_enabled", "w_password", "w_price", "w_matching", "w_viewnew",
- "w_maxday", "w_images", "w_expires","w_vieword","w_viewsord","w_invamts",
- "w_catalog","cust_pre","w_canorder","company","custno")
- or die $mtable->errstr;
- # User in DBF
- return unless $cursor->find_eq($id);
- my $cust_row = $cursor->fetch_hashref;
- # Enabled?
- return unless $cust_row->{w_enabled};
- # check valid cust based on exact match off index search
- return unless $cust_row->{custno} == $id;
- # Expired
- my @time = localtime;
- my $yyyymmdd = sprintf("%04d%02d%02d",$time[5]+1900,$time[4]+1,$time[3]);
- # As per KA on 2009-12-08 Don'r worry about expired
- # return if ($yyyymmdd >= $cust_row->{w_expires});
- $cust_row->{cust_pre} = "!" unless $cust_row->{cust_pre};
- my $u_company = $cust_row->{company};
- $u_company =~ s/\(.*//;
- # die $cust_row->{company};
- my $user = { password => $cust_row->{w_password}, roles => [],
- company => $u_company,
- cust_pre => $cust_row->{cust_pre} };
- foreach my $role (qw/w_price w_matching w_viewnew w_vieword w_viewsord w_catalog w_canorder w_invamts/) {
- push @{$user->{roles}}, $role if $cust_row->{$role};
- }
- $user->{id} ||= $id;
- $user->{store} ||= $self;
- return bless $user, "Catalyst::Plugin::Authentication::Store::StylesApp::User";
- }
- # sub get_user {
- # my ($self, $id) = @_;
- # my $user = { password => "foo", roles => [] };
- # if (Scalar::Util::blessed($user)) {
- # $user->store($self);
- # $user->id($id);
- # return $user;
- # }
- # elsif (ref $user eq "HASH") {
- # $user->{id} ||= $id;
- # $user->{store} ||= $self;
- # return bless $user, "Catalyst::Plugin::Authentication::User::Hash";
- # }
- # else {
- # Catalyst::Exception->throw("The user '$id' is a reference of type "
- # . ref($user)
- # . " but should be a HASH" );
- # }
- # return $user;
- # }
- 1;
- mohan@ialeia:~/adwar/trunk/Adwar$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement