aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm214
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm181
-rw-r--r--perllib/FixMyStreet/App/Controller/Tokens.pm96
3 files changed, 292 insertions, 199 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index c2fd2a377..fa3967bf3 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -13,6 +13,7 @@ use Path::Class;
use Utils;
use mySociety::EmailUtil;
use JSON::MaybeXS;
+use FixMyStreet::SMS;
=head1 NAME
@@ -116,19 +117,25 @@ sub report_new : Path : Args(0) {
$c->forward('redirect_or_confirm_creation');
}
-# This is for the new phonegap versions of the app. It looks a lot like
-# report_new but there's a few workflow differences as we only ever want
-# to sent JSON back here
-
sub report_new_test : Path('_test_') : Args(0) {
my ( $self, $c ) = @_;
$c->stash->{template} = 'email_sent.html';
$c->stash->{email_type} = $c->get_param('email_type');
}
+# This is for the new phonegap versions of the app. It looks a lot like
+# report_new but there's a few workflow differences as we only ever want
+# to sent JSON back here
+
sub report_new_ajax : Path('mobile') : Args(0) {
my ( $self, $c ) = @_;
+ # Apps are sending email as username
+ # Prepare for when they upgrade
+ if (!$c->get_param('username')) {
+ $c->set_param('username', $c->get_param('email'));
+ }
+
# create the report - loading a partial if available
$c->forward('initialize_report');
@@ -737,14 +744,12 @@ sub process_user : Private {
# Extract all the params to a hash to make them easier to work with
my %params = map { $_ => $c->get_param($_) }
- ( 'email', 'name', 'phone', 'password_register', 'fms_extra_title' );
-
- my $user_title = Utils::trim_text( $params{fms_extra_title} );
+ ( 'username', 'email', 'name', 'phone', 'password_register', 'fms_extra_title' );
if ( $c->cobrand->allow_anonymous_reports ) {
my $anon_details = $c->cobrand->anonymous_account;
- for my $key ( qw( email name ) ) {
+ for my $key ( qw( username email name ) ) {
$params{ $key } ||= $anon_details->{ $key };
}
}
@@ -759,34 +764,29 @@ sub process_user : Private {
last;
}
- $user->name( Utils::trim_text( $params{name} ) ) if $params{name};
- $user->phone( Utils::trim_text( $params{phone} ) );
- $user->title( $user_title ) if $user_title;
$report->user( $user );
+ $c->forward('update_user', [ \%params ]);
if ($c->stash->{contributing_as_body} = $user->contributing_as('body', $c, $c->stash->{bodies}) or
$c->stash->{contributing_as_anonymous_user} = $user->contributing_as('anonymous_user', $c, $c->stash->{bodies})) {
$report->name($user->from_body->name);
$user->name($user->from_body->name) unless $user->name;
$c->stash->{no_reporter_alert} = 1;
- } else {
- $report->name($user->name);
}
return 1;
} }
- # cleanup the email address
- my $email = $params{email} ? lc $params{email} : '';
- $email =~ s{\s+}{}g;
-
- $report->user( $c->model('DB::User')->find_or_new( { email => $email } ) )
+ my $parsed = FixMyStreet::SMS->parse_username($params{username});
+ my $type = $parsed->{type} || 'email';
+ $type = 'email' unless FixMyStreet->config('SMS_AUTHENTICATION');
+ $report->user( $c->model('DB::User')->find_or_new( { $type => $parsed->{username} } ) )
unless $report->user;
- # The user is trying to sign in. We only care about email from the params.
+ # The user is trying to sign in. We only care about username from the params.
if ( $c->get_param('submit_sign_in') || $c->get_param('password_sign_in') ) {
- unless ( $c->forward( '/auth/sign_in', [ $email ] ) ) {
- $c->stash->{field_errors}->{password} = _('There was a problem with your email/password combination. If you cannot remember your password, or do not have one, please fill in the ‘sign in by email’ section of the form.');
+ unless ( $c->forward( '/auth/sign_in', [ $params{username} ] ) ) {
+ $c->stash->{field_errors}->{password} = _('There was a problem with your login information. If you cannot remember your password, or do not have one, please fill in the ‘No’ section of the form.');
return 1;
}
my $user = $c->user->obj;
@@ -798,17 +798,28 @@ sub process_user : Private {
return 1;
}
- # set the user's name, phone, and password
- $report->user->name( Utils::trim_text( $params{name} ) ) if $params{name};
- $report->user->phone( Utils::trim_text( $params{phone} ) );
+ $c->forward('update_user', [ \%params ]);
$report->user->password( Utils::trim_text( $params{password_register} ) )
if $params{password_register};
- $report->user->title( $user_title ) if $user_title;
- $report->name( Utils::trim_text( $params{name} ) );
return 1;
}
+sub update_user : Private {
+ my ($self, $c, $params) = @_;
+ my $report = $c->stash->{report};
+ my $user = $report->user;
+ $user->name( Utils::trim_text( $params->{name} ) );
+ $report->name($user->name);
+ if (!$user->phone_verified) {
+ $user->phone( Utils::trim_text( $params->{phone} ) );
+ } elsif (!$user->email_verified) {
+ $user->email( Utils::trim_text( $params->{email} ) );
+ }
+ my $user_title = Utils::trim_text( $params->{fms_extra_title} );
+ $user->title( $user_title ) if $user_title;
+}
+
=head2 process_report
Looking at the parameters passed in create a new item and return it. Does not
@@ -1031,11 +1042,11 @@ sub check_for_errors : Private {
delete $field_errors{name};
}
- # if using social login then we don't care about name and email errors
+ # if using social login then we don't care about other errors
$c->stash->{is_social_user} = $c->get_param('facebook_sign_in') || $c->get_param('twitter_sign_in');
if ( $c->stash->{is_social_user} ) {
delete $field_errors{name};
- delete $field_errors{email};
+ delete $field_errors{username};
}
# add the photo error if there is one.
@@ -1056,7 +1067,8 @@ sub tokenize_user : Private {
my ($self, $c, $report) = @_;
$c->stash->{token_data} = {
name => $report->user->name,
- phone => $report->user->phone,
+ (!$report->user->phone_verified ? (phone => $report->user->phone) : ()),
+ (!$report->user->email_verified ? (email => $report->user->email) : ()),
password => $report->user->password,
title => $report->user->title,
};
@@ -1089,6 +1101,114 @@ sub send_problem_confirm_email : Private {
} );
}
+sub send_problem_confirm_text : Private {
+ my ( $self, $c ) = @_;
+ my $data = $c->stash->{token_data} || {};
+ my $report = $c->stash->{report};
+
+ $data->{id} = $report->id;
+ $c->forward('/auth/phone/send_token', [ $data, 'problem', $report->user->phone ]);
+ $c->stash->{submit_url} = '/report/new/text';
+}
+
+sub confirm_by_text : Path('text') {
+ my ( $self, $c ) = @_;
+
+ my $token = $c->stash->{token} = $c->get_param('token');
+ my $code = $c->get_param('code') || '';
+
+ my $data = $c->stash->{token_data} = $c->forward('/auth/get_token', [ $token, 'problem' ]) || return;
+ if ($data->{code} ne $code) {
+ $c->stash->{template} = 'auth/smsform.html';
+ $c->stash->{submit_url} = '/report/new/text';
+ $c->stash->{incorrect_code} = 1;
+ return;
+ }
+
+ $c->detach('process_confirmation');
+}
+
+sub process_confirmation : Private {
+ my ( $self, $c ) = @_;
+
+ $c->stash->{template} = 'tokens/confirm_problem.html';
+ my $data = $c->stash->{token_data};
+
+ unless ($c->stash->{report}) {
+ # Look at all problems, not just cobrand, in case am approving something we don't actually show
+ $c->stash->{report} = $c->model('DB::Problem')->find({ id => $data->{id} }) || return;
+ }
+ my $problem = $c->stash->{report};
+
+ # check that this email or domain are not the cause of abuse. If so hide it.
+ if ( $problem->is_from_abuser ) {
+ $problem->update(
+ { state => 'hidden', lastupdate => \'current_timestamp' } );
+ $c->stash->{template} = 'tokens/abuse.html';
+ return;
+ }
+
+ # For Zurich, email confirmation simply sets a flag, it does not change the
+ # problem state, log in, or anything else
+ if ($c->cobrand->moniker eq 'zurich') {
+ $problem->set_extra_metadata( email_confirmed => 1 );
+ $problem->update( {
+ confirmed => \'current_timestamp',
+ } );
+
+ if ( $data->{name} || $data->{password} ) {
+ $problem->user->name( $data->{name} ) if $data->{name};
+ $problem->user->phone( $data->{phone} ) if $data->{phone};
+ $problem->user->update;
+ }
+
+ return 1;
+ }
+
+ if ($problem->state ne 'unconfirmed') {
+ my $report_uri = $c->cobrand->base_url_for_report( $problem ) . $problem->url;
+ $c->res->redirect($report_uri);
+ return;
+ }
+
+ # We have an unconfirmed problem
+ $problem->update(
+ {
+ state => 'confirmed',
+ confirmed => \'current_timestamp',
+ lastupdate => \'current_timestamp',
+ }
+ );
+
+ # Subscribe problem reporter to email updates
+ $c->forward( '/report/new/create_reporter_alert' );
+
+ # log the problem creation user in to the site
+ if ( $data->{name} || $data->{password} ) {
+ if (!$problem->user->email_verified) {
+ $problem->user->email( $data->{email} ) if $data->{email};
+ } elsif (!$problem->user->phone_verified) {
+ $problem->user->phone( $data->{phone} ) if $data->{phone};
+ }
+ $problem->user->password( $data->{password}, 1 ) if $data->{password};
+ for (qw(name title facebook_id twitter_id)) {
+ $problem->user->$_( $data->{$_} ) if $data->{$_};
+ }
+ $problem->user->update;
+ }
+ if ($problem->user->email_verified) {
+ $c->authenticate( { email => $problem->user->email, email_verified => 1 }, 'no_password' );
+ } elsif ($problem->user->phone_verified) {
+ $c->authenticate( { phone => $problem->user->phone, phone_verified => 1 }, 'no_password' );
+ } else {
+ warn "Reached user authentication with no username verification";
+ }
+ $c->set_session_cookie_expire(0);
+
+ $c->stash->{created_report} = 'fromemail';
+ return 1;
+}
+
=head2 save_user_and_report
Save the user and the report.
@@ -1143,11 +1263,7 @@ sub save_user_and_report : Private {
# Save or update the user if appropriate
if ( $c->cobrand->never_confirm_reports ) {
- if ( $report->user->in_storage() ) {
- $report->user->update();
- } else {
- $report->user->insert();
- }
+ $report->user->update_or_insert;
$report->confirm();
} elsif ( $c->forward('created_as_someone_else', [ $c->stash->{bodies} ]) ) {
# If created on behalf of someone else, we automatically confirm it,
@@ -1157,7 +1273,11 @@ sub save_user_and_report : Private {
# User does not exist.
$c->forward('tokenize_user', [ $report ]);
$report->user->name( undef );
- $report->user->phone( undef );
+ if (!$report->user->email_verified) {
+ $report->user->email( undef );
+ } elsif (!$report->user->phone_verified) {
+ $report->user->phone( undef );
+ }
$report->user->password( '', 1 );
$report->user->title( undef );
$report->user->insert();
@@ -1177,8 +1297,7 @@ sub save_user_and_report : Private {
$c->log->info($report->user->id . ' exists, but is not logged in for this report');
}
- # save the report;
- $report->in_storage ? $report->update : $report->insert();
+ $report->update_or_insert;
# tidy up
if ( my $token = $c->stash->{partial_token} ) {
@@ -1264,13 +1383,20 @@ sub redirect_or_confirm_creation : Private {
return 1;
}
- # otherwise email a confirm token to them.
- $c->forward( 'send_problem_confirm_email' );
-
- # tell user that they've been sent an email
- $c->stash->{template} = 'email_sent.html';
- $c->stash->{email_type} = 'problem';
- $c->log->info($report->user->id . ' created ' . $report->id . ', email sent, ' . ($c->stash->{token_data}->{password} ? 'password set' : 'password not set'));
+ # otherwise email or text a confirm token to them.
+ my $thing = 'email';
+ if ($report->user->email_verified) {
+ $c->forward( 'send_problem_confirm_email' );
+ # tell user that they've been sent an email
+ $c->stash->{template} = 'email_sent.html';
+ $c->stash->{email_type} = 'problem';
+ } elsif ($report->user->phone_verified) {
+ $c->forward( 'send_problem_confirm_text' );
+ $thing = 'text';
+ } else {
+ warn "Reached problem confirmation with no username verification";
+ }
+ $c->log->info($report->user->id . ' created ' . $report->id . ", $thing sent, " . ($c->stash->{token_data}->{password} ? 'password set' : 'password not set'));
}
sub create_reporter_alert : Private {
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 36c45e621..66724f2d1 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -36,18 +36,6 @@ sub report_update : Path : Args(0) {
$c->forward('redirect_or_confirm_creation');
}
-sub confirm : Private {
- my ( $self, $c ) = @_;
-
- $c->stash->{update}->confirm;
- $c->stash->{update}->update;
-
- $c->forward('update_problem');
- $c->forward('signup_for_alerts');
-
- return 1;
-}
-
sub update_problem : Private {
my ( $self, $c ) = @_;
@@ -109,6 +97,10 @@ sub process_user : Private {
my $update = $c->stash->{update};
+ # Extract all the params to a hash to make them easier to work with
+ my %params = map { $_ => $c->get_param($_) }
+ ( 'username', 'name', 'password_register', 'fms_extra_title' );
+
# Extra block to use 'last'
if ( $c->user_exists ) { {
my $user = $c->user->obj;
@@ -118,13 +110,9 @@ sub process_user : Private {
last;
}
- my $name = $c->get_param('name');
- $user->name( Utils::trim_text( $name ) ) if $name;
- my $title = $c->get_param('fms_extra_title');
- if ( $title ) {
- $c->log->debug( 'user exists and title is ' . $title );
- $user->title( Utils::trim_text( $title ) );
- }
+ $user->name( Utils::trim_text( $params{name} ) ) if $params{name};
+ my $title = Utils::trim_text( $params{fms_extra_title} );
+ $user->title( $title ) if $title;
$update->user( $user );
# Just in case, make sure the user will have a name
@@ -135,21 +123,16 @@ sub process_user : Private {
return 1;
} }
- # Extract all the params to a hash to make them easier to work with
- my %params = map { $_ => $c->get_param($_) }
- ( 'rznvy', 'name', 'password_register', 'fms_extra_title' );
-
- # cleanup the email address
- my $email = $params{rznvy} ? lc $params{rznvy} : '';
- $email =~ s{\s+}{}g;
-
- $update->user( $c->model('DB::User')->find_or_new( { email => $email } ) )
+ my $parsed = FixMyStreet::SMS->parse_username($params{username});
+ my $type = $parsed->{type} || 'email';
+ $type = 'email' unless FixMyStreet->config('SMS_AUTHENTICATION');
+ $update->user( $c->model('DB::User')->find_or_new( { $type => $parsed->{username} } ) )
unless $update->user;
- # The user is trying to sign in. We only care about email from the params.
+ # The user is trying to sign in. We only care about username from the params.
if ( $c->get_param('submit_sign_in') || $c->get_param('password_sign_in') ) {
- unless ( $c->forward( '/auth/sign_in', [ $email ] ) ) {
- $c->stash->{field_errors}->{password} = _('There was a problem with your email/password combination. If you cannot remember your password, or do not have one, please fill in the ‘sign in by email’ section of the form.');
+ unless ( $c->forward( '/auth/sign_in', [ $params{username} ] ) ) {
+ $c->stash->{field_errors}->{password} = _('There was a problem with your login information. If you cannot remember your password, or do not have one, please fill in the ‘No’ section of the form.');
return 1;
}
my $user = $c->user->obj;
@@ -328,8 +311,6 @@ sub process_update : Private {
$update->extra( $extra );
}
- $c->log->debug( 'name is ' . $c->get_param('name') );
-
$c->stash->{add_alert} = $c->get_param('add_alert');
return 1;
@@ -372,7 +353,7 @@ sub check_for_errors : Private {
$c->stash->{is_social_user} = $c->get_param('facebook_sign_in') || $c->get_param('twitter_sign_in');
if ( $c->stash->{is_social_user} ) {
delete $field_errors{name};
- delete $field_errors{email};
+ delete $field_errors{username};
}
if ( my $photo_error = delete $c->stash->{photo_error} ) {
@@ -445,11 +426,7 @@ sub save_update : Private {
}
if ( $c->cobrand->never_confirm_updates ) {
- if ( $update->user->in_storage() ) {
- $update->user->update();
- } else {
- $update->user->insert();
- }
+ $update->user->update_or_insert;
$update->confirm();
} elsif ( $c->forward('/report/new/created_as_someone_else', [ $update->problem->bodies_str ]) ) {
# If created on behalf of someone else, we automatically confirm it,
@@ -464,7 +441,6 @@ sub save_update : Private {
}
elsif ( $c->user && $c->user->id == $update->user->id ) {
# Logged in and same user, so can confirm update straight away
- $c->log->debug( 'user exists' );
$update->user->update;
$update->confirm;
} else {
@@ -473,12 +449,7 @@ sub save_update : Private {
$update->user->discard_changes();
}
- if ( $update->in_storage ) {
- $update->update;
- }
- else {
- $update->insert;
- }
+ $update->update_or_insert;
return 1;
}
@@ -507,28 +478,108 @@ sub redirect_or_confirm_creation : Private {
return 1;
}
- # otherwise create a confirm token and email it to them.
- my $data = $c->stash->{token_data} || {};
- my $token = $c->model("DB::Token")->create(
- {
- scope => 'comment',
- data => {
- %$data,
- id => $update->id,
- add_alert => ( $c->get_param('add_alert') ? 1 : 0 ),
- }
- }
- );
+ my $data = $c->stash->{token_data};
+ $data->{id} = $update->id;
+ $data->{add_alert} = $c->get_param('add_alert') ? 1 : 0;
+
+ if ($update->user->email_verified) {
+ $c->forward('send_confirmation_email');
+ # tell user that they've been sent an email
+ $c->stash->{template} = 'email_sent.html';
+ $c->stash->{email_type} = 'update';
+ } elsif ($update->user->phone_verified) {
+ $c->forward('send_confirmation_text');
+ } else {
+ warn "Reached update confirmation with no username verification";
+ }
+
+ return 1;
+}
+
+sub send_confirmation_email : Private {
+ my ( $self, $c ) = @_;
+
+ my $update = $c->stash->{update};
+ my $token = $c->model("DB::Token")->create( {
+ scope => 'comment',
+ data => $c->stash->{token_data},
+ } );
+ my $template = 'update-confirm.txt';
$c->stash->{token_url} = $c->uri_for_email( '/C', $token->token );
- $c->send_email( 'update-confirm.txt', {
- to => $update->name
- ? [ [ $update->user->email, $update->name ] ]
- : $update->user->email,
+ $c->send_email( $template, {
+ to => [ $update->name ? [ $update->user->email, $update->name ] : $update->user->email ],
} );
+}
+
+sub send_confirmation_text : Private {
+ my ( $self, $c ) = @_;
+ my $update = $c->stash->{update};
+ $c->forward('/auth/phone/send_token', [ $c->stash->{token_data}, 'comment', $update->user->phone ]);
+ $c->stash->{submit_url} = '/report/update/text';
+}
+
+sub confirm_by_text : Path('text') {
+ my ( $self, $c ) = @_;
+
+ my $token = $c->stash->{token} = $c->get_param('token');
+ my $code = $c->get_param('code') || '';
+
+ my $data = $c->stash->{token_data} = $c->forward('/auth/get_token', [ $token, 'comment' ]) || return;
+ if ($data->{code} ne $code) {
+ $c->stash->{template} = 'auth/smsform.html';
+ $c->stash->{submit_url} = '/report/update/text';
+ $c->stash->{incorrect_code} = 1;
+ return;
+ }
+
+ $c->detach('process_confirmation');
+}
+
+sub process_confirmation : Private {
+ my ( $self, $c ) = @_;
+
+ $c->stash->{template} = 'tokens/confirm_update.html';
+ my $data = $c->stash->{token_data};
- # tell user that they've been sent an email
- $c->stash->{template} = 'email_sent.html';
- $c->stash->{email_type} = 'update';
+ unless ($c->stash->{update}) {
+ $c->stash->{update} = $c->model('DB::Comment')->find({ id => $data->{id} }) || return;
+ }
+ my $comment = $c->stash->{update};
+
+ # check that this email or domain are not the cause of abuse. If so hide it.
+ if ( $comment->is_from_abuser ) {
+ $c->stash->{template} = 'tokens/abuse.html';
+ return;
+ }
+
+ if ( $comment->state ne 'unconfirmed' ) {
+ my $report_uri = $c->cobrand->base_url_for_report( $comment->problem ) . $comment->problem->url;
+ $c->res->redirect($report_uri);
+ return;
+ }
+
+ if ( $data->{name} || $data->{password} ) {
+ for (qw(name facebook_id twitter_id)) {
+ $comment->user->$_( $data->{$_} ) if $data->{$_};
+ }
+ $comment->user->password( $data->{password}, 1 ) if $data->{password};
+ $comment->user->update;
+ }
+
+ if ($comment->user->email_verified) {
+ $c->authenticate( { email => $comment->user->email, email_verified => 1 }, 'no_password' );
+ } elsif ($comment->user->phone_verified) {
+ $c->authenticate( { phone => $comment->user->phone, phone_verified => 1 }, 'no_password' );
+ } else {
+ warn "Reached user authentication with no username verification";
+ }
+ $c->set_session_cookie_expire(0);
+
+ $c->stash->{update}->confirm;
+ $c->stash->{update}->update;
+ $c->forward('update_problem');
+ $c->stash->{add_alert} = $data->{add_alert};
+ $c->forward('signup_for_alerts');
return 1;
}
diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm
index 1d4438828..bb6140e0a 100644
--- a/perllib/FixMyStreet/App/Controller/Tokens.pm
+++ b/perllib/FixMyStreet/App/Controller/Tokens.pm
@@ -45,10 +45,10 @@ sub confirm_problem : Path('/P') {
# Load the problem
my $data = $auth_token->data;
$data = { id => $data } unless ref $data;
+ $c->stash->{token_data} = $data;
- my $problem_id = $data->{id};
# Look at all problems, not just cobrand, in case am approving something we don't actually show
- my $problem = $c->model('DB::Problem')->find( { id => $problem_id } )
+ my $problem = $c->model('DB::Problem')->find( { id => $data->{id} } )
|| $c->detach('token_error');
$c->stash->{report} = $problem;
@@ -56,64 +56,7 @@ sub confirm_problem : Path('/P') {
if $problem->state eq 'unconfirmed'
&& $auth_token->created < DateTime->now->subtract( months => 1 );
- # check that this email or domain are not the cause of abuse. If so hide it.
- if ( $problem->is_from_abuser ) {
- $problem->update(
- { state => 'hidden', lastupdate => \'current_timestamp' } );
- $c->stash->{template} = 'tokens/abuse.html';
- return;
- }
-
- # For Zurich, email confirmation simply sets a flag, it does not change the
- # problem state, log in, or anything else
- if ($c->cobrand->moniker eq 'zurich') {
- $problem->set_extra_metadata( email_confirmed => 1 );
- $problem->update( {
- confirmed => \'current_timestamp',
- } );
-
- if ( $data->{name} || $data->{password} ) {
- $problem->user->name( $data->{name} ) if $data->{name};
- $problem->user->phone( $data->{phone} ) if $data->{phone};
- $problem->user->update;
- }
-
- return 1;
- }
-
- if ($problem->state ne 'unconfirmed') {
- my $report_uri = $c->cobrand->base_url_for_report( $problem ) . $problem->url;
- $c->res->redirect($report_uri);
- return;
- }
-
- # We have an unconfirmed problem
- $problem->update(
- {
- state => 'confirmed',
- confirmed => \'current_timestamp',
- lastupdate => \'current_timestamp',
- }
- );
-
- # Subscribe problem reporter to email updates
- $c->forward( '/report/new/create_reporter_alert' );
-
- # log the problem creation user in to the site
- if ( $data->{name} || $data->{password} ) {
- $problem->user->name( $data->{name} ) if $data->{name};
- $problem->user->phone( $data->{phone} ) if $data->{phone};
- $problem->user->password( $data->{password}, 1 ) if $data->{password};
- $problem->user->title( $data->{title} ) if $data->{title};
- $problem->user->facebook_id( $data->{facebook_id} ) if $data->{facebook_id};
- $problem->user->twitter_id( $data->{twitter_id} ) if $data->{twitter_id};
- $problem->user->update;
- }
- $c->authenticate( { email => $problem->user->email, email_verified => 1 }, 'no_password' );
- $c->set_session_cookie_expire(0);
-
- $c->stash->{created_report} = 'fromemail';
- return 1;
+ $c->forward('/report/new/process_confirmation');
}
=head2 redirect_to_partial_problem
@@ -205,11 +148,9 @@ sub confirm_update : Path('/C') {
$c->forward( 'load_auth_token', [ $token_code, 'comment' ] );
# Load the update
- my $data = $auth_token->data;
- my $comment_id = $data->{id};
- $c->stash->{add_alert} = $data->{add_alert};
+ my $data = $c->stash->{token_data} = $auth_token->data;
- my $comment = $c->model('DB::Comment')->find( { id => $comment_id } )
+ my $comment = $c->model('DB::Comment')->find( { id => $data->{id} } )
|| $c->detach('token_error');
$c->stash->{update} = $comment;
@@ -217,32 +158,7 @@ sub confirm_update : Path('/C') {
if $comment->state ne 'confirmed'
&& $auth_token->created < DateTime->now->subtract( months => 1 );
- # check that this email or domain are not the cause of abuse. If so hide it.
- if ( $comment->is_from_abuser ) {
- $c->stash->{template} = 'tokens/abuse.html';
- return;
- }
-
- if ( $comment->state ne 'unconfirmed' ) {
- my $report_uri = $c->cobrand->base_url_for_report( $comment->problem ) . $comment->problem->url;
- $c->res->redirect($report_uri);
- return;
- }
-
- if ( $data->{name} || $data->{password} ) {
- $comment->user->name( $data->{name} ) if $data->{name};
- $comment->user->password( $data->{password}, 1 ) if $data->{password};
- $comment->user->facebook_id( $data->{facebook_id} ) if $data->{facebook_id};
- $comment->user->twitter_id( $data->{twitter_id} ) if $data->{twitter_id};
- $comment->user->update;
- }
-
- $c->authenticate( { email => $comment->user->email, email_verified => 1 }, 'no_password' );
- $c->set_session_cookie_expire(0);
-
- $c->forward('/report/update/confirm');
-
- return 1;
+ $c->forward('/report/update/process_confirmation');
}
sub load_questionnaire : Private {