add skip_dcontext_suffix to skip CDRs with dcontext ending in a definable string...
[freeside.git] / FS / FS / AuthCookieHandler.pm
1 package FS::AuthCookieHandler;
2 use base qw( Apache2::AuthCookie );
3
4 use strict;
5 use FS::UID qw( adminsuidsetup preuser_setup );
6 use FS::CurrentUser;
7 use FS::Auth;
8
9 #Apache 2.2 and below
10 sub useragent_ip {
11   my( $self, $r ) = @_;
12   $r->connection->remote_ip;
13 }
14
15 sub authen_cred {
16   my( $self, $r, $username, $password ) = @_;
17
18   preuser_setup();
19
20   my $info = {};
21
22   unless ( FS::Auth->authenticate($username, $password, $info) ) {
23     warn "failed auth $username from ". $self->useragent_ip($r). "\n";
24     return undef;
25   }
26
27   warn "authenticated $username from ". $self->useragent_ip($r). "\n";
28
29   FS::CurrentUser->load_user( $username,
30                               'autocreate' => FS::Auth->auth_class->autocreate,
31                               %$info,
32                             );
33
34   FS::CurrentUser->new_session;
35 }
36
37 sub authen_ses_key {
38   my( $self, $r, $sessionkey ) = @_;
39
40   preuser_setup();
41
42   my $curuser = FS::CurrentUser->load_user_session( $sessionkey );
43
44   unless ( $curuser ) {
45     warn "bad session $sessionkey from ". $self->useragent_ip($r). "\n";
46     return undef;
47   }
48
49   $curuser->username;
50 }
51
52 1;