diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 32844185bfb3905381eea85fdfff05678af38a93..c4a2b5321a823e745237b83bcf138286658c99a0 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -1059,12 +1059,15 @@ sub startup { $self->helper( 'run_hook' => sub { - my ( $self, $uid, $reason ) = @_; + my ( $self, $uid, $reason, $callback ) = @_; my $hook = $self->get_webhook($uid); if ( not $hook->{enabled} or not $hook->{url} =~ m{^ https?:// }x ) { + if ($callback) { + &$callback(); + } return; } @@ -1080,7 +1083,12 @@ sub startup { } my $ua = $self->ua; - $ua->request_timeout(10); + if ($callback) { + $ua->request_timeout(4); + } + else { + $ua->request_timeout(10); + } $ua->post_p( $hook->{url} => $header => json => $hook_body )->then( sub { @@ -1093,11 +1101,17 @@ sub startup { $self->mark_hook_status( $uid, $hook->{url}, 1, $tx->result->body ); } + if ($callback) { + &$callback(); + } } )->catch( sub { my ($err) = @_; $self->mark_hook_status( $uid, $hook->{url}, 0, $err ); + if ($callback) { + &$callback(); + } } )->wait; } diff --git a/lib/Travelynx/Controller/Account.pm b/lib/Travelynx/Controller/Account.pm index e272eb1c24b932d5bda5441c47a246e8f2a80d95..e2bfd39f1762448cf2fea900ec43524cf4e01b6e 100644 --- a/lib/Travelynx/Controller/Account.pm +++ b/lib/Travelynx/Controller/Account.pm @@ -246,9 +246,18 @@ sub webhook { token => $hook->{token}, enabled => $hook->{enabled} ); - $self->flash( success => 'webhook' ); - $self->redirect_to('account'); - $self->run_hook( $self->current_user->{id}, 'ping' ); + $self->run_hook( + $self->current_user->{id}, + 'ping', + sub { + $self->render( + 'webhooks', + hook => $self->get_webhook, + new_hook => 1 + ); + } + ); + return; } else { $self->param( url => $hook->{url} ); diff --git a/templates/webhooks.html.ep b/templates/webhooks.html.ep index 0bf8cc80467c858774a912cfd840c4e6f88d0772..b782823bf056bf967bf1bcc732a01346a28fb024 100644 --- a/templates/webhooks.html.ep +++ b/templates/webhooks.html.ep @@ -4,7 +4,29 @@
<%= $hook->{output} %>
+<%= $hook->{output} %>
+@@ -31,22 +53,6 @@ %= text_field 'token', id => 'token', class => 'validate', maxlength => 250
Events werden als JSON POST mit folgender Payload übertragen.