diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-04-22 12:11:22 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-04-22 12:11:22 +0200 |
commit | 2aece368035ab71a58f719f7ec526d566839980b (patch) | |
tree | 05d7d94e0b33b9891960bc32110c5d705cac6c38 /lib/Travelynx/Controller | |
parent | 4ed24c55653dafbac3053f57d6d3b094d4ad7fb5 (diff) |
Use Mojo::Pg for all remaining Controller and Helper logic
Diffstat (limited to 'lib/Travelynx/Controller')
-rw-r--r-- | lib/Travelynx/Controller/Account.pm | 12 | ||||
-rwxr-xr-x | lib/Travelynx/Controller/Api.pm | 23 | ||||
-rwxr-xr-x | lib/Travelynx/Controller/Traveling.pm | 33 |
3 files changed, 38 insertions, 30 deletions
diff --git a/lib/Travelynx/Controller/Account.pm b/lib/Travelynx/Controller/Account.pm index 7753493..0037e16 100644 --- a/lib/Travelynx/Controller/Account.pm +++ b/lib/Travelynx/Controller/Account.pm @@ -114,10 +114,11 @@ sub register { return; } - my $token = make_token(); - my $pw_hash = hash_password($password); - $self->app->dbh->begin_work; - my $user_id = $self->add_user( $user, $email, $token, $pw_hash ); + my $token = make_token(); + my $pw_hash = hash_password($password); + my $db = $self->pg->db; + my $tx = $db->begin; + my $user_id = $self->add_user( $db, $user, $email, $token, $pw_hash ); my $reg_url = $self->url_for('reg')->to_abs->scheme('https'); my $imprint_url = $self->url_for('impressum')->to_abs->scheme('https'); @@ -143,11 +144,10 @@ sub register { my $success = $self->sendmail->custom( $email, 'Registrierung bei travelynx', $body ); if ($success) { - $self->app->dbh->commit; + $tx->commit; $self->render( 'login', from => 'register' ); } else { - $self->app->dbh->rollback; $self->render( 'register', invalid => 'sendmail' ); } } diff --git a/lib/Travelynx/Controller/Api.pm b/lib/Travelynx/Controller/Api.pm index c3eccb8..a9500f1 100755 --- a/lib/Travelynx/Controller/Api.pm +++ b/lib/Travelynx/Controller/Api.pm @@ -106,12 +106,27 @@ sub set_token { } if ( $self->param('action') eq 'delete' ) { - $self->app->drop_api_token_query->execute( $self->current_user->{id}, - $token_id ); + $self->pg->db->delete( + 'tokens', + { + user_id => $self->current_user->{id}, + type => $token_id + } + ); } else { - $self->app->set_api_token_query->execute( $self->current_user->{id}, - $token_id, $token ); + $self->pg->db->insert( + 'tokens', + { + user_id => $self->current_user->{id}, + type => $token_id, + token => $token + }, + { + on_conflict => \ + '(user_id, type) do update set token = EXCLUDED.token' + }, + ); } $self->redirect_to('account'); } diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index 43dd7f0..b43c891 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -461,13 +461,15 @@ sub edit_journey { time_zone => 'Europe/Berlin' ); - $self->app->dbh->begin_work; + my $db = $self->pg->db; + my $tx = $db->begin; for my $key (qw(sched_departure rt_departure sched_arrival rt_arrival)) { my $datetime = $parser->parse_datetime( $self->param($key) ); if ( $datetime and $datetime->epoch ne $journey->{$key}->epoch ) { $error = $self->update_journey_part( + $db, $journey->{ids}[0], $journey->{ids}[1], $key, $datetime @@ -478,27 +480,21 @@ sub edit_journey { } } - if ($error) { - $self->app->dbh->rollback; - } - else { + if ( not $error ) { $journey = $self->get_journey( uid => $uid, + db => $db, checkout_id => $checkout_id, verbose => 1 ); $error = $self->journey_sanity_check($journey); - if ($error) { - $self->app->dbh->rollback; - } - else { - $self->invalidate_stats_cache( $journey->{checkout} ); - $self->app->dbh->commit; - $self->redirect_to("/journey/${uid}-${checkout_id}"); - return; - } } - + if ( not $error ) { + $tx->commit; + $self->redirect_to("/journey/${uid}-${checkout_id}"); + $self->invalidate_stats_cache( $journey->{checkout} ); + return; + } } for my $key (qw(sched_departure rt_departure sched_arrival rt_arrival)) { @@ -566,15 +562,12 @@ sub add_journey_form { $opt{$key} = $self->param($key); } - $self->app->dbh->begin_work; - - my ( $checkin_id, $checkout_id, $error ) = $self->add_journey(%opt); + #my ( $checkin_id, $checkout_id, $error ) = $self->add_journey(%opt); - $self->app->dbh->rollback; $self->render( 'add_journey', with_autocomplete => 1, - error => $error + error => 'not implemented', ); return; } |