diff options
author | Struan Donald <struan@exo.org.uk> | 2011-05-12 11:50:32 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-05-12 11:50:32 +0100 |
commit | 105291154c3dfaa905202ff576c51097759094df (patch) | |
tree | e979ccedc614a67b7dac91d971da8f5fbde1ca05 /perllib/FixMyStreet/App/Controller/Alert.pm | |
parent | c0cfc5f8d5c9b1c1728e603a368fbe4570393615 (diff) |
move confirmation email sending to own method
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Alert.pm | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 370992854..56464dd64 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -221,30 +221,12 @@ sub subscribe_email : Private { } elsif ( $type eq 'local' ) { $c->forward('create_local_alert'); - $c->stash->{template} = 'email_sent.html'; } else { throw FixMyStreet::Alert::Error('Invalid type'); } - my $token = $c->model("DB::Token")->create( - { - scope => 'alert', - data => { id => $c->stash->{alert}->id, type => 'subscribe', email => $email } - } - ); - - $c->stash->{token_url} = $c->uri_for_email( '/A', $token->token ); - - my $sender = mySociety::Config::get('CONTACT_EMAIL'); - - $c->send_email( - 'alert-confirm.txt', - { - to => $email, - from => $sender - } - ); + $c->forward('send_confirmation_email'); } =head2 confirm @@ -328,6 +310,42 @@ sub create_local_alert : Private { $c->log->debug( 'created alert ' . $alert->id ); } +=head2 send_confirmation_email + +Generate a token and send out an alert subscription confirmation email and +then display confirmation page. + +=cut + +sub send_confirmation_email : Private { + my ( $self, $c ) = @_; + + my $token = $c->model("DB::Token")->create( + { + scope => 'alert', + data => { + id => $c->stash->{alert}->id, + type => 'subscribe', + email => $c->stash->{alert}->user->email + } + } + ); + + $c->stash->{token_url} = $c->uri_for_email( '/A', $token->token ); + + my $sender = mySociety::Config::get('CONTACT_EMAIL'); + + $c->send_email( + 'alert-confirm.txt', + { + to => $c->stash->{alert}->user->email, + from => $sender + } + ); + + $c->stash->{template} = 'email_sent.html'; +} + =head2 prettify_pc This will canonicalise and prettify the postcode and stick a pretty_pc and pretty_pc_text in the stash. |