source:
LATMOS-Accounts-Web/patch/basic_auth.patch
@
883
Last change on this file since 883 was 883, checked in by nanardon, 13 years ago | |
---|---|
File size: 3.3 KB |
-
lib/LATMOS/Accounts/Web.pm
42 42 __PACKAGE__->config( name => 'LATMOS::Accounts::Web' ); 43 43 44 44 __PACKAGE__->config->{'Plugin::Authentication'} = { 45 default_realm => ' la',45 default_realm => 'remote', 46 46 realms => { 47 remote => { 48 credential => { 49 class => 'Remote' 50 }, 51 store => { 52 class => 'Null', 53 }, 54 }, 47 55 la => { 48 56 credential => { 49 57 class => 'La' -
lib/LATMOS/Accounts/Web/Controller/Root.pm
56 56 sub logout : Local { 57 57 my ( $self, $c ) = @_; 58 58 $c->logout; 59 $c->res->redirect($c->uri_for('/')); 59 #$c->res->status(418); 60 60 61 } 61 62 62 63 =head1 AUTHOR -
lib/LATMOS/Accounts/Web/Controller.pm
3 3 use strict; 4 4 use warnings; 5 5 use base 'Catalyst::Controller'; 6 use MIME::Base64; 6 7 7 8 =head1 NAME 8 9 … … 20 21 21 22 =cut 22 23 24 sub auth_required : Private { 25 my ( $self, $c ) = @_; 26 $c->res->status(401); 27 $c->res->content_type('text/plain'); 28 $c->res->body('Authorization required.'); 29 $c->res->headers->push_header( 30 'WWW-Authenticate' => 'Basic realm="Link::Accounts"' 31 ); 32 } 33 23 34 sub begin : Private { 24 35 my ( $self, $c ) = @_; 25 36 26 if (!$c->user_exists) { 37 if ($c->user_exists) { 38 # Set login user: 39 warn $c->model('Accounts')->db->{_user} = $c->user->{username}; 40 } else { 27 41 # No need to login for About section 28 42 if ($c->namespace ne 'about') { 29 if ($c->req->path ne 'login') { 30 $c->forward('/login'); 43 if ($c->authenticate({}, 'remote')) { 44 # Set login user: 45 $c->model('Accounts')->db->{_user} = $c->user->{username}; 46 } elsif (my $authheader = $c->req->headers->header('Authorization')) { 47 # TODO check auth type 48 my ($type, $base64) = $authheader =~ /(\w+) (\S+)/; 49 my ($login, $pass) = decode_base64($base64) =~ /^([^:]+):(.*)/; 50 if (!$c->authenticate({ 51 username => $login, 52 password => $pass }, 'la')) { 53 $c->forward('auth_required'); 54 return; 55 } 56 } else { 57 $c->forward('auth_required'); 58 return; 31 59 } 32 return;33 60 } 34 } else {35 $c->model('Accounts')->db->connect(36 $c->user->{username},37 $c->user->{password});38 61 } 39 62 } 40 63 … … 51 74 52 75 sub end : ActionClass('RenderView') { 53 76 my ($self, $c) = @_; 54 $c->forward($c->view('TT')) ;77 $c->forward($c->view('TT')) unless($c->res->body); 55 78 $c->model('Accounts')->db->rollback; 56 79 $c->model('Accounts')->call_batch_sync; 57 80 }
Note: See TracBrowser
for help on using the repository browser.