X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FPlack%2FMiddleware%2FAuth%2FComplex.pm;h=ac70da693554a5aec710f194b3e386ba93fcf874;hb=d332726d5726e639bc597493c3db9e79fe5a0174;hp=6ef8769f03c9075bc00c4f03000c5bcb042a23eb;hpb=1f7bfc2775dedc426518325a481c4b490a41c6e3;p=plack-middleware-auth-complex.git diff --git a/lib/Plack/Middleware/Auth/Complex.pm b/lib/Plack/Middleware/Auth/Complex.pm index 6ef8769..ac70da6 100644 --- a/lib/Plack/Middleware/Auth/Complex.pm +++ b/lib/Plack/Middleware/Auth/Complex.pm @@ -4,7 +4,7 @@ use 5.014000; use strict; use warnings; -our $VERSION = '0.000_001'; +our $VERSION = '0.001'; use parent qw/Plack::Middleware/; use re '/s'; @@ -43,7 +43,6 @@ sub new { my %self = $class->default_opts; %self = (%self, %$opts); my $self = bless \%self, $class; - $self->init; $self } @@ -59,12 +58,12 @@ sub init { sub create_user { my ($self, $parms) = @_; my %parms = $parms->flatten; - $self->{insert_sth}->execute($parms{username}, $self->hash_passphrase($parms{password}), $parms{email}) + $self->{insert_sth}->execute($parms{username}, $self->hash_passphrase($parms{password}), $parms{email}) or croak $self->{insert_sth}->errstr; } sub get_user { my ($self, $user) = @_; - $self->{select_sth}->execute($user) or croak $self->{sth}->errstr; + $self->{select_sth}->execute($user) or croak $self->{select_sth}->errstr; $self->{select_sth}->fetchrow_hashref } @@ -95,7 +94,7 @@ sub hash_passphrase { sub set_passphrase { my ($self, $username, $passphrase) = @_; - $self->{update_sth}->execute($self->hash_passphrase($passphrase), $username) + $self->{update_sth}->execute($self->hash_passphrase($passphrase), $username) or croak $self->{update_sth}->errstr; } sub make_reset_hmac { @@ -232,6 +231,12 @@ sub call_reset { sub call { my ($self, $env) = @_; + + unless ($self->{init_done}) { + $self->init; + $self->{init_done} = 1; + } + my $auth = $env->{HTTP_AUTHORIZATION}; if ($auth && $auth =~ /^Basic (.*)$/i) { my ($user, $pass) = split /:/, decode_base64($1), 2; @@ -420,7 +425,7 @@ Creates a new AuthComplex object. =item B -Called at the end of the constructor. The default implementation +Called when the first request is received. The default implementation connects to the database, calls C and prepares the SQL statements. @@ -486,19 +491,19 @@ Returns a 401 Authorization required response. =item B(I<$req>) -Handles the C endpoint. I<$req> is a Plack::Request object. +Handles the C endpoint. I<$req> is a Plack::Request object. =item B(I<$req>) -Handles the C endpoint. I<$req> is a Plack::Request object. +Handles the C endpoint. I<$req> is a Plack::Request object. =item B(I<$req>) -Handles the C endpoint. I<$req> is a Plack::Request object. +Handles the C endpoint. I<$req> is a Plack::Request object. =item B(I<$req>) -Handles the C endpoint. I<$req> is a Plack::Request object. +Handles the C endpoint. I<$req> is a Plack::Request object. =back