aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Tokens.pm
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-08-17 22:56:37 +0100
committerStruan Donald <struan@exo.org.uk>2011-08-17 22:56:37 +0100
commit3b5d561700b184c20e63111d4cbc1daab78e16c6 (patch)
treef0c53c6bf8d4ebf12e5388053ad856fb0d0e7b86 /perllib/FixMyStreet/App/Controller/Tokens.pm
parent390f8e8ad1e10f832c4323c39bed2c883744a03f (diff)
parentf38b8e985697c35a62374a2f02dce2d681ef58cd (diff)
Merge branch 'master' of ssh://git.mysociety.org/data/git/public/fixmystreet into new_statuses
Conflicts: db/schema.sql perllib/FixMyStreet/App/Controller/Admin.pm perllib/FixMyStreet/DB/Result/User.pm t/app/controller/admin.t templates/web/default/admin/update_edit.html web/css/core.css
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Tokens.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Tokens.pm35
1 files changed, 24 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm
index 9abef591d..26a1a1459 100644
--- a/perllib/FixMyStreet/App/Controller/Tokens.pm
+++ b/perllib/FixMyStreet/App/Controller/Tokens.pm
@@ -33,11 +33,17 @@ sub confirm_problem : Path('/P') {
# Load the problem
my $data = $auth_token->data;
- my $problem_id = $data->{id};
+ my $problem_id = ref $data ? $data->{id} : $data;
my $problem = $c->cobrand->problems->find( { id => $problem_id } )
|| $c->detach('token_error');
$c->stash->{problem} = $problem;
+ if ( $problem->state eq 'unconfirmed' && $auth_token->created < DateTime->now->subtract( months => 1 ) ) {
+ $c->stash->{template} = 'errors/generic.html';
+ $c->stash->{message} = _("I'm afraid we couldn't validate that token, as the report was made too long ago.");
+ return;
+ }
+
# check that this email or domain are not the cause of abuse. If so hide it.
if ( $problem->is_from_abuser ) {
$problem->update(
@@ -47,6 +53,7 @@ sub confirm_problem : Path('/P') {
}
# We have a problem - confirm it if needed!
+ my $old_state = $problem->state;
$problem->update(
{
state => 'confirmed',
@@ -60,7 +67,7 @@ sub confirm_problem : Path('/P') {
$c->forward( '/report/new/create_reporter_alert' );
# log the problem creation user in to the site
- if ( $data->{name} || $data->{password} ) {
+ if ( ref($data) && ( $data->{name} || $data->{password} ) ) {
$problem->user->name( $data->{name} ) if $data->{name};
$problem->user->password( $data->{password}, 1 ) if $data->{password};
$problem->user->update;
@@ -68,6 +75,11 @@ sub confirm_problem : Path('/P') {
$c->authenticate( { email => $problem->user->email }, 'no_password' );
$c->set_session_cookie_expire(0);
+ if ( $old_state eq 'confirmed' || $old_state eq 'fixed' ) {
+ my $report_uri = $c->uri_for( '/report', $problem->id );
+ $c->res->redirect($report_uri);
+ }
+
return 1;
}
@@ -169,10 +181,6 @@ sub confirm_update : Path('/C') {
sub load_questionnaire : Private {
my ( $self, $c, $token_code ) = @_;
- # Set up error handling
- $c->stash->{error_template} = 'errors/generic.html';
- $c->stash->{message} = _("I'm afraid we couldn't validate that token. If you've copied the URL from an email, please check that you copied it exactly.\n");
-
my $auth_token = $c->forward( 'load_auth_token', [ $token_code, 'questionnaire' ] );
$c->stash->{id} = $auth_token->data;
$c->stash->{token} = $token_code;
@@ -191,7 +199,7 @@ sub questionnaire : Path('/Q') : Args(1) {
$c->authenticate( { email => $c->stash->{questionnaire}->problem->user->email }, 'no_password' );
$c->set_session_cookie_expire(0);
- $c->forward( '/questionnaire/index');
+ $c->forward( '/questionnaire/show' );
}
=head2 load_auth_token
@@ -218,21 +226,26 @@ sub load_auth_token : Private {
scope => $scope,
token => $token_code,
}
- ) || $c->detach('token_error');
+ );
+
+ unless ( $token ) {
+ $c->stash->{template} = 'errors/generic.html';
+ $c->stash->{message} = _("I'm afraid we couldn't validate that token. If you've copied the URL from an email, please check that you copied it exactly.\n");
+ $c->detach;
+ }
return $token;
}
=head2 token_error
-Display an error page saying that there is something wrong with the token.
+Display an error page saying that there is something wrong with the token (our end).
=cut
sub token_error : Private {
my ( $self, $c ) = @_;
- $c->stash->{template} = $c->stash->{error_template} || 'tokens/error.html';
- $c->detach;
+ $c->stash->{template} = 'tokens/error.html';
}
__PACKAGE__->meta->make_immutable;