[interchange-cvs] interchange - heins modified code/SystemTag/captcha.coretag

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Fri Aug 11 10:39:03 EDT 2006


User:      heins
Date:      2006-08-11 14:39:03 GMT
Modified:  code/SystemTag captcha.coretag
Log:
* Make one image function, modified by parameters.

* Add relative and name-only options to control image function.

* Add reset=1 option to allow more than one captcha per page
  transaction (however unlikely that is to be needed).

* Changed docs to reflect this.

* Add example to docs.

Revision  Changes    Path
1.2       +66 -22    interchange/code/SystemTag/captcha.coretag


rev 1.2, prev_rev 1.1
Index: captcha.coretag
===================================================================
RCS file: /var/cvs/interchange/code/SystemTag/captcha.coretag,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- captcha.coretag	6 Aug 2006 19:51:38 -0000	1.1
+++ captcha.coretag	11 Aug 2006 14:39:03 -0000	1.2
@@ -1,4 +1,5 @@
 UserTag captcha Order function
+UserTag captcha attrAlias func function
 UserTag captcha addAttr
 UserTag captcha Description Generate captcha codes for authentication check
 UserTag captcha Routine <<EOR
@@ -80,9 +81,17 @@
 	else {
 	    my $save_u = umask($::Variable->{CAPTCHA_UMASK} || 2);
 
-		if($func eq 'code') {
+		if($opt->{reset}) {
+			undef $Vend::Captcha;
+			delete $Vend::Session->{captcha};
+		}
+
+		if($Vend::Captcha) {
 			$code ||= $Vend::Session->{captcha};
-			return $code if $code;
+		}
+
+		if($func eq 'code' and $code) {
+			return $code;
 		}
 
 	   eval {
@@ -102,14 +111,23 @@
 			return $code;
 		}
 	
-		if($func =~ /^rel(ative)?ima?ge?$/) {
-			return "$subdir/$code.png";
+		# Now probably an image function.
+
+		unless ($func =~ /ima?ge?/)  {
+			$Tag->error({
+							name => $en,
+							set => errmsg("Unknown function %s", $func),
+						});
+			return undef;
 		}
-		if($func =~ /^ima?ge?$/) {
-			return "$imgpath/$code.png";
+
+		my $path = $opt->{relative} ? "$subdir/$code.png" : "$imgpath/$code.png";
+
+		if(! $opt->{name_only}) {
+			return 	$Tag->image($path);
 		}
-		if($func =~ /^ima?ge?.*tag/) {
-			return 	$Tag->image("$imgpath/$code.png");
+		else {
+			return $path;
 		}
 	}
 
@@ -155,15 +173,10 @@
 
 =item image
 
-Returns the full URL path to the image (based on image directory). 
-
-=item relative_image
-
-Returns a relative URL path to the image.
-
-=item image_tag
-
-Returns an image tag as generated by Interchange's [image] tag.
+Returns an IMG tag as generated by Interchange's [image] tag. If the
+name-only=1 option is passed, no surrounding IMG tag will be generated,
+only the image name. If the C<relative=1> option is passed, that name
+will not be prefaced with the ImageDir.
 
 =back
 
@@ -171,9 +184,10 @@
 
 =over 4
 
-=item length
+=item guess 
 
-Length of the input for the captcha. Default is 4 characters.
+The input from the user when the function is C<check>. Default is the
+contents of [cgi mv_captcha_guess].
 
 =item image-subdir
 
@@ -191,10 +205,18 @@
 Interchange IMAGE_DIR variable based in the Interchange DOCROOT
 variable, with the subdirectory above, i.e. C<[var DOCROOT][var IMAGE_DIR]/captcha>.
 
-=item guess 
+=item length
 
-The input from the user when the function is C<check>. Default is the
-contents of [cgi mv_captcha_guess].
+Length of the input for the captcha. Default is 4 characters.
+
+=item name-only 
+
+When set, tells the image function to not generate an HTML IMG tag.
+
+=item relative 
+
+When set, tells the image function (when in name-only mode) to
+return relative path.
 
 =item source 
 
@@ -202,6 +224,28 @@
 contents of the last-generated captcha, or [cgi mv_captcha_source].
 
 =back
+
+=head1 EXAMPLE
+
+	[if cgi mv_captcha_guess]
+		[tmp good][captcha check][/tmp]
+		[if scratch good]
+			You guessed right!
+		[else]
+			Sorry, try again.
+		[/else]
+		[/if]
+		<br>
+	[/if]
+
+	[captcha function=image]
+
+	<form action="[process href="@@MV_PAGE@@"]">
+	<input type=text name=mv_captcha_guess size value="">
+	<input type=submit value="Guess">
+	</form>
+
+	[error auto=1]
 
 =head1 PREREQUISITES
 








More information about the interchange-cvs mailing list