1 package FS::CurrentUser;
3 use vars qw($CurrentUser $CurrentSession $upgrade_hack);
5 #not at compile-time, circular dependancey causes trouble
6 #use FS::Record qw(qsearchs);
13 FS::CurrentUser - Package representing the current user (and session)
23 =item load_user USERNAME
25 Sets the current user to the provided username
30 my( $class, $user ) = @_; #, $pass
32 if ( $upgrade_hack ) {
33 return $CurrentUser = new FS::CurrentUser::BootstrapUser;
36 #return "" if $user =~ /^fs_(queue|selfservice)$/;
38 #not the best thing in the world...
39 eval "use FS::Record qw(qsearchs);";
41 eval "use FS::access_user;";
44 $CurrentUser = qsearchs('access_user', {
50 die "unknown user: $user" unless $CurrentUser; # or bad password
57 Creates a new session for the current user and returns the session key
61 use vars qw( @saltset );
62 @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '+' , '/' );
67 #not the best thing in the world...
68 eval "use FS::access_user_session;";
71 my $sessionkey = join('', map $saltset[int(rand(scalar @saltset))], 0..39);
73 my $access_user_session = new FS::access_user_session {
74 'sessionkey' => $sessionkey,
75 'usernum' => $CurrentUser->usernum,
78 my $error = $access_user_session->insert;
85 =item load_user_session SESSION_KEY
87 Sets the current user via the provided session key
91 sub load_user_session {
92 my( $class, $sessionkey ) = @_;
94 #not the best thing in the world...
95 eval "use FS::Record qw(qsearchs);";
97 eval "use FS::access_user_session;";
100 $CurrentSession = qsearchs('access_user_session', {
101 'sessionkey' => $sessionkey,
102 #XXX check for timed out but not-yet deleted sessions here
105 $CurrentSession->touch_last_date;
107 $CurrentUser = $CurrentSession->access_user;
119 package FS::CurrentUser::BootstrapUser;
123 my $class = ref($proto) || $proto;
125 bless ($self, $class);