RT#38217: Send email when logging conditions are met [removed unwanted log levels...
[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 sub authen_cred {
10   my( $self, $r, $username, $password ) = @_;
11
12   preuser_setup();
13
14   my $info = {};
15
16   unless ( FS::Auth->authenticate($username, $password, $info) ) {
17     warn "failed auth $username from ". $r->connection->remote_ip. "\n";
18     return undef;
19   }
20
21   warn "authenticated $username from ". $r->connection->remote_ip. "\n";
22
23   FS::CurrentUser->load_user( $username,
24                               'autocreate' => FS::Auth->auth_class->autocreate,
25                               %$info,
26                             );
27
28   FS::CurrentUser->new_session;
29 }
30
31 sub authen_ses_key {
32   my( $self, $r, $sessionkey ) = @_;
33
34   preuser_setup();
35
36   my $curuser = FS::CurrentUser->load_user_session( $sessionkey );
37
38   unless ( $curuser ) {
39     warn "bad session $sessionkey from ". $r->connection->remote_ip. "\n";
40     return undef;
41   }
42
43   $curuser->username;
44 }
45
46 1;