diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Auth.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Moderate.pm | 28 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Alerts.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Questionnaires.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Reports.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 11 |
7 files changed, 56 insertions, 27 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm index a6a6378da..0b156ddd3 100644 --- a/perllib/FixMyStreet/App/Controller/Auth.pm +++ b/perllib/FixMyStreet/App/Controller/Auth.pm @@ -216,7 +216,8 @@ sub token : Path('/M') : Args(1) { $c->stash->{token_not_found} = 1, return if $data->{old_email} && (!$c->user_exists || $c->user->email ne $data->{old_email}); - $c->detach( '/auth/process_login', [ $data, 'email' ] ); + my $type = $data->{login_type} || 'email'; + $c->detach( '/auth/process_login', [ $data, $type ] ); } sub process_login : Private { diff --git a/perllib/FixMyStreet/App/Controller/Moderate.pm b/perllib/FixMyStreet/App/Controller/Moderate.pm index e2ab16b6b..1313b5071 100644 --- a/perllib/FixMyStreet/App/Controller/Moderate.pm +++ b/perllib/FixMyStreet/App/Controller/Moderate.pm @@ -106,19 +106,21 @@ sub report_moderate_audit : Private { reason => (sprintf '%s (%s)', $reason, $types_csv), }); - my $token = $c->model("DB::Token")->create({ - scope => 'moderation', - data => { id => $problem->id } - }); - - $c->send_email( 'problem-moderated.txt', { - to => [ [ $problem->user->email, $problem->name ] ], - types => $types_csv, - user => $problem->user, - problem => $problem, - report_uri => $c->stash->{report_uri}, - report_complain_uri => $c->stash->{cobrand_base} . '/contact?m=' . $token->token, - }); + if ($problem->user->email_verified) { + my $token = $c->model("DB::Token")->create({ + scope => 'moderation', + data => { id => $problem->id } + }); + + $c->send_email( 'problem-moderated.txt', { + to => [ [ $problem->user->email, $problem->name ] ], + types => $types_csv, + user => $problem->user, + problem => $problem, + report_uri => $c->stash->{report_uri}, + report_complain_uri => $c->stash->{cobrand_base} . '/contact?m=' . $token->token, + }); + } } sub report_moderate_hide : Private { diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index b954a68ab..56601480d 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -485,12 +485,21 @@ Return a url for this problem report that logs a user in sub tokenised_url { my ($self, $user, $params) = @_; + my %params; + if ($user->email_verified) { + $params{email} = $user->email; + } elsif ($user->phone_verified) { + $params{phone} = $user->phone; + # This is so the email token can look up/ log in a phone user + $params{login_type} = 'phone'; + } + my $token = FixMyStreet::App->model('DB::Token')->create( { scope => 'email_sign_in', data => { + %params, id => $self->id, - email => $user->email, r => $self->url, p => $params, } diff --git a/perllib/FixMyStreet/Script/Alerts.pm b/perllib/FixMyStreet/Script/Alerts.pm index c001cc311..86f11c7b5 100644 --- a/perllib/FixMyStreet/Script/Alerts.pm +++ b/perllib/FixMyStreet/Script/Alerts.pm @@ -109,7 +109,7 @@ sub send() { my $user = $schema->resultset('User')->find( { id => $row->{alert_user_id} } ); - $data{alert_email} = $user->email; + $data{alert_user} = $user; my $token_obj = $schema->resultset('Token')->create( { scope => 'alert_to_reporter', data => { @@ -209,7 +209,7 @@ sub send() { template => $template, data => [], alert_id => $alert->id, - alert_email => $alert->user->email, + alert_user => $alert->user, lang => $alert->lang, cobrand => $cobrand, cobrand_data => $alert->cobrand_data, @@ -258,16 +258,20 @@ sub _send_aggregated_alert_email(%) { $cobrand->set_lang_and_domain( $data{lang}, 1, FixMyStreet->path_to('locale')->stringify ); FixMyStreet::Map::set_map_class($cobrand->map_type); - if (!$data{alert_email}) { + if (!$data{alert_user}) { my $user = $data{schema}->resultset('User')->find( { id => $data{alert_user_id} } ); - $data{alert_email} = $user->email; + $data{alert_user} = $user; } - my ($domain) = $data{alert_email} =~ m{ @ (.*) \z }x; + # Ignore phone-only users + return unless $data{alert_user}->email_verified; + + my $email = $data{alert_user}->email; + my ($domain) = $email =~ m{ @ (.*) \z }x; return if $data{schema}->resultset('Abuse')->search( { - email => [ $data{alert_email}, $domain ] + email => [ $email, $domain ] } )->first; my $token = $data{schema}->resultset("Token")->new_result( { @@ -275,7 +279,7 @@ sub _send_aggregated_alert_email(%) { data => { id => $data{alert_id}, type => 'unsubscribe', - email => $data{alert_email}, + email => $email, } } ); $data{unsubscribe_url} = $cobrand->base_url( $data{cobrand_data} ) . '/A/' . $token->token; @@ -286,7 +290,7 @@ sub _send_aggregated_alert_email(%) { "$data{template}.txt", \%data, { - To => $data{alert_email}, + To => $email, }, $sender, 0, diff --git a/perllib/FixMyStreet/Script/Questionnaires.pm b/perllib/FixMyStreet/Script/Questionnaires.pm index ec6139d2d..5fc01512d 100644 --- a/perllib/FixMyStreet/Script/Questionnaires.pm +++ b/perllib/FixMyStreet/Script/Questionnaires.pm @@ -49,7 +49,11 @@ sub send_questionnaires_period { # Not all cobrands send questionnaires next unless $cobrand->send_questionnaires; - next if $row->is_from_abuser; + + if ($row->is_from_abuser || !$row->user->email_verified) { + $row->update( { send_questionnaire => 0 } ); + next; + } # Cobranded and non-cobranded messages can share a database. In this case, the conf file # should specify a vhost to send the reports for each cobrand, so that they don't get sent diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm index 1e5fd55bb..1ea98342c 100644 --- a/perllib/FixMyStreet/Script/Reports.pm +++ b/perllib/FixMyStreet/Script/Reports.pm @@ -84,7 +84,6 @@ sub send(;$) { $h{query} = $row->postcode; $h{url} = $email_base_url . $row->url; $h{admin_url} = $row->admin_url($cobrand); - $h{phone_line} = $h{phone} ? _('Phone:') . " $h{phone}\n\n" : ''; if ($row->photo) { $h{has_photo} = _("This web page also contains a photo of the problem, provided by the user.") . "\n\n"; $h{image_url} = $email_base_url . $row->photos->[0]->{url_full}; @@ -299,6 +298,9 @@ sub _send_report_sent_email { my $nomail = shift; my $cobrand = shift; + # Don't send 'report sent' text + return unless $row->user->email_verified; + FixMyStreet::Email::send_cron( $row->result_source->schema, 'confirm_report_sent.txt', diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index eefb14553..0aacc14a1 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -74,14 +74,21 @@ sub send { my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new(); my $params = { To => $self->to, - From => $self->send_from( $row ), }; $cobrand->call_hook(munge_sendreport_params => $row, $h, $params); $params->{Bcc} = $self->bcc if @{$self->bcc}; - my $sender = FixMyStreet::Email::unique_verp_id('report', $row->id); + my $sender; + if ($row->user->email && $row->user->email_verified) { + $sender = FixMyStreet::Email::unique_verp_id('report', $row->id); + $params->{From} = $self->send_from( $row ); + } else { + $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL'); + my $name = sprintf(_("On behalf of %s"), $params->{From}[1]); + $params->{From} = [ $sender, $name ]; + } if (FixMyStreet::Email::test_dmarc($params->{From}[0]) || Utils::Email::same_domain($params->{From}, $params->{To})) { |