Authentication/Display/Basic.pm

filter: Statementstmt 100% 50 / 50 Branchbran 100% 10 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 100% 74 / 74 SCAR 19.5
CC
7
Cov
100%
login_box
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.0
« Authentication/Driver/Generic.pm ↑ Summary Authentication/Driver/Authen/Simple.pm »
1 package CGI::Application::Plugin::Authentication::Display::Basic;
2 2 $CGI::Application::Plugin::Authentication::Display::Basic::VERSION = '0.21';
3 2 ▶use base qw(CGI::Application::Plugin::Authentication::Display);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub new {
11 5 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12 5 my $cgiapp = shift;
13 5 my $self = CGI::Application::Plugin::Authentication::Display->new($cgiapp);
14 5 bless $self, $class;
15 5 return $self;
16 }
17  
18 sub login_box {
19 6 ▶ my $self = shift;
Subroutine login_box: called CC=7 SCAR=19.5
Pod documented
20 6 ▶ croak "already authenticated" if $self->_cgiapp->authen->is_authenticated;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_cgiapp->authen->is_authenticated 1 5 6
21 5 my $credentials = $self->_cgiapp->authen->credentials;
22 5 my $runmode = $self->_cgiapp->get_current_runmode;
23 5 ▶ my $destination = $self->_cgiapp->authen->_detaint_destination || $self->_cgiapp->authen->_detaint_selfurl;
Condition100%3/3
$self->_cgiapp->authen->_detaint_destination || $self->_cgiapp->authen->_detaint_selfurl
l!l&&r!l&&!r
131
MC/DC100%2/2
$self->_cgiapp->authen->_detaint_destination || $self->_cgiapp->authen->_detaint_selfurl
$self->_cgiapp->authen->_detaint_destination $self->_cgiapp->authen->_detaint_selfurl
Truth table100%3/3
A || B
A= $self->_cgiapp->authen->_detaint_destinationB= $self->_cgiapp->authen->_detaint_selfurl
ABresult
1X1
011
000
24 5 my $action = $self->_cgiapp->authen->_detaint_url;
25 5 my $username = $credentials->[0];
26 5 my $password = $credentials->[1];
27 5 my $login_form = $self->_cgiapp->authen->_config->{LOGIN_FORM};
28 5 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<br />(login attempt %d)',
42 FORM_SUBMIT_METHOD => 'post',
43 %$login_form,
44 );
45  
46 5 my $messages = '';
47 5 ▶ if ( my $attempts = $self->_cgiapp->authen->login_attempts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $attempts = $self->_cgiapp->authen->login_attempts) { } 3 2 5
48 3 $messages .= '<li class="warning">' . sprintf($options{INVALIDPASSWORD_MESSAGE}, $attempts) . '</li>';
49 } else {
50 2 $messages .= "<li>$options{COMMENT}</li>";
51 }
52  
53 5 my $tabindex = 3;
54 5 my ($rememberuser, $username_value, $register, $forgotpassword) = ('','','','');
55 5 ▶ if ($options{REMEMBERUSER_OPTION}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"REMEMBERUSER_OPTION"}) 3 2 5
56 3 $rememberuser = <<END;
57 <label for="authen_rememberuserfield" id="authen_rememberuserfield_label" class="authen_label">$options{REMEMBERUSER_LABEL}
58 <input id="authen_rememberuserfield" class="authen_input" tabindex="$tabindex" type="checkbox" name="authen_rememberuser" value="1" />
59 </label>
60 END
61 3 $tabindex++;
62 3 $username_value = $self->_cgiapp->authen->_detaint_username($username, $options{REMEMBERUSER_COOKIENAME});
63 }
64 5 my $submit_tabindex = $tabindex++;
65 5 ▶ if ($options{REGISTER_URL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"REGISTER_URL"}) 2 3 5
66 2 $register = qq[<a href="$options{REGISTER_URL}" id="authen_registerlink" tabindex="$tabindex">$options{REGISTER_LABEL}</a>];
67 2 $tabindex++;
68 }
69 5 ▶ if ($options{FORGOTPASSWORD_URL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"FORGOTPASSWORD_URL"}) 2 3 5
70 2 $forgotpassword = qq[<a href="$options{FORGOTPASSWORD_URL}" id="authen_forgotpasswordlink" tabindex="$tabindex">$options{FORGOTPASSWORD_LABEL}</a>];
71 2 $tabindex++;
72 }
73  
74 5 my $html .= <<END;
75 <form id="loginform" method="$options{FORM_SUBMIT_METHOD}" action="${action}">
76 <div class="login">
77 <div class="login_header">
78 $options{TITLE}
79 </div>
80 <div class="login_content">
81 <ul class="message">
82 ${messages}
83 </ul>
84 <fieldset>
85 <label for="authen_loginfield" id="authen_loginfield_label" class="authen_label">$options{USERNAME_LABEL}
86 <input id="authen_loginfield" class="authen_input" tabindex="1" type="text" name="${username}" size="20" value="$username_value" />
87 </label>
88 <label for="authen_passwordfield" id="authen_passwordfield_label" class="authen_label">$options{PASSWORD_LABEL}
89 <input id="authen_passwordfield" class="authen_input" tabindex="2" type="password" name="${password}" size="20" />
90 </label>
91 ${rememberuser}
92 </fieldset>
93 </div>
94 <div class="login_footer">
95 <div class="buttons">
96 <input id="authen_loginbutton" tabindex="${submit_tabindex}" type="submit" name="authen_loginbutton" value="$options{SUBMIT_LABEL}" class="button" />
97 ${register}
98 ${forgotpassword}
99 </div>
100 </div>
101 </div>
102 <input type="hidden" name="destination" value="${destination}" />
103 <input type="hidden" name="rm" value="${runmode}" />
104 </form>
105 END
106  
107 5 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<CGI::Application> 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: <none>)
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: <none>)
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<br />(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<CGI::Application>, perl(1)
211  
212 =head1 AUTHOR
213  
214 Author: Cees Hek <ceeshek@gmail.com>; Co-maintainer: Nicholas Bamber <nicholas@periapt.co.uk>.
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<CGI::Application::Plugin::ActionDispatch> 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 2 1;
« Authentication/Driver/Generic.pm ↑ Summary Authentication/Driver/Authen/Simple.pm »