From: Errietta Kostala Date: Thu, 22 Jan 2015 15:45:47 +0000 (+0000) Subject: Allow having no captcha, add registration test X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=32d1fbf8a53b71b4e981c1b9e7aa6e966b872394;p=scpubgit%2Fstemmaweb.git Allow having no captcha, add registration test --- diff --git a/lib/stemmaweb/Controller/Users.pm b/lib/stemmaweb/Controller/Users.pm index 1e87b37..96516a7 100644 --- a/lib/stemmaweb/Controller/Users.pm +++ b/lib/stemmaweb/Controller/Users.pm @@ -83,12 +83,16 @@ form with an error message. before register => sub { my ($self, $c) = @_; + warn $c->config->{'Registration'}->{'no_recaptcha'}; + ## Puts HTML into stash in "recaptcha" key. - $c->forward('captcha_get'); + if (!$c->config->{'Registration'}->{'no_recaptcha'}) { + $c->forward('captcha_get'); + } ## When submitting, check recaptcha passes, else re-draw form if($c->req->method eq 'POST') { - if(!$c->forward('captcha_check') || 0 ) { + if ( !$c->config->{'Registration'}->{'no_recaptcha'} && !$c->forward('captcha_check') ) { ## Need these two lines to detach, so end can draw the correct template again: my $form = $self->form_handler->new( active => [ $self->login_id_field, 'password', 'confirm_password' ] ); $c->stash( template => $self->register_template, form => $form ); diff --git a/stemmaweb.conf b/stemmaweb.conf index 3bfed71..e01f291 100644 --- a/stemmaweb.conf +++ b/stemmaweb.conf @@ -14,3 +14,6 @@ name = stemmaweb public_cert_url https://www.googleapis.com/oauth2/v1/certs client_id 577442226093-pi2ud795g49ibip78bgfoabhl4kdrguc.apps.googleusercontent.com + + no_recaptcha 0 + diff --git a/stemmaweb_tests.conf b/stemmaweb_tests.conf new file mode 100644 index 0000000..a4e4302 --- /dev/null +++ b/stemmaweb_tests.conf @@ -0,0 +1,3 @@ + + no_recaptcha 1 + diff --git a/t/05register.t b/t/05register.t new file mode 100644 index 0000000..57e5b59 --- /dev/null +++ b/t/05register.t @@ -0,0 +1,45 @@ +use warnings; +use strict; + +use stemmaweb; +use LWP::Protocol::PSGI; +use Test::WWW::Mechanize; + +use Test::More; +use HTML::TreeBuilder; +use Data::Dumper; + +use FindBin; +use lib ("$FindBin::Bin/lib"); + +use stemmaweb::Test::DB; + +stemmaweb::Test::DB->new_db; + +LWP::Protocol::PSGI->register(stemmaweb->psgi_app); + +use stemmaweb::Test::Common; + +my $ua = Test::WWW::Mechanize->new; + +$ua->get_ok('http://localhost/register'); + +my $response = $ua->submit_form( + fields => { + username => 'user2@example.org', + password => 'UserPass', + confirm_password => 'UserPass', + }); + +warn $ua->content; + +=cut + +$ua->content_contains('Stemmaweb - Logged in', 'Log in successful.'); + +my $content = $ua->get('/'); +$ua->content_contains('Hello! user@example.org', 'We are logged in.'); + +=cut + +done_testing; diff --git a/t/lib/stemmaweb/Test/Common.pm b/t/lib/stemmaweb/Test/Common.pm new file mode 100644 index 0000000..85a6a79 --- /dev/null +++ b/t/lib/stemmaweb/Test/Common.pm @@ -0,0 +1,11 @@ +package stemmaweb::Test::Common; + +use strict; +use warnings; + +BEGIN { + $ENV{STEMMAWEB_CONFIG_LOCAL_SUFFIX} = 'tests'; + $ENV{STEMMAWEB_CONFIG_PATH} = '.'; +} + +1;