Allow having no captcha, add registration test
[scpubgit/stemmaweb.git] / lib / stemmaweb / Controller / Users.pm
index 32f629f..96516a7 100644 (file)
@@ -2,6 +2,13 @@ package stemmaweb::Controller::Users;
 use Moose;
 use namespace::autoclean;
 
+use Google::JWT;
+
+use JSON::MaybeXS;
+use JSON::WebToken;
+
+use MIME::Base64;
+
 BEGIN {extends 'CatalystX::Controller::Auth'; }
 with 'Catalyst::TraitFor::Controller::reCAPTCHA';
 
@@ -56,6 +63,12 @@ before login => sub {
   my($self, $c) = @_;
   $c->req->param( realm => 'openid')
     if $c->req->param('openid-check');
+
+  if ($c->req->params->{email} && $c->req->params->{id_token}) {
+    $c->req->param( realm => 'google');
+  }
+
+  $c->stash->{google_client_id} = $c->config->{'Authentication::Credential::Google'}->{client_id};
 };
 
 =head2 register with recaptcha
@@ -70,13 +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')) {
-            
+        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 );