blib/lib/CGI/Application/Plugin/Authentication/Display/Basic.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 10 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 100% 73 / 73 CC 7 SCAR 14.4
CC
7
Cov
100%
login_box
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.2
« Build ↑ Summary blib/lib/CGI/Application/Plugin/Authentication/Driver/HTPasswd.pm »
1 package CGI::Application::Plugin::Authentication::Display::Basic;
2 3 ▶use base qw(CGI::Application::Plugin::Authentication::Display);
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub new {
10 5 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11 5 my $cgiapp = shift;
12 5 my $self = CGI::Application::Plugin::Authentication::Display->new($cgiapp);
13 5 bless $self, $class;
14 5 return $self;
15 }
16  
17 sub login_box {
18 6 ▶ my $self = shift;
Subroutine login_box: called CC=7 SCAR=19.5
Pod documented
19 6 ▶ croak "already authenticated" if $self->_cgiapp->authen->is_authenticated;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_cgiapp->authen->is_authenticated 1 5 6
20 5 my $credentials = $self->_cgiapp->authen->credentials;
21 5 my $runmode = $self->_cgiapp->get_current_runmode;
22 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
23 5 my $action = $self->_cgiapp->authen->_detaint_url;
24 5 my $username = $credentials->[0];
25 5 my $password = $credentials->[1];
26 5 my $login_form = $self->_cgiapp->authen->_config->{LOGIN_FORM};
27 5 my %options = (
28 TITLE => 'Sign In',
29 USERNAME_LABEL => 'User Name',
30 PASSWORD_LABEL => 'Password',
31 SUBMIT_LABEL => 'Sign In',
32 COMMENT => 'Please enter your username and password in the fields below.',
33 REMEMBERUSER_OPTION => 1,
34 REMEMBERUSER_LABEL => 'Remember User Name',
35 REMEMBERUSER_COOKIENAME => 'CAPAUTHTOKEN',
36 REGISTER_URL => '',
37 REGISTER_LABEL => 'Register Now!',
38 FORGOTPASSWORD_URL => '',
39 FORGOTPASSWORD_LABEL => 'Forgot Password?',
40 INVALIDPASSWORD_MESSAGE => 'Invalid username or password<br />(login attempt %d)',
41 FORM_SUBMIT_METHOD => 'post',
42 %$login_form,
43 );
44  
45 5 my $messages = '';
46 5 ▶ if ( my $attempts = $self->_cgiapp->authen->login_attempts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $attempts = $self->_cgiapp->authen->login_attempts) { } 3 2 5
47 3 $messages .= '<li class="warning">' . sprintf($options{INVALIDPASSWORD_MESSAGE}, $attempts) . '</li>';
48 } else {
49 2 $messages .= "<li>$options{COMMENT}</li>";
50 }
51  
52 5 my $tabindex = 3;
53 5 my ($rememberuser, $username_value, $register, $forgotpassword) = ('','','','');
54 5 ▶ if ($options{REMEMBERUSER_OPTION}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"REMEMBERUSER_OPTION"}) 3 2 5
55 3 $rememberuser = <<END;
56 <label for="authen_rememberuserfield" id="authen_rememberuserfield_label" class="authen_label">$options{REMEMBERUSER_LABEL}
57 <input id="authen_rememberuserfield" class="authen_input" tabindex="$tabindex" type="checkbox" name="authen_rememberuser" value="1" />
58 </label>
59 END
60 3 $tabindex++;
61 3 $username_value = $self->_cgiapp->authen->_detaint_username($username, $options{REMEMBERUSER_COOKIENAME});
62 }
63 5 my $submit_tabindex = $tabindex++;
64 5 ▶ if ($options{REGISTER_URL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"REGISTER_URL"}) 2 3 5
65 2 $register = qq[<a href="$options{REGISTER_URL}" id="authen_registerlink" tabindex="$tabindex">$options{REGISTER_LABEL}</a>];
66 2 $tabindex++;
67 }
68 5 ▶ if ($options{FORGOTPASSWORD_URL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"FORGOTPASSWORD_URL"}) 2 3 5
69 2 $forgotpassword = qq[<a href="$options{FORGOTPASSWORD_URL}" id="authen_forgotpasswordlink" tabindex="$tabindex">$options{FORGOTPASSWORD_LABEL}</a>];
70 2 $tabindex++;
71 }
72  
73 5 my $html .= <<END;
74 <form id="loginform" method="$options{FORM_SUBMIT_METHOD}" action="${action}">
75 <div class="login">
76 <div class="login_header">
77 $options{TITLE}
78 </div>
79 <div class="login_content">
80 <ul class="message">
81 ${messages}
82 </ul>
83 <fieldset>
84 <label for="authen_loginfield" id="authen_loginfield_label" class="authen_label">$options{USERNAME_LABEL}
85 <input id="authen_loginfield" class="authen_input" tabindex="1" type="text" name="${username}" size="20" value="$username_value" />
86 </label>
87 <label for="authen_passwordfield" id="authen_passwordfield_label" class="authen_label">$options{PASSWORD_LABEL}
88 <input id="authen_passwordfield" class="authen_input" tabindex="2" type="password" name="${password}" size="20" />
89 </label>
90 ${rememberuser}
91 </fieldset>
92 </div>
93 <div class="login_footer">
94 <div class="buttons">
95 <input id="authen_loginbutton" tabindex="${submit_tabindex}" type="submit" name="authen_loginbutton" value="$options{SUBMIT_LABEL}" class="button" />
96 ${register}
97 ${forgotpassword}
98 </div>
99 </div>
100 </div>
101 <input type="hidden" name="destination" value="${destination}" />
102 <input type="hidden" name="rm" value="${runmode}" />
103 </form>
104 END
105  
106 5 return $html;
107 }
108  
109 =head1 DESCRIPTION
110  
111 This module provides a login box that works out of the box but which can be
112 configured to modify the styling.
113  
114 =head1 METHODS
115  
116 =head2 new
117  
118 The constructor must be passed the L<CGI::Application> object as the first
119 non-object argument.
120  
121 =head2 login_box
122  
123 This method will return the HTML for a login box that can be
124 embedded into another page. This is the same login box that is used
125 in the default authen_login runmode that the plugin provides.
126 Note that if somehow this method is run, whilst the user is authenticated,
127 it will croak.
128  
129 You can set this option to customize the login form that is created when a user
130 needs to be authenticated. If you wish to replace the entire login form with a
131 completely custom version, then just set LOGIN_RUNMODE to point to your custom
132 runmode.
133  
134 All of the parameters listed below are optional, and a reasonable default will
135 be used if left blank:
136  
137 =over 4
138  
139 =item TITLE (default: Sign In)
140  
141 the heading at the top of the login box
142  
143 =item USERNAME_LABEL (default: User Name)
144  
145 the label for the user name input
146  
147 =item PASSWORD_LABEL (default: Password)
148  
149 the label for the password input
150  
151 =item SUBMIT_LABEL (default: Sign In)
152  
153 the label for the submit button
154  
155 =item COMMENT (default: Please enter your username and password in the fields below.)
156  
157 a message provided on the first login attempt
158  
159 =item REMEMBERUSER_OPTION (default: 1)
160  
161 provide a checkbox to offer to remember the users name in a cookie so that
162 their user name will be pre-filled the next time they log in
163  
164 =item REMEMBERUSER_LABEL (default: Remember User Name)
165  
166 the label for the remember user name checkbox
167  
168 =item REMEMBERUSER_COOKIENAME (default: CAPAUTHTOKEN)
169  
170 the name of the cookie where the user name will be saved
171  
172 =item REGISTER_URL (default: <none>)
173  
174 the URL for the register new account link
175  
176 =item REGISTER_LABEL (default: Register Now!)
177  
178 the label for the register new account link
179  
180 =item FORGOTPASSWORD_URL (default: <none>)
181  
182 the URL for the forgot password link
183  
184 =item FORGOTPASSWORD_LABEL (default: Forgot Password?)
185  
186 the label for the forgot password link
187  
188 =item INVALIDPASSWORD_MESSAGE (default: Invalid username or password<br />(login attempt %d)
189  
190 a message given when a login failed
191  
192 =item FORM_SUBMIT_METHOD (default: post)
193  
194 use this to get the form to submit using 'get' instead of 'post'
195  
196 =back
197  
198 =head1 BUGS
199  
200 This is alpha software and as such, the features and interface
201 are subject to change. So please check the Changes file when upgrading.
202  
203 =head1 SEE ALSO
204  
205 L<CGI::Application>, perl(1)
206  
207 =head1 AUTHOR
208  
209 Author: Cees Hek <ceeshek@gmail.com>; Co-maintainer: Nicholas Bamber <nicholas@periapt.co.uk>.
210  
211 =head1 CREDITS
212  
213 Thanks to SiteSuite (http://www.sitesuite.com.au) for funding the
214 development of this plugin and for releasing it to the world.
215  
216 Thanks to Christian Walde for suggesting changes to fix the incompatibility with
217 L<CGI::Application::Plugin::ActionDispatch> and for help with github.
218  
219 =head1 LICENCE AND COPYRIGHT
220  
221 Copyright (c) 2005, SiteSuite. All rights reserved.
222 Copyright (c) 2010, Nicholas Bamber.
223  
224 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
225  
226 =head1 DISCLAIMER OF WARRANTY
227  
228 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.
229  
230 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.
231  
232 =cut
233  
234 3 1;
« Build ↑ Summary blib/lib/CGI/Application/Plugin/Authentication/Driver/HTPasswd.pm »