]> Dogcows Code - chaz/p5-CGI-Ex/commitdiff
CGI::Ex 2.20 v2.20
authorPaul Seamons <perl@seamons.com>
Mon, 8 Oct 2007 00:00:00 +0000 (00:00 +0000)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Fri, 9 May 2014 23:46:42 +0000 (17:46 -0600)
14 files changed:
Changes
META.yml
lib/CGI/Ex.pm
lib/CGI/Ex/App.pm
lib/CGI/Ex/Auth.pm
lib/CGI/Ex/Conf.pm
lib/CGI/Ex/Die.pm
lib/CGI/Ex/Dump.pm
lib/CGI/Ex/Fill.pm
lib/CGI/Ex/JSONDump.pm
lib/CGI/Ex/Template.pm
lib/CGI/Ex/Validate.pm
lib/CGI/Ex/validate.js
samples/js_validate_2.html

diff --git a/Changes b/Changes
index 635b3c528ba2d51176f6c0e5afac11a1c8e7d5fb..f1577ae3f41e471ccc943eba34899d0fdbd8e045 100644 (file)
--- 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
index 5df1a6f84719bc5d12056cda891f06cc217bbd41..8a005adb3e04affd93442b8352e513ebdd0be023 100644 (file)
--- 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
index f33b9b3e7d727ea774a8fc028f58584d186d5582..faa5a3614da050b1e72059cdd255b983dde40ea4 100644 (file)
@@ -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
index da5904f55a0f5a3705bc4bc4c7186ac0dcceafa0..5e78cc3e398bc92eb8130f992f14c1027fd47b60 100644 (file)
@@ -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) {
index 85c28fe0dc0794c0c8d82a09698a14bb13b8a0cb..a762ead3de1944ae0b767ad913319dc2f7b27836 100644 (file)
@@ -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
index b62674b3b120ba3d0896f10bc7cdae2887987571..0b13ca86a85db7b723659055d8d784305ffbfbcb 100644 (file)
@@ -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';
 
index 62f8debb6af3bc07cd539f54444611b97b373c94..a87f50097e7348cc2bbf17c3b21ffa15373fbbbe 100644 (file)
@@ -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;
index 5039cc2dab187898c035c1af1472c956b71674dd..d83d6c2cab8edb190f4225c918d65538eea18b5f 100644 (file)
@@ -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);
index 9641f18867c7cd334266a600145f98fc015a0b49..c4ab9f4621910c0870c6ff93893277a00c24f32b 100644 (file)
@@ -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);
 };
index 6d58f0923803880524ac40ab9711a427982c49e1..f212ec75990e69995511889e996b66522d690573 100644 (file)
@@ -17,7 +17,7 @@ use strict;
 use base qw(Exporter);
 
 BEGIN {
-    $VERSION  = '2.19';
+    $VERSION  = '2.20';
 
     @EXPORT = qw(JSONDump);
     @EXPORT_OK = @EXPORT;
index d0a837e94ea9bc2170c459ff7f99d02515d89560..715dc19290e7a1f6e8cc2a63b93c9c9fe91c75fb 100644 (file)
@@ -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;
index 651b3c903e5f7ffc3ffa1e231554e52a80c2ce56..18a350192a13064782302d62875e2289bbf758a2 100644 (file)
@@ -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<clear_on_error>
+
+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
index 8ac047976a473c7fc9ab25ca4e8a3906a58958a4..40b4c04d6d7f92d615df5c69fe65c9e5e7c9849e 100644 (file)
@@ -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') {
index bb6e9edcde8b62408514bb9d77ffa2a8289fe626..1e777f3247b4ba9505ca3baf7a58e37a2ec15110 100644 (file)
@@ -87,6 +87,7 @@ name: Verify email
 validate_if: *em
 equals: email
 equals_name: email
+clear_on_error: 1
 "><br>
     <span id=email2_error class=error></span>
   </td>
This page took 0.039888 seconds and 4 git commands to generate.