aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App.pm')
-rw-r--r--perllib/FixMyStreet/App.pm70
1 files changed, 60 insertions, 10 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index fda9d665c..1664f0f30 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -2,7 +2,11 @@ package FixMyStreet::App;
use Moose;
use namespace::autoclean;
+# Should move away from Email::Send, but until then:
+$Return::Value::NO_CLUCK = 1;
+
use Catalyst::Runtime 5.80;
+use DateTime;
use FixMyStreet;
use FixMyStreet::Cobrand;
use Memcached;
@@ -23,6 +27,7 @@ use Catalyst (
'Session::State::Cookie', # FIXME - we're using our own override atm
'Authentication',
'SmartURI',
+ 'Compress::Gzip',
);
extends 'Catalyst';
@@ -45,7 +50,7 @@ __PACKAGE__->config(
default_view => 'Web',
# Serve anything in web dir that is not a .cgi script
- static => { #
+ 'Plugin::Static::Simple' => {
include_path => [ FixMyStreet->path_to("web") . "" ],
ignore_extensions => ['cgi'],
},
@@ -85,6 +90,13 @@ __PACKAGE__->config(
# Start the application
__PACKAGE__->setup();
+# Due to some current issues with proxyings, need to manually
+# tell the code we're secure if we are.
+after 'prepare_headers' => sub {
+ my $self = shift;
+ $self->req->secure( 1 ) if $self->config->{BASE_URL} eq 'https://www.zueriwieneu.ch';
+};
+
# set up DB handle for old code
FixMyStreet->configure_mysociety_dbhandle;
@@ -188,6 +200,22 @@ sub setup_request {
mySociety::MaPit::configure( "http://$host/fakemapit/" );
}
+ # XXX Put in cobrand / do properly
+ if ($c->cobrand->moniker eq 'zurich') {
+ FixMyStreet::DB::Result::Problem->visible_states_add_unconfirmed();
+ DateTime->DefaultLocale( 'de_CH' );
+ } else {
+ DateTime->DefaultLocale( 'en_US' );
+ }
+
+ if (FixMyStreet->test_mode) {
+ # Is there a better way of altering $c->config that may have
+ # override_config involved?
+ $c->setup_finished(0);
+ $c->config( %{ FixMyStreet->config() } );
+ $c->setup_finished(1);
+ }
+
return $c;
}
@@ -274,9 +302,8 @@ sub send_email {
my $template = shift;
my $extra_stash_values = shift || {};
- my $sender = $c->cobrand->contact_email;
+ my $sender = $c->config->{DO_NOT_REPLY_EMAIL};
my $sender_name = $c->cobrand->contact_name;
- $sender =~ s/team/fms-DO-NOT-REPLY/;
# create the vars to pass to the email template
my $vars = {
@@ -297,6 +324,8 @@ sub send_email {
$email->header_set( ucfirst($_), $vars->{$_} )
for grep { $vars->{$_} } qw( to from subject);
+ return if $c->is_abuser( $email->header('To') );
+
$email->header_set( 'Message-ID', sprintf('<fms-%s-%s@%s>',
time(), unpack('h*', random_bytes(5, 1)), $c->config->{EMAIL_DOMAIN}
) );
@@ -307,6 +336,7 @@ sub send_email {
{
_template_ => $email->body, # will get line wrapped
_parameters_ => {},
+ _line_indent => '',
$email->header_pairs
}
) };
@@ -320,8 +350,10 @@ sub send_email {
sub send_email_cron {
my ( $c, $params, $env_from, $env_to, $nomail ) = @_;
- $params->{'Message-ID'} = sprintf('<fms-cron-%s-%s@mysociety.org>', time(),
- unpack('h*', random_bytes(5, 1))
+ return 1 if $c->is_abuser( $env_to );
+
+ $params->{'Message-ID'} = sprintf('<fms-cron-%s-%s@%s>', time(),
+ unpack('h*', random_bytes(5, 1)), FixMyStreet->config('EMAIL_DOMAIN')
);
$params->{_parameters_}->{signature} = '';
@@ -334,6 +366,7 @@ sub send_email_cron {
# }
#);
+ $params->{_line_indent} = '';
my $email = mySociety::Locale::in_gb_locale { mySociety::Email::construct_email($params) };
if ( FixMyStreet->test_mode ) {
@@ -435,22 +468,39 @@ Hashref contains height, width and url keys.
sub get_photo_params {
my ($self, $key) = @_;
- $key = ($key eq 'id') ? '' : "/$key";
return {} unless $self->photo;
+ $key = ($key eq 'id') ? '' : "/$key";
+
+ my $pre = "/photo$key/" . $self->id;
+ my $post = '.jpeg';
my $photo = {};
+
if (length($self->photo) == 40) {
- $photo->{url_full} = '/photo' . $key . '/' . $self->id . '.full.jpeg';
+ $post .= '?' . $self->photo;
+ $photo->{url_full} = "$pre.full$post";
+ # XXX Can't use size here because {url} (currently 250px height) may be
+ # being used, but at this point it doesn't yet exist to find the width
+ # $str = FixMyStreet->config('UPLOAD_DIR') . $self->photo . '.jpeg';
} else {
- ( $photo->{width}, $photo->{height} ) =
- Image::Size::imgsize( \$self->photo );
+ my $str = \$self->photo;
+ ( $photo->{width}, $photo->{height} ) = Image::Size::imgsize( $str );
}
- $photo->{url} = '/photo' . $key . '/' . $self->id . '.jpeg';
+
+ $photo->{url} = "$pre$post";
+ $photo->{url_tn} = "$pre.tn$post";
+ $photo->{url_fp} = "$pre.fp$post";
return $photo;
}
+sub is_abuser {
+ my ($c, $email) = @_;
+ my ($domain) = $email =~ m{ @ (.*) \z }x;
+ return $c->model('DB::Abuse')->search( { email => [ $email, $domain ] } )->first;
+}
+
=head1 SEE ALSO
L<FixMyStreet::App::Controller::Root>, L<Catalyst>