Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added captcha register thingie

  • Loading branch information...
commit 94a391245f171c2398dd4de1d7ff01cccee25cce 1 parent b39c384
Stefan Corneliu Petrea authored May 06, 2011
6  .gitignore
... ...
@@ -0,0 +1,6 @@
  1
+root/static/captcha_images/*
  2
+root/static/temp_dir/*
  3
+pdfs
  4
+Makefile.old
  5
+blib/
  6
+*.swp
3  Makefile.PL
@@ -24,6 +24,9 @@ requires 'MooseX::NonMoose';
24 24
 requires 'DBIx::Class::TimeStamp';
25 25
 requires 'DBD::Pg';
26 26
 
  27
+requires 'String::Random';
  28
+requires 'GD::SecurityImage';
  29
+
27 30
 requires 'IO::All' => '0.41';
28 31
 requires 'XML::FeedPP' => '0.42';
29 32
 requires 'Moose';
2  debug.sh
... ...
@@ -1 +1 @@
1  
-perl ./script/swissarmyknife_server.pl -r
  1
+CATALYST_REPL=1 perl ./script/swissarmyknife_server.pl -r
6  lib/swissarmyknife.pm
... ...
@@ -1,7 +1,5 @@
1 1
 package swissarmyknife;
2 2
 use Moose;
3  
-use namespace::autoclean;
4  
-
5 3
 use Catalyst::Runtime 5.80;
6 4
 
7 5
 use Catalyst qw/
@@ -17,6 +15,8 @@ use Catalyst qw/
17 15
 /;
18 16
 
19 17
 extends 'Catalyst';
  18
+#with 'CatalystX::REPL';
  19
+use namespace::autoclean;
20 20
 
21 21
 
22 22
 
@@ -54,7 +54,7 @@ __PACKAGE__->config(
54 54
 
55 55
 );
56 56
 
57  
-__PACKAGE__->setup();
  57
+__PACKAGE__->setup(qw/-Debug/);
58 58
 
59 59
 
60 60
 1;
64  lib/swissarmyknife/Controller/Login.pm
@@ -2,13 +2,15 @@ package swissarmyknife::Controller::Login;
2 2
 use Moose;
3 3
 use Data::Dumper;
4 4
 use Digest::MD5 qw(md5_hex);
  5
+use GD::SecurityImage;
  6
+use String::Random;
  7
+use Devel::REPL;
5 8
 
6 9
 
7 10
 BEGIN{ 
8 11
     extends 'Catalyst::Controller::HTML::FormFu';
9 12
 };
10 13
 
11  
-
12 14
 #extends 'Catalyst::Plugin::Authentication';
13 15
 use namespace::autoclean;
14 16
 
@@ -33,9 +35,10 @@ sub index
33 35
 }
34 36
 
35 37
 
36  
-
37  
-
38  
-sub generateCaptcha {
  38
+sub generateCaptcha 
  39
+:Private
  40
+{
  41
+    my ($self,$c) = @_;
39 42
 	my $image = GD::SecurityImage->new(
40 43
 		width   => 80,
41 44
 		height  => 60,
@@ -53,12 +56,13 @@ sub generateCaptcha {
53 56
     my $md5 = md5_hex($data);
54 57
 
55 58
 	my $captcha_file = "$md5.png";#probably needs to be a random file name
  59
+    my $output_path = $c->config->{root_dir}."root/static/captcha_images/$captcha_file";
56 60
 
57  
-	
58  
-	open my $f , ">".$c->config->{root_dir}."root/static/$captcha_file";
  61
+	open my $f , ">$output_path";
59 62
 	print $f $data;
  63
+    close $f;
60 64
 
61  
-	return $captcha_file;
  65
+	return "static/captcha_images/$captcha_file";
62 66
 };
63 67
 
64 68
 sub register
@@ -69,9 +73,40 @@ sub register
69 73
     my ( $self, $c) = @_;
70 74
 
71 75
 
  76
+    my $captcha_img = $c->forward("generateCaptcha");
  77
+
  78
+
  79
+
  80
+    ############ devel::repl break
  81
+    #my $repl = Devel::REPL->new;
  82
+    #$repl->load_plugin($_) for qw(History LexEnv Packages PPI);
  83
+    #$Devel::REPL::Plugin::Packages::DefaultScratchpad::ctx = $c;
  84
+    ##$repl::Plugin::Packages::DefaultScratchpad::ctx = $c;
  85
+    ##$main::ctx = $c;
  86
+    #$repl->run;
  87
+    ############ 
  88
+    
  89
+
  90
+    #unless( $c->stash->{form}->get_all_element({name=>"captcha"})) {
  91
+        #die "sudden death";
  92
+    #};
  93
+
  94
+
  95
+    $c->stash->{form}->get_all_element({name => "captchaimg"})->attributes({ src=>$captcha_img });
  96
+
  97
+
  98
+    #$c->stash->{form}->insert_after(
  99
+        #$c->stash->{form}->element({
  100
+                #type=>"Block",
  101
+                #name=>"captchaimg",
  102
+                #tag=>"div",
  103
+                #content_xml=>"<img src=\"$captcha_img\"/>",
  104
+        #})->clone,
  105
+        #$c->stash->{form}->get_all_element({name=>"captcha"}),
  106
+    #);
  107
+
72 108
     $c->stash( 
73 109
         template=>'register.tt',
74  
-        image=>,
75 110
     );
76 111
 }
77 112
 
@@ -83,7 +118,6 @@ sub login
83 118
 {
84 119
     my ( $self, $c, $message ) = @_;
85 120
 
86  
-
87 121
     #just for testing out the DB
88 122
     map { warn $_->username."\n";  } $c->model("DB")->resultset("User")->all;
89 123
 
@@ -117,18 +151,6 @@ sub login
117 151
     );
118 152
 }
119 153
 
120  
-
121  
-=head1 AUTHOR
122  
-
123  
-s,,,
124  
-
125  
-=head1 LICENSE
126  
-
127  
-This library is free software. You can redistribute it and/or modify
128  
-it under the same terms as Perl itself.
129  
-
130  
-=cut
131  
-
132 154
 __PACKAGE__->meta->make_immutable;
133 155
 
134 156
 1;
40  root/forms/login/register.yml
... ...
@@ -0,0 +1,40 @@
  1
+---
  2
+action: /login
  3
+indicator: submit
  4
+auto_fieldset: 1
  5
+
  6
+elements:
  7
+  - type: Text
  8
+    name: username
  9
+    label: username
  10
+    constraints:
  11
+      - Required
  12
+
  13
+  - type: Password
  14
+    name: password
  15
+    label: password
  16
+    constraints:
  17
+      - Required
  18
+
  19
+  - type: Password
  20
+    name: confirmpw
  21
+    label: Confirm password
  22
+    constraints:
  23
+      - Required
  24
+
  25
+  - type: Text
  26
+    name: captcha
  27
+    label: Please verify this captcha
  28
+    constraints:
  29
+      - Required
  30
+  - type: Block
  31
+    name: captchaimg
  32
+    tag: img
  33
+
  34
+  - type: Submit
  35
+    value: submit
  36
+    name: submit
  37
+
  38
+constraints:
  39
+  - SingleValue
  40
+
21  root/register.tt
... ...
@@ -0,0 +1,21 @@
  1
+[% PROCESS header.tt %]
  2
+
  3
+[% IF not c.user %]
  4
+
  5
+
  6
+<div class="loginbox">
  7
+[% form %]
  8
+</div>
  9
+
  10
+[% ELSE %]
  11
+
  12
+
  13
+<div class="loginbox">
  14
+[% form %]
  15
+</div>
  16
+
  17
+[% END %]
  18
+
  19
+
  20
+
  21
+[% PROCESS footer.tt %]
0  root/static/captcha_images/empty
No changes.
0  root/static/temp_dir/empty
No changes.

0 notes on commit 94a3912

Please sign in to comment.
Something went wrong with that request. Please try again.