diff options
author | Matthew Somerville <matthew@mysociety.org> | 2011-06-28 12:19:05 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2011-06-28 12:19:05 +0100 |
commit | 841cb92f5e395e77af08374affbca828f8c28c48 (patch) | |
tree | 025c012d33f96cd6a8b72cfbe4a18b73eda5adb2 /perllib/FixMyStreet/App/Controller | |
parent | b3c14cc0e839fc11c1d192c46476751e5154d2d7 (diff) |
Allow people to sign in (or not) as they make an update.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index d586035bc..71031bb0d 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -20,15 +20,15 @@ Creates an update to a report sub report_update : Path : Args(0) { my ( $self, $c ) = @_; - $c->forward( '/report/load_problem_or_display_error', [ $c->req->param('id') ] ) - && $c->forward('process_update') - && $c->forward('process_user') - && $c->forward('/report/new/process_photo') - && $c->forward('check_for_errors') + $c->forward( '/report/load_problem_or_display_error', [ $c->req->param('id') ] ); + $c->forward('process_update'); + $c->forward('process_user'); + $c->forward('/report/new/process_photo'); + $c->forward('check_for_errors') or $c->go( '/report/display', [ $c->req->param('id') ] ); - return $c->forward('save_update') - && $c->forward('redirect_or_confirm_creation'); + $c->forward('save_update'); + $c->forward('redirect_or_confirm_creation'); } sub confirm : Private { @@ -88,12 +88,17 @@ sub process_user : Private { my $update = $c->stash->{update}; - $update->user( $c->user->obj ) if $c->user; + if ( $c->user_exists ) { + my $user = $c->user->obj; + my $name = scalar $c->req->param('name'); + $user->name( Utils::trim_text( $name ) ) if $name; + $update->user( $user ); + return 1; + } # Extract all the params to a hash to make them easier to work with - my %params = # - map { $_ => scalar $c->req->param($_) } # - ( 'rznvy', 'name' ); + my %params = map { $_ => scalar $c->req->param($_) } + ( 'rznvy', 'name', 'password_register' ); # cleanup the email address my $email = $params{rznvy} ? lc $params{rznvy} : ''; @@ -102,8 +107,22 @@ sub process_user : Private { $update->user( $c->model('DB::User')->find_or_new( { email => $email } ) ) unless $update->user; + # The user is trying to sign in. We only care about email from the params. + if ( $c->req->param('submit_sign_in') ) { + unless ( $c->forward( '/auth/sign_in', [ $email ] ) ) { + $c->stash->{field_errors}->{password} = _('There was a problem with your email/password combination. Please try again.'); + return 1; + } + my $user = $c->user->obj; + $update->user( $user ); + $update->name( $user->name ); + $c->stash->{field_errors}->{name} = _('You have successfully signed in; please check and confirm your details are accurate:'); + return 1; + } + $update->user->name( Utils::trim_text( $params{name} ) ) if $params{name}; + $update->user->password( Utils::trim_text( $params{password_register} ) ); return 1; } @@ -128,10 +147,7 @@ sub process_update : Private { Utils::cleanup_text( $params{update}, { allow_multiline => 1 } ); my $name = Utils::trim_text( $params{name} ); - - my $anonymous = 1; - - $anonymous = 0 if ( $name && $c->req->param('may_show_name') ); + my $anonymous = $c->req->param('may_show_name') ? 0 : 1; my $update = $c->model('DB::Comment')->new( { @@ -165,25 +181,27 @@ sub check_for_errors : Private { my ( $self, $c ) = @_; # let the model check for errors + $c->stash->{field_errors} ||= {}; my %field_errors = ( + %{ $c->stash->{field_errors} }, %{ $c->stash->{update}->user->check_for_errors }, %{ $c->stash->{update}->check_for_errors }, ); - # we don't care if there are errors with this... - delete $field_errors{name}; + if ( my $photo_error = delete $c->stash->{photo_error} ) { + $field_errors{photo} = $photo_error; + } # all good if no errors return 1 unless ( scalar keys %field_errors - || ( $c->stash->{errors} && scalar @{ $c->stash->{errors} } ) - || $c->stash->{photo_error} ); + || ( $c->stash->{errors} && scalar @{ $c->stash->{errors} } ) ); $c->stash->{field_errors} = \%field_errors; $c->stash->{errors} ||= []; - push @{ $c->stash->{errors} }, - _('There were problems with your update. Please see below.'); + #push @{ $c->stash->{errors} }, + # _('There were problems with your update. Please see below.'); return; } |