use strict;
use warnings;
-our $VERSION = '0.000_001';
+our $VERSION = '0.001';
use parent qw/Plack::Middleware/;
use re '/s';
my %self = $class->default_opts;
%self = (%self, %$opts);
my $self = bless \%self, $class;
- $self->init;
$self
}
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
}
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 {
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;
=item B<init>
-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<post_connect_cb> and prepares the
SQL statements.
=item B<call_register>(I<$req>)
-Handles the C</register> endpoint. I<$req> is a Plack::Request object.
+Handles the C</action/register> endpoint. I<$req> is a Plack::Request object.
=item B<call_passwd>(I<$req>)
-Handles the C</passwd> endpoint. I<$req> is a Plack::Request object.
+Handles the C</action/passwd> endpoint. I<$req> is a Plack::Request object.
=item B<call_request_reset>(I<$req>)
-Handles the C</request-reset> endpoint. I<$req> is a Plack::Request object.
+Handles the C</action/request-reset> endpoint. I<$req> is a Plack::Request object.
=item B<call_reset>(I<$req>)
-Handles the C</reset> endpoint. I<$req> is a Plack::Request object.
+Handles the C</action/reset> endpoint. I<$req> is a Plack::Request object.
=back