realm => 'restricted area',
cache_fail => 0,
cache_max_age => 5 * 60,
- token_max_age => 60 * 60 * 24,
+ token_max_age => 60 * 60,
username_regex => qr/^\w{2,20}$/a,
register_url => '/action/register',
passwd_url => '/action/passwd',
$self->{update_sth} = $self->{dbh}->prepare($self->{update_pass}) or die $self->{dbh}->errstr;
}
+sub create_user {
+ my ($self, $parms) = @_;
+ my %parms = $parms->flatten;
+ $self->{insert_sth}->execute($parms{username}, $self->hash_passphrase($parms{password}), $parms{email})
+}
+
sub get_user {
my ($self, $user) = @_;
$self->{select_sth}->execute($user) or die $self->{sth}->errstr;
header => [
From => $self->{mail_from},
To => $user->{email},
- Subject => $user->{mail_subject},
+ Subject => $self->{mail_subject},
],
body => $self->mail_body($username, $token),
));
return $self->bad_request('Username must match ' . $self->{username_regex}) unless $parms{username} =~ /$self->{username_regex}/;
return $self->bad_request('Username already in use') if $self->get_user($parms{username});
return $self->bad_request('The two passwords do not match') unless $parms{password} eq $parms{confirm_password};
- $self->{insert_sth}->execute($parms{username}, $self->hash_passphrase($parms{password}), $parms{email});
+
+ $self->create_user($req->parameters);
return $self->reply('Registered successfully')
}
AuthComplex sets REMOTE_USER if the request includes correct basic
authentication and intercepts POST requests to some configurable URLs.
-It also sets C<$env->{authcomplex}> to itself before passing the
+It also sets C<< $env->{authcomplex} >> to itself before passing the
request.
Some options can be controlled by passing a hashref to the
=item token_max_age
-Password reset token validity, in seconds. Defaults to 24 hours.
+Password reset token validity, in seconds. Defaults to 1 hour.
=item username_regex
connects to the database, calls C<post_connect_cb> and prepares the
SQL statements.
+=item B<create_user>(I<$parms>)
+
+Inserts a new user into the database. I<$parms> is a
+L<Hash::MultiValue> object containing the request parameters.
+
=item B<get_user>(I<$username>)
Returns a hashref with (at least) the following keys: passphrase (the