diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-04-30 18:05:07 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-04-30 18:05:07 +0200 |
commit | 048767149e571469d888ec81d324caa7b3b64671 (patch) | |
tree | d713208b260e83b9b134b48d61cf2817718efde0 /lib/Travelynx.pm | |
parent | a57a24c2d68daa4d4561ed9035c863e574cdc70a (diff) |
use a separate table for registration tokens
Diffstat (limited to 'lib/Travelynx.pm')
-rwxr-xr-x | lib/Travelynx.pm | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 99d0fb2..b04526a 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -728,17 +728,26 @@ sub startup { ); $self->helper( - 'get_user_token' => sub { - my ( $self, $uid ) = @_; + 'verify_registration_token' => sub { + my ( $self, $uid, $token ) = @_; - my $res = $self->pg->db->select( - 'users', - [ 'name', 'status', 'token' ], - { id => $uid } + my $db = $self->pg->db; + my $tx = $db->begin; + + my $res = $db->select( + 'pending_registrations', + 'count(*) as count', + { + user_id => $uid, + token => $token + } ); - if ( my $ret = $res->array ) { - return @{$ret}; + if ( $res->hash->{count} ) { + $db->update( 'users', { status => 1 }, { id => $uid } ); + $db->delete( 'pending_registrations', { user_id => $uid } ); + $tx->commit; + return 1; } return; } @@ -976,15 +985,23 @@ sub startup { status => 0, public_level => 0, email => $email, - token => $token, password => $password, registered_at => $now, last_seen => $now, }, { returning => 'id' } ); + my $uid = $res->hash->{id}; + + $db->insert( + 'pending_registrations', + { + user_id => $uid, + token => $token + } + ); - return $res->hash->{id}; + return $uid; } ); |