1 package FS::CurrentUser;
3 use vars qw($CurrentUser $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
22 my( $class, $user ) = @_; #, $pass
24 if ( $upgrade_hack ) {
25 return $CurrentUser = new FS::CurrentUser::BootstrapUser;
28 #return "" if $user =~ /^fs_(queue|selfservice)$/;
30 #not the best thing in the world...
31 eval "use FS::Record qw(qsearchs);";
33 eval "use FS::access_user;";
36 $CurrentUser = qsearchs('access_user', {
42 die "unknown user: $user" unless $CurrentUser; # or bad password
49 Creates a new session for the current user and returns the session key
53 use vars qw( @saltset );
54 @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '+' , '/' );
59 #not the best thing in the world...
60 eval "use FS::access_user_session;";
63 my $sessionkey = join('', map $saltset[int(rand(scalar @saltset))], 0..39);
65 my $access_user_session = new FS::access_user_session {
66 'sessionkey' => $sessionkey,
67 'usernum' => $CurrentUser->usernum,
70 my $error = $access_user_session->insert;
77 =item load_user_session SESSION_KEY
79 Sets the current user via the provided session key
83 sub load_user_session {
84 my( $class, $sessionkey ) = @_;
86 #not the best thing in the world...
87 eval "use FS::Record qw(qsearchs);";
89 eval "use FS::access_user_session;";
92 $CurrentSession = qsearchs('access_user_session', {
93 'sessionkey' => $sessionkey,
94 #XXX check for timed out but not-yet deleted sessions here
97 $CurrentSession->touch_last_date;
99 $CurrentUser = $CurrentSession->access_user;
111 package FS::CurrentUser::BootstrapUser;
115 my $class = ref($proto) || $proto;
117 bless ($self, $class);