diff options
author | Struan Donald <struan@exo.org.uk> | 2011-05-11 11:37:36 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-05-11 11:37:36 +0100 |
commit | 5f1db7700255e00ce492d57939f861f76b6ddadf (patch) | |
tree | efa957abee5ae5fc36b9d3be871ec1f18ba92465 /perllib/FixMyStreet/App/Controller | |
parent | 4bb7f2af6a5a2e5f401d47f8aa2291000f95a641 (diff) |
confirm alert subscription
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Alert.pm | 24 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Tokens.pm | 32 |
2 files changed, 54 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 12624b8f2..742aa6c1d 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -298,7 +298,7 @@ sub subscribe_email : Private { $options->{parameter2} = $params[1]; } - $alert = $c->model('DB::Alert')->find( $options ); + $alert = $c->model('DB::Alert')->find($options); unless ($alert) { $options->{cobrand} = $c->cobrand->moniker(); @@ -335,6 +335,28 @@ sub subscribe_email : Private { ); } +=head2 confirm + +Confirm signup to an alert + +=cut + +sub confirm : Private { + my ( $self, $c ) = @_; + + my $alert = $c->stash->{alert}; + $c->stash->{template} = 'alert/confirm.html'; + + if ( $c->stash->{confirm_type} eq 'subscribe' ) { + $alert->confirm(); + $alert->update; + } + elsif ( $c->stash->{confirm_type} eq 'unsubscribe' ) { + $alert->delete(); + $alert->update; + } +} + =head2 prettify_pc This will canonicalise and prettify the postcode and stick a pretty_pc and pretty_pc_text in the stash. diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm index 369be23c6..9cbbc42b4 100644 --- a/perllib/FixMyStreet/App/Controller/Tokens.pm +++ b/perllib/FixMyStreet/App/Controller/Tokens.pm @@ -82,7 +82,37 @@ sub redirect_to_partial_problem : Path('/L') { my ( $self, $c, $token_code ) = @_; my $url = $c->uri_for( "/report/new", { partial => $token_code } ); - return $c->res->redirect( $url ); + return $c->res->redirect($url); +} + +=head2 confirm_alert + + /A/([0-9A-Za-z]{16,18}).*$ + +Confirm an alert - url appears in emails sent to users after they create the +alert but are not logged in. + +=cut + +sub confirm_alert : Path('/A') { + my ( $self, $c, $token_code ) = @_; + + my $auth_token = $c->forward( 'load_auth_token', [ $token_code, 'alert' ] ); + + # Load the problem + my $alert_id = $auth_token->data->{id}; + $c->stash->{confirm_type} = $auth_token->data->{type}; + my $alert = $c->model('DB::Alert')->find( { id => $alert_id } ) + || $c->detach('token_error'); + $c->stash->{alert} = $alert; + + # check that this email or domain are not the cause of abuse. If so hide it. + if ( $alert->is_from_abuser ) { + $c->stash->{template} = 'tokens/abuse.html'; + return; + } + + $c->forward('/alert/confirm'); } =head2 load_auth_token |