File Coverage

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


line stmt bran cond sub pod time code
1             package CGI::Application::Plugin::Authentication::Display::Basic;
2             $CGI::Application::Plugin::Authentication::Display::Basic::VERSION = '0.23';
3 2     2   13 use base qw(CGI::Application::Plugin::Authentication::Display);
  2         4  
  2         490  
4              
5 2     2   28 use 5.006;
  2         6  
6 2     2   8 use strict;
  2         4  
  2         34  
7 2     2   8 use warnings;
  2         4  
  2         42  
8 2     2   8 use Carp;
  2         4  
  2         904  
9              
10             sub new {
11 5     5 1 12 my $class = shift;
12 5         10 my $cgiapp = shift;
13 5         30 my $self = CGI::Application::Plugin::Authentication::Display->new($cgiapp);
14 5         10 bless $self, $class;
15 5         14 return $self;
16             }
17              
18             sub login_box {
19 6     6 1 67 my $self = shift;
20 6 100       18 croak "already authenticated" if $self->_cgiapp->authen->is_authenticated;
21 5         29 my $credentials = $self->_cgiapp->authen->credentials;
22 5         14 my $runmode = $self->_cgiapp->get_current_runmode;
23 5   100     27 my $destination = $self->_cgiapp->authen->_detaint_destination || $self->_cgiapp->authen->_detaint_selfurl;
24 5         15 my $action = $self->_cgiapp->authen->_detaint_url;
25 5         12 my $username = $credentials->[0];
26 5         9 my $password = $credentials->[1];
27 5         16 my $login_form = $self->_cgiapp->authen->_config->{LOGIN_FORM};
28 5         48 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         12 my $messages = '';
47 5 100       12 if ( my $attempts = $self->_cgiapp->authen->login_attempts ) {
48 3         17 $messages .= '
  • ' . sprintf($options{INVALIDPASSWORD_MESSAGE}, $attempts) . '
  • ';
    49             } else {
    50 2         8 $messages .= "
  • $options{COMMENT}
  • ";
    51             }
    52              
    53 5         11 my $tabindex = 3;
    54 5         13 my ($rememberuser, $username_value, $register, $forgotpassword) = ('','','','');
    55 5 100       15 if ($options{REMEMBERUSER_OPTION}) {
    56 3         11 $rememberuser = <
    57            
    58            
    59            
    60             END
    61 3         6 $tabindex++;
    62 3         9 $username_value = $self->_cgiapp->authen->_detaint_username($username, $options{REMEMBERUSER_COOKIENAME});
    63             }
    64 5         12 my $submit_tabindex = $tabindex++;
    65 5 100       14 if ($options{REGISTER_URL}) {
    66 2         9 $register = qq[$options{REGISTER_LABEL}];
    67 2         4 $tabindex++;
    68             }
    69 5 100       13 if ($options{FORGOTPASSWORD_URL}) {
    70 2         7 $forgotpassword = qq[$options{FORGOTPASSWORD_LABEL}];
    71 2         3 $tabindex++;
    72             }
    73              
    74 5         55 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         30 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 DESCRIPTION
    115              
    116             This module provides a login box that works out of the box but which can be
    117             configured to modify the styling.
    118              
    119             =head1 METHODS
    120              
    121             =head2 new
    122              
    123             The constructor must be passed the L object as the first
    124             non-object argument.
    125              
    126             =head2 login_box
    127              
    128             This method will return the HTML for a login box that can be
    129             embedded into another page. This is the same login box that is used
    130             in the default authen_login runmode that the plugin provides.
    131             Note that if somehow this method is run, whilst the user is authenticated,
    132             it will croak.
    133              
    134             You can set this option to customize the login form that is created when a user
    135             needs to be authenticated. If you wish to replace the entire login form with a
    136             completely custom version, then just set LOGIN_RUNMODE to point to your custom
    137             runmode.
    138              
    139             All of the parameters listed below are optional, and a reasonable default will
    140             be used if left blank:
    141              
    142             =over 4
    143              
    144             =item TITLE (default: Sign In)
    145              
    146             the heading at the top of the login box
    147              
    148             =item USERNAME_LABEL (default: User Name)
    149              
    150             the label for the user name input
    151              
    152             =item PASSWORD_LABEL (default: Password)
    153              
    154             the label for the password input
    155              
    156             =item SUBMIT_LABEL (default: Sign In)
    157              
    158             the label for the submit button
    159              
    160             =item COMMENT (default: Please enter your username and password in the fields below.)
    161              
    162             a message provided on the first login attempt
    163              
    164             =item REMEMBERUSER_OPTION (default: 1)
    165              
    166             provide a checkbox to offer to remember the users name in a cookie so that
    167             their user name will be pre-filled the next time they log in
    168              
    169             =item REMEMBERUSER_LABEL (default: Remember User Name)
    170              
    171             the label for the remember user name checkbox
    172              
    173             =item REMEMBERUSER_COOKIENAME (default: CAPAUTHTOKEN)
    174              
    175             the name of the cookie where the user name will be saved
    176              
    177             =item REGISTER_URL (default: )
    178              
    179             the URL for the register new account link
    180              
    181             =item REGISTER_LABEL (default: Register Now!)
    182              
    183             the label for the register new account link
    184              
    185             =item FORGOTPASSWORD_URL (default: )
    186              
    187             the URL for the forgot password link
    188              
    189             =item FORGOTPASSWORD_LABEL (default: Forgot Password?)
    190              
    191             the label for the forgot password link
    192              
    193             =item INVALIDPASSWORD_MESSAGE (default: Invalid username or password
    (login attempt %d)
    194              
    195             a message given when a login failed
    196              
    197             =item FORM_SUBMIT_METHOD (default: post)
    198              
    199             use this to get the form to submit using 'get' instead of 'post'
    200              
    201             =back
    202              
    203             =head1 BUGS
    204              
    205             This is alpha software and as such, the features and interface
    206             are subject to change. So please check the Changes file when upgrading.
    207              
    208             =head1 SEE ALSO
    209              
    210             L, perl(1)
    211              
    212             =head1 AUTHOR
    213              
    214             Author: Cees Hek ; Co-maintainer: Nicholas Bamber .
    215              
    216             =head1 CREDITS
    217              
    218             Thanks to SiteSuite (http://www.sitesuite.com.au) for funding the
    219             development of this plugin and for releasing it to the world.
    220              
    221             Thanks to Christian Walde for suggesting changes to fix the incompatibility with
    222             L and for help with github.
    223              
    224             =head1 LICENCE AND COPYRIGHT
    225              
    226             Copyright (c) 2005, SiteSuite. All rights reserved.
    227             Copyright (c) 2010, Nicholas Bamber.
    228              
    229             This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
    230              
    231             =head1 DISCLAIMER OF WARRANTY
    232              
    233             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.
    234              
    235             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.
    236              
    237             =cut
    238              
    239             1;