aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Alert.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Alert.pm104
1 files changed, 66 insertions, 38 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm
index 3d2c86970..12624b8f2 100644
--- a/perllib/FixMyStreet/App/Controller/Alert.pm
+++ b/perllib/FixMyStreet/App/Controller/Alert.pm
@@ -27,7 +27,6 @@ Show the alerts page
sub index : Path('') : Args(0) {
my ( $self, $c ) = @_;
-
# my $q = shift;
# my $cobrand = Page::get_cobrand($q);
# my $error = shift;
@@ -67,7 +66,7 @@ sub index : Path('') : Args(0) {
sub list : Path('list') : Args(0) {
my ( $self, $c ) = @_;
- $c->stash->{rznvy} = $c->req->param('rznvy');
+ $c->stash->{rznvy} = $c->req->param('rznvy');
$c->stash->{selected_feed} = $c->req->param('feed');
# my ($q, @errors) = @_;
@@ -172,10 +171,11 @@ Target for subscribe form
sub subscribe : Path('subscribe') : Args(0) {
my ( $self, $c ) = @_;
- if ( $c->req->param( 'rss' ) ) {
- $c->detach( 'rss' );
- } elsif ( $c->req->param( 'rznvy' ) ) {
- $c->detach( 'subscribe_email' );
+ if ( $c->req->param('rss') ) {
+ $c->detach('rss');
+ }
+ elsif ( $c->req->param('rznvy') ) {
+ $c->detach('subscribe_email');
}
}
@@ -230,81 +230,109 @@ sub subscribe_email : Private {
$c->stash->{email_type} = 'alert';
my @errors;
- push @errors, _('Please enter a valid email address') unless is_valid_email($c->req->param('rznvy'));
- push @errors, _('Please select the type of alert you want') if $type && $type eq 'local' && !$c->req->param('feed');
+ push @errors, _('Please enter a valid email address')
+ unless is_valid_email( $c->req->param('rznvy') );
+ push @errors, _('Please select the type of alert you want')
+ if $type && $type eq 'local' && !$c->req->param('feed');
if (@errors) {
$c->stash->{errors} = \@errors;
$c->go('list');
-# return alert_updates_form($q, @errors) if $type && $type eq 'updates';
-# return alert_list($q, @errors) if $type && $type eq 'local';
-# return alert_front_page($q, @errors);
+
+ # return alert_updates_form($q, @errors) if $type && $type eq 'updates';
+ # return alert_list($q, @errors) if $type && $type eq 'local';
+ # return alert_front_page($q, @errors);
}
- my $alert_id;
+ my $alert;
my $email = $c->req->param('rznvy');
-# my $cobrand = Page::get_cobrand($q);
-# my $cobrand_data = Cobrand::extra_alert_data($cobrand, $q);
- if ($type eq 'updates') {
+
+ # my $cobrand = Page::get_cobrand($q);
+ # my $cobrand_data = Cobrand::extra_alert_data($cobrand, $q);
+ if ( $type eq 'updates' ) {
+
# my $id = $q->param('id');
# $alert_id = FixMyStreet::Alert::create($email, 'new_updates', $cobrand, $cobrand_data, $id);
- } elsif ($type eq 'problems') {
+ }
+ elsif ( $type eq 'problems' ) {
+
# $alert_id = FixMyStreet::Alert::create($email, 'new_problems', $cobrand, $cobrand_data);
- } elsif ($type eq 'local') {
+ }
+ elsif ( $type eq 'local' ) {
my $feed = $c->req->param('feed');
my ( $type, @params );
- if ($feed =~ /^area:(?:\d+:)?(\d+)/) {
+ if ( $feed =~ /^area:(?:\d+:)?(\d+)/ ) {
$type = 'area_problems';
push @params, $1;
- } elsif ($feed =~ /^council:(\d+)/) {
+ }
+ elsif ( $feed =~ /^council:(\d+)/ ) {
$type = 'council_problems';
push @params, $1, $1;
- } elsif ($feed =~ /^ward:(\d+):(\d+)/) {
+ }
+ elsif ( $feed =~ /^ward:(\d+):(\d+)/ ) {
$type = 'ward_problems';
push @params, $1, $2;
- } elsif ($feed =~ m{ \A local: ( [\+\-]? \d+ \.? \d* ) : ( [\+\-]? \d+ \.? \d* ) }xms ) {
+ }
+ elsif ( $feed =~
+ m{ \A local: ( [\+\-]? \d+ \.? \d* ) : ( [\+\-]? \d+ \.? \d* ) }xms
+ )
+ {
$type = 'local_problems';
push @params, $1, $2;
+
# my $lat = $1;
# my $lon = $2;
# $alert_id = FixMyStreet::Alert::create($email, 'local_problems', $cobrand, $cobrand_data, $lon, $lat);
}
my $options = {
- email => $email,
- alert_type => $type
+ email => $email,
+ alert_type => $type
};
if ( scalar @params == 1 ) {
$options->{parameter} = $params[0];
- } elsif ( scalar @params == 2 ) {
- $options->{parameter} = $params[0];
+ }
+ elsif ( scalar @params == 2 ) {
+ $options->{parameter} = $params[0];
$options->{parameter2} = $params[1];
}
- my $alert = $c->model('DB::Alert')->find(
- $options
- );
+ $alert = $c->model('DB::Alert')->find( $options );
- unless ( $alert ) {
- $options->{cobrand} = $c->cobrand->moniker();
+ unless ($alert) {
+ $options->{cobrand} = $c->cobrand->moniker();
$options->{cobrand_data} = $c->cobrand->extra_update_data();
- $alert = $c->model('DB::Alert')->new( $options );
+ $alert = $c->model('DB::Alert')->new($options);
$alert->insert();
}
$c->log->debug( 'created alert ' . $alert->id );
$c->stash->{template} = 'email_sent.html';
- } else {
+ }
+ else {
throw FixMyStreet::Alert::Error('Invalid type');
}
-#
-# my %h = ();
-# $h{url} = Page::base_url_with_lang($q, undef, 1) . '/A/'
-# . mySociety::AuthToken::store('alert', { id => $alert_id, type => 'subscribe', email => $email } );
-# dbh()->commit();
-# return Page::send_confirmation_email($q, $email, undef, 'alert', %h);
+
+ my $token = $c->model("DB::Token")->create(
+ {
+ scope => 'alert',
+ data => { id => $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
+ }
+ );
}
=head2 prettify_pc