Split user creation logic from call_register
authorMarius Gavrilescu <marius@ieval.ro>
Sun, 1 Mar 2015 11:30:15 +0000 (13:30 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sun, 1 Mar 2015 11:30:15 +0000 (13:30 +0200)
lib/Plack/Middleware/Auth/Complex.pm

index 55fc5ee1861579b4af2e2a6de06fc8ee5f50be2c..f69bbe6aa6e1b91ba570d9bc37da6836304d7fdb 100644 (file)
@@ -55,6 +55,12 @@ sub init {
        $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;
@@ -172,7 +178,8 @@ sub call_register {
        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')
 }
 
@@ -417,6 +424,11 @@ Called at the end of the constructor. The default implementation
 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
This page took 0.011646 seconds and 4 git commands to generate.