add the small FS::CurrentUser::BootstrapUser class for... surprise... bootstrapping
[freeside.git] / FS / FS / CurrentUser.pm
1 package FS::CurrentUser;
2
3 use vars qw($CurrentUser $upgrade_hack);
4
5 #not at compile-time, circular dependancey causes trouble
6 #use FS::Record qw(qsearchs);
7 #use FS::access_user;
8
9 $upgrade_hack = 0;
10
11 =head1 NAME
12
13 FS::CurrentUser - Package representing the current user
14
15 =head1 SYNOPSIS
16
17 =head1 DESCRIPTION
18
19 =cut
20
21 sub load_user {
22   my( $class, $user ) = @_; #, $pass
23
24   if ( $upgrade_hack ) {
25     return new FS::CurrentUser::BootstrapUser;
26   }
27
28   #return "" if $user =~ /^fs_(queue|selfservice)$/;
29
30   #not the best thing in the world...
31   eval "use FS::Record qw(qsearchs);";
32   die $@ if $@;
33   eval "use FS::access_user;";
34   die $@ if $@;
35
36   $CurrentUser = qsearchs('access_user', {
37     'username' => $user,
38     #'_password' =>
39   } );
40
41   die "unknown user: $user" unless $CurrentUser; # or bad password
42
43   $CurrentUser;
44 }
45
46 =head1 BUGS
47
48 Creepy crawlies
49
50 =head1 SEE ALSO
51
52 =cut
53
54 package FS::CurrentUser::BootstrapUser;
55
56 sub new {
57   my $proto = shift;
58   my $class = ref($proto) || $proto;
59   my $self = {};
60   bless ($self, $class);
61 }
62
63 sub AUTOLOAD { 1 };
64
65 1;
66