diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 52ffa653..7f1a28ae 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -135,7 +135,7 @@ sub machines :Local Args(0) { { order_by => 'stoptime desc', rows => 1 }); ${$machines}{$m}{'idle'} = $idle ? $idle->stoptime : 0; } - + $c->stash->{machines} = $machines; $c->stash->{steps} = [ $c->model('DB::BuildSteps')->search( { finished => 0, 'me.busy' => 1, 'build.busy' => 1, }, diff --git a/src/lib/Hydra/Controller/User.pm b/src/lib/Hydra/Controller/User.pm index 84ec88df..3b9efb0a 100644 --- a/src/lib/Hydra/Controller/User.pm +++ b/src/lib/Hydra/Controller/User.pm @@ -8,6 +8,8 @@ use Crypt::RandPasswd; use Digest::SHA1 qw(sha1_hex); use Hydra::Helper::Nix; use Hydra::Helper::CatalystUtils; +use LWP::UserAgent; +use JSON; __PACKAGE__->config->{namespace} = ''; @@ -70,6 +72,43 @@ sub logout_GET { } +sub persona_login :Path('/persona-login') Args(0) { + my ($self, $c) = @_; + $c->stash->{json} = {}; + die if $c->request->method ne "POST"; + + my $assertion = $c->req->params->{assertion} or die; + + my $ua = new LWP::UserAgent; + my $response = $ua->post( + 'https://verifier.login.persona.org/verify', + { assertion => $assertion, + audience => "http://localhost:3000/" + }); + Catalyst::Exception->throw("Did not get a response from Persona.") unless $response->is_success; + + my $d = decode_json($response->decoded_content) or die; + Catalyst::Exception->throw("Persona says: $d->{reason}") if $d->{status} ne "okay"; + + my $email = $d->{email} or die; + + my $user = $c->find_user({ username => $email }); + + if (!$user) { + $c->model('DB::Users')->create( + { username => $email + , password => "!" + , emailaddress => $email, + }); + $user = $c->find_user({ username => $email }) or die; + } + + $c->set_authenticated($user); + + $c->stash->{json}->{result} = "ok"; +} + + sub captcha :Local Args(0) { my ($self, $c) = @_; $c->create_captcha(); diff --git a/src/root/layout.tt b/src/root/layout.tt index 2337599b..3357726b 100644 --- a/src/root/layout.tt +++ b/src/root/layout.tt @@ -11,6 +11,8 @@