diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports/New.pm | 95 | ||||
-rw-r--r-- | templates/email/default/problem-confirm.txt | 20 | ||||
-rw-r--r-- | templates/web/default/email_sent.html | 34 |
3 files changed, 104 insertions, 45 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports/New.pm b/perllib/FixMyStreet/App/Controller/Reports/New.pm index 78a36cb5d..12f904e5e 100644 --- a/perllib/FixMyStreet/App/Controller/Reports/New.pm +++ b/perllib/FixMyStreet/App/Controller/Reports/New.pm @@ -92,7 +92,8 @@ sub report_new : Path : Args(0) { && $c->forward('process_report') && $c->forward('check_form_submitted') && $c->forward('check_for_errors') - && $c->forward('save_user_and_report'); + && $c->forward('save_user_and_report') + && $c->forward('redirect_or_confirm_creation'); } =head2 determine_location @@ -496,9 +497,6 @@ sub process_report : Private { $report->name( $params{name} ); $report->category( $params{category} ); - # set defaults that make sense - $report->state('unconfirmed'); - # my $fh = $q->upload('photo'); # if ($fh) { # my $err = Page::check_photo( $q, $fh ); @@ -563,9 +561,10 @@ sub process_report : Private { join( ',', @councils_with_category ), join( ',', @councils_without_category ) ); - $council_string ||= '-1'; # no councils found with categories $report->council($council_string); - warn "council_string: $council_string"; + + # set defaults that make sense + $report->state('unconfirmed'); # my $image; # if ($fh) { @@ -590,16 +589,16 @@ sub process_report : Private { # close FP; # } # -# return display_form( $q, \@errors, \%field_errors ) -# if ( @errors || scalar keys %field_errors ); -# -# delete $input{council} if $input{council} eq '-1'; -# my $used_map = $input{skipped} ? 'f' : 't'; -# $input{category} = _('Other') unless $input{category}; -# my ( $id, $out ); -# my $cobrand_data = Cobrand::extra_problem_data( $cobrand, $q ); -# if ( my $token = $input{partial} ) { -# my $id = mySociety::AuthToken::retrieve( 'partial', $token ); + + # save the cobrand and language related information + $report->cobrand( $c->cobrand->moniker ); + $report->cobrand_data( $c->cobrand->extra_problem_data ); + $report->lang( $c->stash->{lang_code} ); + + # if ( my $token = $input{partial} ) { + + # my $id = mySociety::AuthToken::retrieve( 'partial', $token ); + # if ($id) { # dbh()->do( # "update problem set postcode=?, latitude=?, longitude=?, title=?, detail=?, @@ -612,6 +611,7 @@ sub process_report : Private { # $input{anonymous} ? 'f' : 't', # $input{category}, $areas, $cobrand, $cobrand_data, $id # ); + # Utils::workaround_pg_bytea( # 'update problem set photo=? where id=?', # 1, $image, $id ) @@ -640,35 +640,6 @@ sub process_report : Private { # } # } # else { -# $id = dbh()->selectrow_array("select nextval('problem_id_seq');"); -# Utils::workaround_pg_bytea( -# "insert into problem -# (id, postcode, latitude, longitude, title, detail, name, -# email, phone, photo, state, council, used_map, anonymous, category, areas, lang, cobrand, cobrand_data) -# values -# (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'unconfirmed', ?, ?, ?, ?, ?, ?, ?, ?)", -# 10, -# $id, $input{pc}, $input{latitude}, $input{longitude}, -# $input{title}, -# $input{detail}, $input{name}, $input{email}, $input{phone}, -# $image, -# $input{council}, $used_map, $input{anonymous} ? 'f' : 't', -# $input{category}, -# $areas, $mySociety::Locale::lang, $cobrand, $cobrand_data -# ); -# my %h = (); -# $h{title} = $input{title}; -# $h{detail} = $input{detail}; -# $h{name} = $input{name}; -# my $base = Page::base_url_with_lang( $q, undef, 1 ); -# $h{url} = -# $base . '/P/' . mySociety::AuthToken::store( 'problem', $id ); -# dbh()->commit(); -# -# $out = -# Page::send_email( $q, $input{email}, $input{name}, 'problem', -# %h ); -# # } # return $out; # } @@ -756,9 +727,13 @@ sub save_user_and_report : Private { # add the user to the report $report->user($report_user); + # Set a default if possible + $report->category( _('Other') ) unless $report->category; + # save the report; $report->insert(); + return 1; } =head2 generate_map @@ -815,6 +790,36 @@ END_MAP_HTML return 1; } +=head2 redirect_or_confirm_creation + +Now that the report has been created either redirect the user to its page if it +has been confirmed or email them a token if it has not been. + +=cut + +sub redirect_or_confirm_creation : Private { + my ( $self, $c ) = @_; + my $report = $c->stash->{report}; + + # If confirmed send the user straigh there. + if ( $report->confirmed ) { + my $report_uri = $c->uri_for( '/reports', $report->id ); + $c->res->redirect($report_uri); + $c->detach; + } + + # otherwise create a confirm token and email it to them. + my $token = + $c->model("DB::Token") + ->create( { scope => 'problem', data => $report->id } ); + $c->stash->{token_url} = $c->uri_for( '/P', $token->token ); + $c->send_email( 'problem-confirm.txt', { to => $report->user->email } ); + + # tell user that they've been sent an email + $c->stash->{template} = 'email_sent.html'; + $c->stash->{email_type} = 'problem'; +} + __PACKAGE__->meta->make_immutable; 1; diff --git a/templates/email/default/problem-confirm.txt b/templates/email/default/problem-confirm.txt new file mode 100644 index 000000000..e16c90037 --- /dev/null +++ b/templates/email/default/problem-confirm.txt @@ -0,0 +1,20 @@ +Subject: Confirm your problem on FixMyStreet + +Hi [% report.user.name %], + +Please click on the link below to confirm the problem you just +added to FixMyStreet: + +[% token_url %] + +If your email program does not let you click on this link, +copy and paste it into your web browser and press return. + +Your problem had the title: +[% report.title %] + +And details: +[% report.detail %] + +Yours, +The FixMyStreet team diff --git a/templates/web/default/email_sent.html b/templates/web/default/email_sent.html new file mode 100644 index 000000000..bcfcf8617 --- /dev/null +++ b/templates/web/default/email_sent.html @@ -0,0 +1,34 @@ +[% INCLUDE 'header.html', title => loc('Create a report') %] + +[% + messages = { + problem => { + action => loc('your problem will not be posted'), + worry => loc("we'll hang on to your problem report while you're checking your email."), + }, + update => { + action => loc('your update will not be posted'), + worry => loc("we'll hang on to your update while you're checking your email."), + }, + alert => { + action => loc('your alert will not be activated'), + worry => loc("we'll hang on to your alert while you're checking your email."), + }, + tms => { + action => 'your expression of interest will not be registered', + worry => "we'll hang on to your expression of interest while you're checking your email.", + } + } +%] +<h1>Nearly Done! Now check your email...</h1> + +<p>The confirmation email <strong>may</strong> take a few minutes to arrive — <em>please</em> be patient.</p> + +<p>If you use web-based email or have 'junk mail' filters, you may wish to check your bulk/spam mail folders: sometimes, our messages are marked that way.</p> + +<p>You must now click the link in the email we've just sent you — if you do not, [% messages.$email_type.action %].</p> + +<p>(Don't worry — [% messages.$email_type.worry %])</p> + + +[% INCLUDE 'footer.html' %]
\ No newline at end of file |