CGI-Application-Plugin-Authentication
view release on metacpan or search on metacpan
lib/CGI/Application/Plugin/Authentication/Display/Classic.pm view on Meta::CPAN
package CGI::Application::Plugin::Authentication::Display::Classic;
$CGI::Application::Plugin::Authentication::Display::Classic::VERSION = '0.25';
use base qw(CGI::Application::Plugin::Authentication::Display);
use 5.006;
use strict;
use warnings;
use Carp;
sub new {
my $class = shift;
my $cgiapp = shift;
my $self = CGI::Application::Plugin::Authentication::Display->new($cgiapp);
bless $self, $class;
return $self;
}
sub login_box {
my $self = shift;
my $credentials = $self->_cgiapp->authen->credentials;
my $runmode = $self->_cgiapp->get_current_runmode;
my $destination = $self->_cgiapp->authen->_detaint_destination || $self->_cgiapp->authen->_detaint_selfurl;
my $action = $self->_cgiapp->authen->_detaint_url;
my $username = $credentials->[0];
my $password = $credentials->[1];
my $login_form = $self->_cgiapp->authen->_config->{LOGIN_FORM} || {};
my %options = (
TITLE => 'Sign In',
USERNAME_LABEL => 'User Name',
PASSWORD_LABEL => 'Password',
SUBMIT_LABEL => 'Sign In',
COMMENT => 'Please enter your username and password in the fields below.',
REMEMBERUSER_OPTION => 1,
REMEMBERUSER_LABEL => 'Remember User Name',
REMEMBERUSER_COOKIENAME => 'CAPAUTHTOKEN',
REGISTER_URL => '',
REGISTER_LABEL => 'Register Now!',
FORGOTPASSWORD_URL => '',
FORGOTPASSWORD_LABEL => 'Forgot Password?',
INVALIDPASSWORD_MESSAGE => 'Invalid username or password<br />(login attempt %d)',
INCLUDE_STYLESHEET => 1,
FORM_SUBMIT_METHOD => 'post',
%$login_form,
);
my $messages = '';
if ( my $attempts = $self->_cgiapp->authen->login_attempts ) {
$messages .= '<li class="warning">' . sprintf($options{INVALIDPASSWORD_MESSAGE}, $attempts) . '</li>';
} elsif ($options{COMMENT}) {
$messages .= "<li>$options{COMMENT}</li>";
}
my $tabindex = 3;
my ($rememberuser, $username_value, $register, $forgotpassword, $javascript, $style) = ('','','','','','');
if ($options{FOCUS_FORM_ONLOAD}) {
$javascript .= "document.loginform.${username}.focus();\n";
}
if ($options{REMEMBERUSER_OPTION}) {
$rememberuser = qq[<input id="authen_rememberuserfield" tabindex="$tabindex" type="checkbox" name="authen_rememberuser" value="1" />$options{REMEMBERUSER_LABEL}<br />];
$tabindex++;
$username_value = $self->_cgiapp->authen->_detaint_username($username, $options{REMEMBERUSER_COOKIENAME});
$javascript .= "document.loginform.${username}.select();\n" if $username_value;
}
my $submit_tabindex = $tabindex++;
if ($options{REGISTER_URL}) {
$register = qq[<a href="$options{REGISTER_URL}" id="authen_registerlink" tabindex="$tabindex">$options{REGISTER_LABEL}</a>];
$tabindex++;
}
if ($options{FORGOTPASSWORD_URL}) {
$forgotpassword = qq[<a href="$options{FORGOTPASSWORD_URL}" id="authen_forgotpasswordlink" tabindex="$tabindex">$options{FORGOTPASSWORD_LABEL}</a>];
$tabindex++;
}
if ($options{INCLUDE_STYLESHEET}) {
my $login_styles = $self->_login_styles;
$style = <<EOS;
<style type="text/css">
<!--/* <![CDATA[ */
$login_styles
/* ]]> */-->
</style>
EOS
}
if ($javascript) {
$javascript = qq[<script type="text/javascript" language="JavaScript">$javascript</script>];
}
( run in 0.540 second using v1.01-cache-2.11-cpan-39bf76dae61 )