« CatalystX/SimpleLogin/TraitFor/Controller/Login/WithRedirect.pm
↑ Summary
CatalystX/SimpleLogin/Controller/Login.pm »
| 1 | package CatalystX::SimpleLogin::TraitFor::Controller::Login::OpenID; | ||
| 2 | |||
| 3 | use MooseX::MethodAttributes (); | ||
| 4 | use MooseX::Types::Common::String qw/ NonEmptySimpleStr /; | ||
| 5 | use Moose::Role -traits => 'MethodAttributes'; | ||
| 6 | use namespace::autoclean; | ||
| 7 | |||
| 8 | has 'openid_realm' => ( | ||
| 9 | is => 'ro', | ||
| 10 | isa => NonEmptySimpleStr, | ||
| 11 | required => 1, | ||
| 12 | default => 'openid', | ||
| 13 | ); | ||
| 14 | |||
| 15 | around 'login_GET' => sub { | ||
| 16 | my $orig = shift; | ||
| 17 | my $self = shift; | ||
| 18 | my ( $c) = @_; | ||
| 19 | |||
| 20 | if($c->req->param("openid.mode")) | ||
| 21 | { | ||
| 22 | if($c->authenticate({},$self->openid_realm)) { | ||
| 23 | $c->flash(success_msg => "You signed in with OpenID!"); | ||
| 24 | $c->res->redirect($self->redirect_after_login_uri($c)); | ||
| 25 | } | ||
| 26 | else | ||
| 27 | { | ||
| 28 | $c->flash(error_msg => "Failed to sign in with OpenID!"); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | else | ||
| 32 | { | ||
| 33 | return $self->$orig(@_); | ||
| 34 | } | ||
| 35 | }; | ||
| 36 | |||
| 37 | =head1 NAME | ||
| 38 | |||
| 39 | CatalystX::SimpleLogin::TraitFor::Controller::Login::OpenID - allows a User to login via OpenID | ||
| 40 | |||
| 41 | =head1 SYNOPSIS | ||
| 42 | |||
| 43 | package MyApp::Controller::NeedsAuth; | ||
| 44 | |||
| 45 | sub something : Path Does('NeedsLogin') { | ||
| 46 | # Redirects to /login if not logged in | ||
| 47 | } | ||
| 48 | |||
| 49 | # Turn on in config | ||
| 50 | MyApp->config('Contoller::Login' => { traits => 'Login::OpenID' }); | ||
| 51 | |||
| 52 | =head1 DESCRIPTION | ||
| 53 | |||
| 54 | Provides the C<login> action with a wrapper to redirect to a page which needs | ||
| 55 | authentication, from which the user was previously redirected. Goes hand in | ||
| 56 | hand with L<Catalyst::ActionRole::NeedsLogin> . | ||
| 57 | |||
| 58 | =head1 WRAPPED METHODS | ||
| 59 | |||
| 60 | =head2 login_GET | ||
| 61 | |||
| 62 | Wrap around an openid authentication if the C<'openid.mode'> request parameter | ||
| 63 | is set. Otherwise, use the default login_GET() method. | ||
| 64 | |||
| 65 | =head1 SEE ALSO | ||
| 66 | |||
| 67 | =over | ||
| 68 | |||
| 69 | =item L<CatalystX::SimpleLogin::Controller::Login> | ||
| 70 | |||
| 71 | =item L<CatalystX::SimpleLogin::Form::Login> | ||
| 72 | |||
| 73 | =back | ||
| 74 | |||
| 75 | =head1 AUTHORS | ||
| 76 | |||
| 77 | See L<CatalystX::SimpleLogin> for authors. | ||
| 78 | |||
| 79 | =head1 LICENSE | ||
| 80 | |||
| 81 | See L<CatalystX::SimpleLogin> for license. | ||
| 82 | |||
| 83 | =cut | ||
| 84 | |||
| 85 | 1; |