Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.82 KB | None | 0 0
  1. mohan@ialeia:~/adwar/trunk/Adwar$ cat lib/Catalyst/Plugin/Authentication/Store/StylesApp/Backend.pm
  2. package Catalyst::Plugin::Authentication::Store::StylesApp::Backend;
  3.  
  4. use File::Spec;
  5. use XBase;
  6.  
  7. use strict;
  8. use warnings;
  9.  
  10. use Catalyst::Plugin::Authentication::Store::StylesApp::User;
  11. use Scalar::Util ();
  12.  
  13. sub new {
  14.   my ($class, $db_path) = @_;
  15.  
  16.   bless { db_path => $db_path }, $class;
  17. }
  18.  
  19. sub from_session {
  20.   my ($self, $c, $id) = @_;
  21.  
  22.   return $id if ref $id;
  23.  
  24.   $self->get_user($id);
  25. }
  26.  
  27. sub get_user {
  28.   my ($self, $id) = @_;
  29.  
  30.   my $mtable = XBase->new("name" =>
  31.                           File::Spec->catfile($self->{db_path}, "arcust01.DBF"))
  32.     or die XBase->errstr;
  33.  
  34.   my $cursor = $mtable->prepare_select_with_index(
  35.     [File::Spec->catfile($self->{db_path}, "ARCUST01.CDX"),'CUSTNO',],
  36.     "w_enabled", "w_password", "w_price", "w_matching", "w_viewnew",
  37.     "w_maxday", "w_images", "w_expires","w_vieword","w_viewsord","w_invamts",
  38.     "w_catalog","cust_pre","w_canorder","company","custno")
  39.       or die $mtable->errstr;
  40.  
  41.   # User in DBF
  42.   return unless $cursor->find_eq($id);
  43.  
  44.   my $cust_row = $cursor->fetch_hashref;
  45.  
  46.   # Enabled?
  47.   return unless $cust_row->{w_enabled};
  48.  
  49.   # check valid cust based on exact match off index search
  50.   return unless $cust_row->{custno} == $id;
  51.  
  52.   # Expired
  53.   my @time = localtime;
  54.   my $yyyymmdd = sprintf("%04d%02d%02d",$time[5]+1900,$time[4]+1,$time[3]);
  55.  
  56.   # As per KA on 2009-12-08 Don'r worry about expired
  57.   # return if ($yyyymmdd >= $cust_row->{w_expires});
  58.  
  59.   $cust_row->{cust_pre} = "!" unless $cust_row->{cust_pre};
  60.  
  61.   my $u_company = $cust_row->{company};
  62.   $u_company =~ s/\(.*//;
  63.  
  64. #  die $cust_row->{company};
  65.  
  66.   my $user = { password => $cust_row->{w_password}, roles => [],
  67.                company  => $u_company,
  68.                cust_pre => $cust_row->{cust_pre} };
  69.  
  70.   foreach my $role (qw/w_price w_matching w_viewnew w_vieword w_viewsord w_catalog w_canorder w_invamts/) {
  71.     push @{$user->{roles}}, $role if $cust_row->{$role};
  72.   }
  73.  
  74.   $user->{id} ||= $id;
  75.   $user->{store} ||= $self;
  76.  
  77.   return bless $user, "Catalyst::Plugin::Authentication::Store::StylesApp::User";
  78. }
  79.  
  80. # sub get_user {
  81. #   my ($self, $id) = @_;
  82.  
  83. #   my $user = { password => "foo", roles => [] };
  84.  
  85. #   if (Scalar::Util::blessed($user)) {
  86. #     $user->store($self);
  87. #     $user->id($id);
  88. #     return $user;
  89. #   }
  90. #   elsif (ref $user eq "HASH") {
  91. #     $user->{id} ||= $id;
  92. #     $user->{store} ||= $self;
  93. #     return bless $user, "Catalyst::Plugin::Authentication::User::Hash";
  94. #   }
  95. #   else {
  96. #     Catalyst::Exception->throw("The user '$id' is a reference of type "
  97. #                                . ref($user)
  98. #                                . " but should be a HASH" );
  99. #   }
  100.  
  101. #   return $user;
  102. # }
  103.  
  104. 1;
  105. mohan@ialeia:~/adwar/trunk/Adwar$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement