File Coverage

blib/lib/CGI/Application/Plugin/Authentication/Display/Basic.pm
Criterion Covered Total %
statement 49 49 100.0
branch 10 10 100.0
condition 3 3 100.0
subroutine 7 7 100.0
pod 2 2 100.0
total 71 71 100.0


line stmt bran cond sub pod time code
1             package CGI::Application::Plugin::Authentication::Display::Basic;
2 2     2   14 use base qw(CGI::Application::Plugin::Authentication::Display);
  2         5  
  2         890  
3              
4 2     2   46 use 5.006;
  2         9  
  2         88  
5 2     2   12 use strict;
  2         4  
  2         72  
6 2     2   11 use warnings;
  2         5  
  2         61  
7 2     2   12 use Carp;
  2         5  
  2         1675  
8             our $VERSION = '0.20';
9              
10             sub new {
11 5     5 1 13 my $class = shift;
12 5         10 my $cgiapp = shift;
13 5         45 my $self = CGI::Application::Plugin::Authentication::Display->new($cgiapp);
14 5         20 bless $self, $class;
15 5         23 return $self;
16             }
17              
18             sub login_box {
19 6     6 1 194 my $self = shift;
20 6 100       31 croak "already authenticated" if $self->_cgiapp->authen->is_authenticated;
21 5         23 my $credentials = $self->_cgiapp->authen->credentials;
22 5         22 my $runmode = $self->_cgiapp->get_current_runmode;
23 5   100     45 my $destination = $self->_cgiapp->authen->_detaint_destination || $self->_cgiapp->authen->_detaint_selfurl;
24 5         47 my $action = $self->_cgiapp->authen->_detaint_url;
25 5         17 my $username = $credentials->[0];
26 5         13 my $password = $credentials->[1];
27 5         23 my $login_form = $self->_cgiapp->authen->_config->{LOGIN_FORM};
28 5         115 my %options = (
29             TITLE => 'Sign In',
30             USERNAME_LABEL => 'User Name',
31             PASSWORD_LABEL => 'Password',
32             SUBMIT_LABEL => 'Sign In',
33             COMMENT => 'Please enter your username and password in the fields below.',
34             REMEMBERUSER_OPTION => 1,
35             REMEMBERUSER_LABEL => 'Remember User Name',
36             REMEMBERUSER_COOKIENAME => 'CAPAUTHTOKEN',
37             REGISTER_URL => '',
38             REGISTER_LABEL => 'Register Now!',
39             FORGOTPASSWORD_URL => '',
40             FORGOTPASSWORD_LABEL => 'Forgot Password?',
41             INVALIDPASSWORD_MESSAGE => 'Invalid username or password
(login attempt %d)',
42             FORM_SUBMIT_METHOD => 'post',
43             %$login_form,
44             );
45              
46 5         14 my $messages = '';
47 5 100       22 if ( my $attempts = $self->_cgiapp->authen->login_attempts ) {
48 3         29 $messages .= '
  • ' . sprintf($options{INVALIDPASSWORD_MESSAGE}, $attempts) . '
  • ';
    49             } else {
    50 2         10 $messages .= "
  • $options{COMMENT}
  • ";
    51             }
    52              
    53 5         18 my $tabindex = 3;
    54 5         24 my ($rememberuser, $username_value, $register, $forgotpassword) = ('','','','');
    55 5 100       23 if ($options{REMEMBERUSER_OPTION}) {
    56 3         15 $rememberuser = <
    57            
    58            
    59            
    60             END
    61 3         7 $tabindex++;
    62 3         12 $username_value = $self->_cgiapp->authen->_detaint_username($username, $options{REMEMBERUSER_COOKIENAME});
    63             }
    64 5         15 my $submit_tabindex = $tabindex++;
    65 5 100       22 if ($options{REGISTER_URL}) {
    66 2         13 $register = qq[$options{REGISTER_LABEL}];
    67 2         5 $tabindex++;
    68             }
    69 5 100       18 if ($options{FORGOTPASSWORD_URL}) {
    70 2         10 $forgotpassword = qq[$options{FORGOTPASSWORD_LABEL}];
    71 2         5 $tabindex++;
    72             }
    73              
    74 5         62 my $html .= <
    75            
    76            
    77            
    78             $options{TITLE}
    79            
    80            
    81            
    82             ${messages}
    83            
    84            
    85            
    86            
    87            
    88            
    89            
    90            
    91             ${rememberuser}
    92            
    93            
    94            
    95            
    96            
    97             ${register}
    98             ${forgotpassword}
    99            
    100            
    101            
    102            
    103            
    104            
    105             END
    106              
    107 5         109 return $html;
    108             }
    109              
    110             =head1 NAME
    111              
    112             CGI::Application::Plugin::Authentication::Display::Basic - XHTML compliant no frills login display driver
    113              
    114             =head1 VERSION
    115              
    116             This document describes CGI::Application::Plugin::Authentication::Display::Basic version 0.20
    117              
    118             =head1 DESCRIPTION
    119              
    120             This module provides a login box that works out of the box but which can be
    121             configured to modify the styling.
    122              
    123             =head1 METHODS
    124              
    125             =head2 new
    126              
    127             The constructor must be passed the L object as the first
    128             non-object argument.
    129              
    130             =head2 login_box
    131              
    132             This method will return the HTML for a login box that can be
    133             embedded into another page. This is the same login box that is used
    134             in the default authen_login runmode that the plugin provides.
    135             Note that if somehow this method is run, whilst the user is authenticated,
    136             it will croak.
    137              
    138             You can set this option to customize the login form that is created when a user
    139             needs to be authenticated. If you wish to replace the entire login form with a
    140             completely custom version, then just set LOGIN_RUNMODE to point to your custom
    141             runmode.
    142              
    143             All of the parameters listed below are optional, and a reasonable default will
    144             be used if left blank:
    145              
    146             =over 4
    147              
    148             =item TITLE (default: Sign In)
    149              
    150             the heading at the top of the login box
    151              
    152             =item USERNAME_LABEL (default: User Name)
    153              
    154             the label for the user name input
    155              
    156             =item PASSWORD_LABEL (default: Password)
    157              
    158             the label for the password input
    159              
    160             =item SUBMIT_LABEL (default: Sign In)
    161              
    162             the label for the submit button
    163              
    164             =item COMMENT (default: Please enter your username and password in the fields below.)
    165              
    166             a message provided on the first login attempt
    167              
    168             =item REMEMBERUSER_OPTION (default: 1)
    169              
    170             provide a checkbox to offer to remember the users name in a cookie so that
    171             their user name will be pre-filled the next time they log in
    172              
    173             =item REMEMBERUSER_LABEL (default: Remember User Name)
    174              
    175             the label for the remember user name checkbox
    176              
    177             =item REMEMBERUSER_COOKIENAME (default: CAPAUTHTOKEN)
    178              
    179             the name of the cookie where the user name will be saved
    180              
    181             =item REGISTER_URL (default: )
    182              
    183             the URL for the register new account link
    184              
    185             =item REGISTER_LABEL (default: Register Now!)
    186              
    187             the label for the register new account link
    188              
    189             =item FORGOTPASSWORD_URL (default: )
    190              
    191             the URL for the forgot password link
    192              
    193             =item FORGOTPASSWORD_LABEL (default: Forgot Password?)
    194              
    195             the label for the forgot password link
    196              
    197             =item INVALIDPASSWORD_MESSAGE (default: Invalid username or password
    (login attempt %d)
    198              
    199             a message given when a login failed
    200              
    201             =item FORM_SUBMIT_METHOD (default: post)
    202              
    203             use this to get the form to submit using 'get' instead of 'post'
    204              
    205             =back
    206              
    207             =head1 BUGS
    208              
    209             This is alpha software and as such, the features and interface
    210             are subject to change. So please check the Changes file when upgrading.
    211              
    212             =head1 SEE ALSO
    213              
    214             L, perl(1)
    215              
    216             =head1 AUTHOR
    217              
    218             Author: Cees Hek ; Co-maintainer: Nicholas Bamber .
    219              
    220             =head1 CREDITS
    221              
    222             Thanks to SiteSuite (http://www.sitesuite.com.au) for funding the
    223             development of this plugin and for releasing it to the world.
    224              
    225             Thanks to Christian Walde for suggesting changes to fix the incompatibility with
    226             L and for help with github.
    227              
    228             =head1 LICENCE AND COPYRIGHT
    229              
    230             Copyright (c) 2005, SiteSuite. All rights reserved.
    231             Copyright (c) 2010, Nicholas Bamber.
    232              
    233             This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
    234              
    235             =head1 DISCLAIMER OF WARRANTY
    236              
    237             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
    238              
    239             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
    240              
    241             =cut
    242              
    243             1;