V2/Check.pm

filter: Statementstmt 21.6% 13 / 60 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 36.3% 4 / 11 Podpod 100% 7 / 7 totaltotal 24.2% 24 / 99 CC 11 SCAR 20.3
CC
11
Cov
16%
isCaptchaValid
12.0
isElementPresent
12.0
dateDiff
12.0
CRAP 7.6
« V2/Geo.pm ↑ Summary V2/Legacy.pm »
1 package FWS::V2::Check;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 FWS::V2::Check - Framework Sites version 2 validation and checking methods
11  
12 =head1 VERSION
13  
14 Version 1.13091122
15  
16 =cut
17  
18 1 our $VERSION = '1.13091122';
19  
20  
21 =head1 SYNOPSIS
22  
23 use FWS::V2;
24  
25 #
26 # Create $fws
27 #
28 my $fws = FWS::V2->new();
29  
30 #
31 # all simple boolean response in conditionals
32 #
33 if ( $fws->isValidEmail( 'this@email.com') ) { print "Its not real, but it could be!\n" }
34 else { print "Yuck, bad email.\n" }
35  
36  
37 =head1 DESCRIPTION
38  
39 Simple methods that will return boolean results based on the validation of the passed parameter.
40  
41 =cut
42  
43  
44 =head1 METHODS
45  
46 =head2 isAdminLoggedIn
47  
48 Return a 0 or 1 depending if a admin user is currently logged in.
49  
50 #
51 # do something if logged in as an admin user
52 #
53 if ( $fws->isAdminLoggedIn() ) { $valueHash{html} .= 'I am logged in as a admin<br/>' }
54  
55 =cut
56  
57 0 ▶sub isAdminLoggedIn {
Subroutine isAdminLoggedIn: not called CC=2 SCAR=17.9
Pod documented
58 0 my ( $self, $loginType ) = @_;
59 0 ▶ if ( $self->{adminLoginId} ) { return 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"adminLoginId"}) 0 0 0
60 0 return 0;
61 }
62  
63  
64 =head2 isUserLoggedIn
65  
66 Return a 0 or 1 depending if a site user is currently logged in.
67  
68 #
69 # do something if logged in as an site user
70 #
71 if ( $fws->isUserLoggedIn() ) { $valueHash{html} .= 'I am logged in as a user<br/>' }
72  
73 =cut
74  
75 0 ▶sub isUserLoggedIn {
Subroutine isUserLoggedIn: not called CC=2 SCAR=17.9
Pod documented
76 0 my ( $self, $loginType ) = @_;
77 0 ▶ if ( $self->{userLoginId} ) { return 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"userLoginId"}) 0 0 0
78 0 return 0;
79 }
80  
81  
82 =head2 isValidEmail
83  
84 Return a boolean response to validate if an email address is well formed.
85  
86 =cut
87  
88 0 ▶sub isValidEmail {
Subroutine isValidEmail: not called CC=2 SCAR=17.9
Pod documented
89 0 my ( $self, $fieldValue ) = @_;
90 0 ▶ if ( $fieldValue !~ /^\w+[\w|\.|-]*\w+@(\w+[\w|\.|-]*\w+\.[a-z]{2,4}|(\d{1,3}\.){3}\d{1,3})$/i ) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($fieldValue =~ /^\w+[\w|\.|-]*\w+@(\w+[\w|\.|-]*\w+\.[a-z]{2,4}|(\d{1,3}\.){3}\d{1,3})$/i) 0 0 0
91 0 return 1;
92 }
93  
94  
95 =head2 isCaptchaValid
96  
97 Built in captcha support will return 1 or 0 based on the last captcha post.
98  
99 =cut
100  
101 0 ▶sub isCaptchaValid {
Subroutine isCaptchaValid: not called CC=3 SCAR=24.8
Pod documented
102 0 my ( $self ) = @_;
103 0 my $publicKey = $self->siteValue( 'captchaPublicKey' );
104 0 my $privateKey = $self->siteValue( 'captchaPrivateKey' );
105 0 my $returnHTML;
106 0 ▶ if ( $publicKey ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($publicKey) 0 0 0
107 0 require Captcha::reCAPTCHA;
108 0 Captcha::reCAPTCHA->import();
109 0 my $captcha = Captcha::reCAPTCHA->new();
110 0 my $result = $captcha->check_answer( $privateKey, $ENV{REMOTE_ADDR}, $self->formValue( 'recaptcha_challenge_field' ), $self->formValue( 'recaptcha_response_field' ) );
111 0 ▶ if ( !$result->{is_valid} ) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($result->{"is_valid"}) 0 0 0
112 }
113 0 return 1;
114 }
115  
116  
117 =head2 isStrongPassword
118  
119 FWS standard strong password checker. Upper, lower, number, at least 6 chars.
120  
121 =cut
122  
123 0 ▶sub isStrongPassword {
Subroutine isStrongPassword: not called CC=2 SCAR=17.9
Pod documented
124 0 my ( $self, $fieldValue ) = @_;
125 0 ▶ if ( $fieldValue !~ /^.*(?=.{6,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($fieldValue =~ /^.*(?=.{6,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/) 0 0 0
126 0 return 1;
127 }
128  
129  
130 =head2 isElementPresent
131  
132 See if an element is present on the current page. This is here for some legacy code but should not be used because it is not good practice and could be slow if the page is complex. Just find another way to achieve the same result of knowing if something is present on a page.
133  
134 =cut
135  
136 0 ▶sub isElementPresent {
Subroutine isElementPresent: not called CC=3 SCAR=24.8
Pod documented
137 0 my ( $self, $guid, $elementName ) = @_;
138  
139 #
140 # Lets check if the formavalue FWS_elementblahblah is set if, so we have already looked this up and don't need to re-run it
141 #
142 0 my $isPresent = $self->formValue( 'FWS_ELEMENT_PRESENT_' . $elementName );
143  
144 #
145 # if it is blank, then we do need to run it for the first time :(
146 #
147 0 ▶ if ( !$isPresent ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($isPresent) 0 0 0
148  
149 #
150 # pull from the database to see if its there
151 #
152 0 my $pageId = $self->getPageGUID( $guid );
153 0 ( $isPresent ) = @{$self->runSQL( SQL => "select 1 from data left join guid_xref on data.guid=child where guid_xref.parent='". $self->safeSQL( $pageId ) . "' and data.site_guid='" . $self->safeSQL( $self->{siteGUID} ) . "' and (element_type like '" . $self->safeSQL( $elementName ) . "')" )};
154  
155 #
156 # if it comes back as "NO NO NO!" then it will be blank. so we will need to set it to 0
157 #
158 0 ▶ $isPresent ||= 0;
Condition0%0/2
$isPresent ||= 0
l!l
00
MC/DC0%0/1
$isPresent ||= 0
$isPresent
Truth table0%0/2
A
A= $isPresent
Aresult
11
00
159  
160 #
161 # Set the form value to what the value is so then we don't have to worry about it the next time we are here
162 #
163 0 $self->formValue( 'FWS_ELEMENT_PRESENT_' . $elementName, $isPresent );
164 }
165  
166 #
167 # pass back the value if we have gotten it from the cache or we had to look it up
168 #
169 0 return $isPresent;
170 }
171  
172  
173 =head2 dateDiff
174  
175 Return the amount of time between two dates in days or seconds.
176  
177 Possible Parameters:
178  
179 =over 4
180  
181 =item * date
182  
183 The base date to compare against
184  
185 =item * compDate
186  
187 A date in the future or past compare it to. If not passed, the current date will be used.
188  
189 =item * format
190  
191 The date format used. Default is SQLTime, you can choose epoch as an alternative
192  
193 =item * type
194  
195 The compare type to return as. Default is in 'seconds', you set this to 'days' if you would like the amount in days with its remainder as a decimal.
196  
197 =back
198  
199 =cut
200  
201 0 ▶sub dateDiff {
Subroutine dateDiff: not called CC=3 SCAR=24.8
Pod documented
202 0 my ( $self, %paramHash ) = @_;
203  
204 0 my $format = 'SQLTime';
205  
206 0 my $epoch1 = $self->formatDate( format => 'epoch', $format => $paramHash{date} );
207 0 my $epoch2 = $self->formatDate( format => 'epoch', $format => $paramHash{compDate} );
208  
209 0 my $secDiff = ( $epoch2 - $epoch1 );
210  
211 #
212 # if its 0 lets get out of here so we don't have devide by 0 errors
213 #
214 0 ▶ if ( $secDiff == 0 ) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($secDiff == 0) 0 0 0
215  
216 0 ▶ if ( $paramHash{type} =~ /day/i ) { return $secDiff / 86400 }
Branch: 1 branch
BranchTrueFalseTotal
if ($paramHash{"type"} =~ /day/i) 0 0 0
217  
218 0 return $secDiff;
219 }
220  
221  
222 =head1 AUTHOR
223  
224 Nate Lewis, C<< <nlewis at gnetworks.com> >>
225  
226 =head1 BUGS
227  
228 Please report any bugs or feature requests to C<bug-fws-lite at rt.cpan.org>, or through
229 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FWS-Check>. I will be notified, and then you'll
230 automatically be notified of progress on your bug as I make changes.
231  
232  
233 =head1 SUPPORT
234  
235 You can find documentation for this module with the perldoc command.
236  
237 perldoc FWS::V2::Check
238  
239  
240 You can also look for information at:
241  
242 =over 4
243  
244 =item * RT: CPAN's request tracker (report bugs here)
245  
246 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=FWS-Check>
247  
248 =item * AnnoCPAN: Annotated CPAN documentation
249  
250 L<http://annocpan.org/dist/FWS-Check>
251  
252 =item * CPAN Ratings
253  
254 L<http://cpanratings.perl.org/d/FWS-Check>
255  
256 =item * Search CPAN
257  
258 L<http://search.cpan.org/dist/FWS-Check/>
259  
260 =back
261  
262 =head1 LICENSE AND COPYRIGHT
263  
264 Copyright 2013 Nate Lewis.
265  
266 This program is free software; you can redistribute it and/or modify it
267 under the terms of either: the GNU General Public License as published
268 by the Free Software Foundation; or the Artistic License.
269  
270 See http://dev.perl.org/licenses/ for more information.
271  
272  
273 =cut
274  
275 1 1; # End of FWS::V2::Check
« V2/Geo.pm ↑ Summary V2/Legacy.pm »