From 8637972b00a5a66c0ed26df6be086321d7f7b840 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sun, 1 Mar 2015 13:30:15 +0200 Subject: [PATCH] Split user creation logic from call_register --- lib/Plack/Middleware/Auth/Complex.pm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Plack/Middleware/Auth/Complex.pm b/lib/Plack/Middleware/Auth/Complex.pm index 55fc5ee..f69bbe6 100644 --- a/lib/Plack/Middleware/Auth/Complex.pm +++ b/lib/Plack/Middleware/Auth/Complex.pm @@ -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 and prepares the SQL statements. +=item B(I<$parms>) + +Inserts a new user into the database. I<$parms> is a +L object containing the request parameters. + =item B(I<$username>) Returns a hashref with (at least) the following keys: passphrase (the -- 2.39.2