Get email and token from g+
[scpubgit/stemmaweb.git] / lib / stemmaweb / Controller / Users.pm
index 8a5c6ac..61ccbbc 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';
 
@@ -47,7 +54,7 @@ sub index :Path :Args(0) {
 Logging in with openid/google requires two passes through the login
 action, on the 2nd pass the C<openid-check> value is passed in when
 the openid providing webserver links the user back to the stemmaweb
-site. This adaption to the C<login> action sets the realm we are
+site. This adaptation to the C<login> action sets the realm we are
 authenticating against to be C<openid> in this case.
 
 =cut
@@ -75,8 +82,7 @@ before register => sub {
 
     ## When submitting, check recaptcha passes, else re-draw form
     if($c->req->method eq 'POST') {
-        if(!$c->forward('captcha_check')) {
-            
+        if(!$c->forward('captcha_check') || 0 ) {
             ## 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 );
@@ -86,6 +92,41 @@ before register => sub {
     }
 };
 
+before login => sub {
+    my ($self, $c) = @_;
+
+    if ($c->req->params->{email} && $c->req->params->{id_token}) {
+
+        $c->req->param( realm => 'google');
+
+    }
+};
+
+=head2 success
+
+A stub page returned on login / registration success.
+
+=cut
+
+sub success :Local :Args(0) {
+    my ( $self, $c ) = @_;
+
+       $c->load_status_msgs;
+    $c->stash->{template} = 'auth/success.tt';
+}
+
+=head2 post_logout
+
+Return to the index page, not to the login page.
+
+=cut
+
+sub post_logout {
+       my( $self, $c ) = @_;
+       $c->response->redirect( $c->uri_for_action( '/index' ) );
+       $c->detach;
+}
+
 =head1 AUTHOR
 
 A clever guy