From 7d6db2c0fed3624edeb29de8890e982f743ff158 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Sun, 18 Jan 2015 14:37:26 -0800 Subject: [PATCH] DRY --- FS/FS/AuthCookieHandler.pm | 12 +++++++++--- FS/FS/AuthCookieHandler24.pm | 44 +++++--------------------------------------- 2 files changed, 14 insertions(+), 42 deletions(-) diff --git a/FS/FS/AuthCookieHandler.pm b/FS/FS/AuthCookieHandler.pm index b571e4705..93d8ea6a5 100644 --- a/FS/FS/AuthCookieHandler.pm +++ b/FS/FS/AuthCookieHandler.pm @@ -6,6 +6,12 @@ use FS::UID qw( adminsuidsetup preuser_setup ); use FS::CurrentUser; use FS::Auth; +#Apache 2.2 and below +sub useragent_ip { + my( $self, $r ) = @_; + $r->connection->remote_ip; +} + sub authen_cred { my( $self, $r, $username, $password ) = @_; @@ -14,11 +20,11 @@ sub authen_cred { my $info = {}; unless ( FS::Auth->authenticate($username, $password, $info) ) { - warn "failed auth $username from ". $r->connection->remote_ip. "\n"; + warn "failed auth $username from ". $self->useragent_ip($r). "\n"; return undef; } - warn "authenticated $username from ". $r->connection->remote_ip. "\n"; + warn "authenticated $username from ". $self->useragent_ip($r). "\n"; FS::CurrentUser->load_user( $username, 'autocreate' => FS::Auth->auth_class->autocreate, @@ -36,7 +42,7 @@ sub authen_ses_key { my $curuser = FS::CurrentUser->load_user_session( $sessionkey ); unless ( $curuser ) { - warn "bad session $sessionkey from ". $r->connection->remote_ip. "\n"; + warn "bad session $sessionkey from ". $self->useragent_ip($r). "\n"; return undef; } diff --git a/FS/FS/AuthCookieHandler24.pm b/FS/FS/AuthCookieHandler24.pm index fa24890cc..d65934f9d 100644 --- a/FS/FS/AuthCookieHandler24.pm +++ b/FS/FS/AuthCookieHandler24.pm @@ -1,46 +1,12 @@ package FS::AuthCookieHandler24; -use base qw( Apache2::AuthCookie ); +use base qw( FS::AuthCookieHandler ); use strict; -use FS::UID qw( adminsuidsetup preuser_setup ); -use FS::CurrentUser; -use FS::Auth; -sub authen_cred { - my( $self, $r, $username, $password ) = @_; - - preuser_setup(); - - my $info = {}; - - unless ( FS::Auth->authenticate($username, $password, $info) ) { - warn "failed auth $username from ". $r->useragent_ip. "\n"; - return undef; - } - - warn "authenticated $username from ". $r->useragent_ip. "\n"; - - FS::CurrentUser->load_user( $username, - 'autocreate' => FS::Auth->auth_class->autocreate, - %$info, - ); - - FS::CurrentUser->new_session; -} - -sub authen_ses_key { - my( $self, $r, $sessionkey ) = @_; - - preuser_setup(); - - my $curuser = FS::CurrentUser->load_user_session( $sessionkey ); - - unless ( $curuser ) { - warn "bad session $sessionkey from ". $r->useragent_ip. "\n"; - return undef; - } - - $curuser->username; +#Apache 2.4+ / Apache2::AuthCookie 3.19+ +sub useragent_ip { + my( $self, $r ) = @_; + $r->useragent_ip; } 1; -- 2.11.0