<%once>
my $loaded_user = 0;
</%once>
<%init>

use RT::Authen::ExternalAuth;

###################################################################################
# Work around a bug in the RT 3.8.0 and 3.8.1 plugin system (fixed in 3.8.2)      #
# Temporarily force RT to reload RT::User, since it isn't being loaded            #
# correctly as a plugin.                                                          #
###################################################################################
unless ($loaded_user) {
    $RT::Logger->debug("Reloading RT::User to work around a bug in RT-3.8.0 and RT-3.8.1");
    $loaded_user++;
    delete $INC{'RT/User.pm'};
    delete $INC{'RT/User_Overlay.pm'};
    delete $INC{'RT/User_Vendor.pm'};
    require RT::User;
}
###################################################################################

my ($val,$msg);
unless($session{'CurrentUser'} && $session{'CurrentUser'}->Id) {
    ($val,$msg) = RT::Authen::ExternalAuth::DoAuth(\%session,$user,$pass);
    $RT::Logger->debug("Autohandler called ExternalAuth. Response: ($val, $msg)");
}

return;
</%init>

<%ARGS>
$user => undef
$pass => undef
$menu => undef
</%ARGS>

