From a9adfe5a3786f860510fcf10792958a25e1a7727 Mon Sep 17 00:00:00 2001 From: Paul Seamons Date: Mon, 8 Oct 2007 00:00:00 +0000 Subject: [PATCH] CGI::Ex 2.20 --- Changes | 7 ++++++ META.yml | 2 +- lib/CGI/Ex.pm | 2 +- lib/CGI/Ex/App.pm | 4 ++-- lib/CGI/Ex/Auth.pm | 22 +++++++++++++++++- lib/CGI/Ex/Conf.pm | 2 +- lib/CGI/Ex/Die.pm | 2 +- lib/CGI/Ex/Dump.pm | 2 +- lib/CGI/Ex/Fill.pm | 2 +- lib/CGI/Ex/JSONDump.pm | 2 +- lib/CGI/Ex/Template.pm | 2 +- lib/CGI/Ex/Validate.pm | 7 +++++- lib/CGI/Ex/validate.js | 46 ++++++++++++++++++++++---------------- samples/js_validate_2.html | 1 + 14 files changed, 72 insertions(+), 31 deletions(-) diff --git a/Changes b/Changes index 635b3c5..f1577ae 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,10 @@ +2.20 + 2007-10-08 + * Added success_hook and failure_hook to Auth (not documented) + * Fix precedence issue in conf reading in App (thanks to Krassimir Berov) + * Fix bug in validate.js with LOCAL_PART matching (thanks to Thomas den Braber) + * Add support for clear_on_error to validate.js (thanks to Thomas den Braber) + 2.19 2007-10-05 * Make verify_token more granualar in Auth diff --git a/META.yml b/META.yml index 5df1a6f..8a005ad 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- #YAML:1.0 name: CGI-Ex -version: 2.19 +version: 2.20 abstract: CGI utility suite - makes powerful application writing fun and easy license: ~ generated_by: ExtUtils::MakeMaker version 6.36 diff --git a/lib/CGI/Ex.pm b/lib/CGI/Ex.pm index f33b9b3..faa5a36 100644 --- a/lib/CGI/Ex.pm +++ b/lib/CGI/Ex.pm @@ -24,7 +24,7 @@ use vars qw($VERSION use base qw(Exporter); BEGIN { - $VERSION = '2.19'; + $VERSION = '2.20'; $PREFERRED_CGI_MODULE ||= 'CGI'; @EXPORT = (); @EXPORT_OK = qw(get_form diff --git a/lib/CGI/Ex/App.pm b/lib/CGI/Ex/App.pm index da5904f..5e78cc3 100644 --- a/lib/CGI/Ex/App.pm +++ b/lib/CGI/Ex/App.pm @@ -13,7 +13,7 @@ BEGIN { eval { use Scalar::Util }; } -our $VERSION = '2.19'; +our $VERSION = '2.20'; sub new { my $class = shift || croak "Usage: ".__PACKAGE__."->new"; @@ -374,7 +374,7 @@ sub conf { return $self->{'conf'} ||= do { my $conf = $self->conf_file; if (! ref $conf) { - $conf = $self->conf_obj->read($conf, {no_warn_on_fail => 1}) || $self->conf_die_on_fail ? croak $@ : {}; + $conf = $self->conf_obj->read($conf, {no_warn_on_fail => 1}) || ($self->conf_die_on_fail ? croak $@ : {}); } my $hash = $self->conf_validation; if ($hash && scalar keys %$hash) { diff --git a/lib/CGI/Ex/Auth.pm b/lib/CGI/Ex/Auth.pm index 85c28fe..a762ead 100644 --- a/lib/CGI/Ex/Auth.pm +++ b/lib/CGI/Ex/Auth.pm @@ -18,7 +18,7 @@ use MIME::Base64 qw(encode_base64 decode_base64); use Digest::MD5 qw(md5_hex); use CGI::Ex; -$VERSION = '2.19'; +$VERSION = '2.20'; ###----------------------------------------------------------------### @@ -138,6 +138,7 @@ sub handle_success { ### if they have cookies we are done } elsif (scalar(keys %{$self->cookies}) || $self->no_cookie_verify) { + $self->success_hook; return $self; ### need to verify cookies are set-able @@ -151,6 +152,14 @@ sub handle_success { } } +sub success_hook { + my $self = shift; + if (my $meth = $self->{'success_hook'}) { + return $meth->($self); + } + return; +} + sub handle_failure { my $self = shift; my $args = shift || {}; @@ -181,10 +190,19 @@ sub handle_failure { ### allow for a sleep to help prevent brute force sleep($self->failed_sleep) if defined($data) && $data->error ne 'Login expired' && $self->failed_sleep; + $self->failure_hook; return; } +sub failure_hook { + my $self = shift; + if (my $meth = $self->{'failure_hook'}) { + return $meth->($self); + } + return; +} + sub check_valid_auth { my $self = shift; $self = $self->new(@_) if ! ref $self; @@ -930,6 +948,8 @@ defined separately. login_template handle_success handle_failure + success_hook + failure_hook no_cookie_verify path_info script_name diff --git a/lib/CGI/Ex/Conf.pm b/lib/CGI/Ex/Conf.pm index b62674b..0b13ca8 100644 --- a/lib/CGI/Ex/Conf.pm +++ b/lib/CGI/Ex/Conf.pm @@ -29,7 +29,7 @@ use vars qw($VERSION ); @EXPORT_OK = qw(conf_read conf_write in_cache); -$VERSION = '2.19'; +$VERSION = '2.20'; $DEFAULT_EXT = 'conf'; diff --git a/lib/CGI/Ex/Die.pm b/lib/CGI/Ex/Die.pm index 62f8deb..a87f500 100644 --- a/lib/CGI/Ex/Die.pm +++ b/lib/CGI/Ex/Die.pm @@ -23,7 +23,7 @@ use CGI::Ex; use CGI::Ex::Dump qw(debug ctrace dex_html); BEGIN { - $VERSION = '2.19'; + $VERSION = '2.20'; $SHOW_TRACE = 0 if ! defined $SHOW_TRACE; $IGNORE_EVAL = 0 if ! defined $IGNORE_EVAL; $EXTENDED_ERRORS = 1 if ! defined $EXTENDED_ERRORS; diff --git a/lib/CGI/Ex/Dump.pm b/lib/CGI/Ex/Dump.pm index 5039cc2..d83d6c2 100644 --- a/lib/CGI/Ex/Dump.pm +++ b/lib/CGI/Ex/Dump.pm @@ -17,7 +17,7 @@ use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION use strict; use Exporter; -$VERSION = '2.19'; +$VERSION = '2.20'; @ISA = qw(Exporter); @EXPORT = qw(dex dex_warn dex_text dex_html ctrace dex_trace); @EXPORT_OK = qw(dex dex_warn dex_text dex_html ctrace dex_trace debug); diff --git a/lib/CGI/Ex/Fill.pm b/lib/CGI/Ex/Fill.pm index 9641f18..c4ab9f4 100644 --- a/lib/CGI/Ex/Fill.pm +++ b/lib/CGI/Ex/Fill.pm @@ -24,7 +24,7 @@ use vars qw($VERSION use base qw(Exporter); BEGIN { - $VERSION = '2.19'; + $VERSION = '2.20'; @EXPORT = qw(form_fill); @EXPORT_OK = qw(fill form_fill html_escape get_tagval_by_key swap_tagval_by_key); }; diff --git a/lib/CGI/Ex/JSONDump.pm b/lib/CGI/Ex/JSONDump.pm index 6d58f09..f212ec7 100644 --- a/lib/CGI/Ex/JSONDump.pm +++ b/lib/CGI/Ex/JSONDump.pm @@ -17,7 +17,7 @@ use strict; use base qw(Exporter); BEGIN { - $VERSION = '2.19'; + $VERSION = '2.20'; @EXPORT = qw(JSONDump); @EXPORT_OK = @EXPORT; diff --git a/lib/CGI/Ex/Template.pm b/lib/CGI/Ex/Template.pm index d0a837e..715dc19 100644 --- a/lib/CGI/Ex/Template.pm +++ b/lib/CGI/Ex/Template.pm @@ -25,7 +25,7 @@ use vars qw($VERSION $VOBJS ); -$VERSION = '2.19'; +$VERSION = '2.20'; ### install true symbol table aliases that can be localized *QR_PRIVATE = *Template::Alloy::QR_PRIVATE; diff --git a/lib/CGI/Ex/Validate.pm b/lib/CGI/Ex/Validate.pm index 651b3c9..18a3501 100644 --- a/lib/CGI/Ex/Validate.pm +++ b/lib/CGI/Ex/Validate.pm @@ -22,7 +22,7 @@ use vars qw($VERSION @UNSUPPORTED_BROWSERS ); -$VERSION = '2.19'; +$VERSION = '2.20'; $DEFAULT_EXT = 'val'; $QR_EXTRA = qr/^(\w+_error|as_(array|string|hash)_\w+|no_\w+)/; @@ -1740,6 +1740,11 @@ field has been checked and there are no errors - the field is "untainted." This is for use in conjunction with perl's -T switch. +=item C + +Clears the form field should a validation error occur. Only supported +on the Javascript side (no affect on the server side). + =back =head1 ERROR OBJECT diff --git a/lib/CGI/Ex/validate.js b/lib/CGI/Ex/validate.js index 8ac0479..40b4c04 100644 --- a/lib/CGI/Ex/validate.js +++ b/lib/CGI/Ex/validate.js @@ -4,7 +4,7 @@ * Based upon CGI/Ex/Validate.pm v1.14 from Perl * * For instructions on usage, see perldoc of CGI::Ex::Validate * ***----------------------------------------------------------------**/ -// $Revision: 1.41 $ +// $Revision: 1.42 $ function Validate () { this.error = vob_error; @@ -233,8 +233,16 @@ function vob_filter_types (type, types) { return values; } -function vob_add_error (errors,field,type,field_val,ifs_match) { +function vob_add_error (errors,field,type,field_val,ifs_match,form) { errors[errors.length] = new Array(field, type, field_val, ifs_match); + if (field_val['clear_on_error']) { + var el = form[field]; + if (el) { + var type = el.type; + if (type && (type == 'hidden' || type == 'password' || type == 'text' || type == 'textarea' || type == 'submit')) + el.value = ''; + } + } } /// this is where the main checking goes on @@ -373,7 +381,7 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) { if (is_required && (typeof(_value) == 'undefined' || ((typeof(_value) == 'object' && _value.length == 0) || ! _value.length))) { - this.add_error(errors, field, is_required, field_val, ifs_match); + this.add_error(errors, field, is_required, field_val, ifs_match, form); return errors; } @@ -382,7 +390,7 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) { for (var i = 0; i < tests.length; i ++) { var n = field_val[tests[i]]; if (n_values < n) { - this.add_error(errors, field, tests[i], field_val, ifs_match); + this.add_error(errors, field, tests[i], field_val, ifs_match, form); return errors; } } @@ -396,7 +404,7 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) { for (var i = 0; i < tests.length; i ++) { var n = field_val[tests[i]]; if (n_values > n) { - this.add_error(errors, field, tests[i], field_val, ifs_match); + this.add_error(errors, field, tests[i], field_val, ifs_match, form); return errors; } } @@ -427,7 +435,7 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) { } if ( (minmax == 'min' && n > 0) || (minmax == 'max' && n < 0)) { - this.add_error(errors, field, tests[i], field_val, ifs_match); + this.add_error(errors, field, tests[i], field_val, ifs_match, form); return errors; } } @@ -448,7 +456,7 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) { is_found = 1; break; } - if (! is_found) this.add_error(errors, field, tests[i], field_val, ifs_match); + if (! is_found) this.add_error(errors, field, tests[i], field_val, ifs_match, form); } /// field equality test @@ -466,21 +474,21 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) { if (value == value2) success = 1; } if (not && success || ! not && ! success) - this.add_error(errors, field, tests[i], field_val, ifs_match); + this.add_error(errors, field, tests[i], field_val, ifs_match, form); } /// length min check var tests = this.filter_types('min_len', types); for (var i = 0; i < tests.length; i ++) { var n = field_val[tests[i]]; - if (value.length < n) this.add_error(errors, field, tests[i], field_val, ifs_match); + if (value.length < n) this.add_error(errors, field, tests[i], field_val, ifs_match, form); } /// length max check var tests = this.filter_types('max_len', types); for (var i = 0; i < tests.length; i ++) { var n = field_val[tests[i]]; - if (value.length > n) this.add_error(errors, field, tests[i], field_val, ifs_match); + if (value.length > n) this.add_error(errors, field, tests[i], field_val, ifs_match, form); } /// now do match types @@ -492,7 +500,7 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) { : ref.split(new RegExp('\\s*\\|\\|\\s*')); for (var j = 0; j < ref.length; j ++) { if (typeof(ref[j]) == 'function') { - if (! value.match(ref[j])) this.add_error(errors, field, tests[i], field_val, ifs_match); + if (! value.match(ref[j])) this.add_error(errors, field, tests[i], field_val, ifs_match, form); } else { if (! (m = ref[j].match('^\\s*(!\\s*|)m([^\\s\\w])(.*)\\2([eigsmx]*)\\s*$'))) return this.error("Not sure how to parse that match ("+ref[j]+")"); @@ -505,7 +513,7 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) { var regexp = new RegExp(pat, opt); if ( ( not && value.match(regexp)) || (! not && ! value.match(regexp))) { - this.add_error(errors, field, tests[i], field_val, ifs_match); + this.add_error(errors, field, tests[i], field_val, ifs_match, form); } } } @@ -541,7 +549,7 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) { } else { return this.error("Not sure how to compare \""+comp+"\""); } - if (! hold) this.add_error(errors, field, tests[i], field_val, ifs_match); + if (! hold) this.add_error(errors, field, tests[i], field_val, ifs_match, form); } } @@ -549,7 +557,7 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) { var tests = this.filter_types('type',types); for (var i = 0; i < tests.length; i ++) if (! this.check_type(value, field_val[tests[i]], field, form)) - this.add_error(errors, field, tests[i], field_val, ifs_match); + this.add_error(errors, field, tests[i], field_val, ifs_match, form); /// do custom_js type checks // this will allow for a custom piece of javascript @@ -558,7 +566,7 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) { var tests = this.filter_types('custom_js',types); for (var i = 0; i < tests.length; i ++) if (! eval(field_val[tests[i]])) - this.add_error(errors, field, tests[i], field_val, ifs_match); + this.add_error(errors, field, tests[i], field_val, ifs_match, form); } /// all done - time to return @@ -581,10 +589,10 @@ function vob_check_type (value, type, field, form) { /// the "username" portion of an email address } else if (type == 'LOCAL_PART') { if (typeof(value) == 'undefined' || ! value.length) return 0; - if (! value.match('[^a-z0-9.\\-!&+]')) return 0; - if (! value.match('^[.\\-]')) return 0; - if (! value.match('[.\\-&]$')) return 0; - if (! value.match('(\\.-|-\\.|\\.\\.)')) return 0; + if (value.match('[^a-z0-9.\\-!&+]')) return 0; + if (value.match('^[.\\-]')) return 0; + if (value.match('[.\\-&]$')) return 0; + if (value.match('(\\.-|-\\.|\\.\\.)')) return 0; /// standard IP address } else if (type == 'IP') { diff --git a/samples/js_validate_2.html b/samples/js_validate_2.html index bb6e9ed..1e777f3 100644 --- a/samples/js_validate_2.html +++ b/samples/js_validate_2.html @@ -87,6 +87,7 @@ name: Verify email validate_if: *em equals: email equals_name: email +clear_on_error: 1 ">
-- 2.45.2