diff options
author | M Somerville <matthew-github@dracos.co.uk> | 2020-09-30 20:04:05 +0100 |
---|---|---|
committer | M Somerville <matthew-github@dracos.co.uk> | 2020-09-30 20:04:05 +0100 |
commit | 3a511f5facc4bd066f0e7e4d00060979686bb766 (patch) | |
tree | 9438a2b3de8f2784e9ee588bb8b4b871f152213e /perllib/FixMyStreet/App/Controller/Report/Update.pm | |
parent | b6fb09db4ff31aba28833b9e735e6c92ce9081c7 (diff) | |
parent | 2abe443efb8bbbd7cf3048eec271fd28a777932f (diff) |
Merge branch 'improved-email-phone-in-form'
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 8ffba3dcf..2acafc654 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -6,7 +6,6 @@ BEGIN { extends 'Catalyst::Controller'; } use utf8; use Path::Class; -use List::Util 'first'; use Utils; =head1 NAME @@ -103,8 +102,14 @@ sub process_user : Private { my %params = map { $_ => $c->get_param($_) } ( 'name', 'password_register', 'fms_extra_title' ); - # Update form includes two username fields: #form_username_register and #form_username_sign_in - $params{username} = (first { $_ } $c->get_param_list('username')) || ''; + if ($c->user_exists) { + $params{username} = $c->get_param('username'); + } elsif ($c->get_param('submit_sign_in') || $c->get_param('password_sign_in')) { + $params{username} = $c->get_param('username'); + } else { + $params{username} = $c->get_param('username_register'); + } + $params{username} ||= ''; my $anon_button = $c->cobrand->allow_anonymous_reports eq 'button' && $c->get_param('report_anonymously'); if ($anon_button) { @@ -145,8 +150,7 @@ sub process_user : Private { my $parsed = FixMyStreet::SMS->parse_username($params{username}); my $type = $parsed->{type} || 'email'; $type = 'email' unless FixMyStreet->config('SMS_AUTHENTICATION') || $c->stash->{contributing_as_another_user}; - $update->user( $c->model('DB::User')->find_or_new( { $type => $parsed->{username} } ) ) - unless $update->user; + $update->user( $c->model('DB::User')->find_or_new( { $type => $parsed->{username} } ) ); $c->stash->{phone_may_be_mobile} = $type eq 'phone' && $parsed->{may_be_mobile}; @@ -404,6 +408,16 @@ sub check_for_errors : Private { $field_errors{photo} = $photo_error; } + # Now assign the username error according to where it came from + if ($field_errors{username}) { + if ($c->get_param('submit_sign_in') || $c->get_param('password_sign_in')) { + $field_errors{username_sign_in} = $field_errors{username}; + } else { + $field_errors{username_register} = $field_errors{username}; + } + delete $field_errors{username}; + } + # all good if no errors return 1 unless ( scalar keys %field_errors @@ -578,6 +592,11 @@ 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 ]); + my $error = $c->render_fragment( 'auth/_username_error.html', { default => 'phone' }); + if ($error) { + $c->stash->{field_errors}{username_register} = $error; + $c->go( '/report/display', [ $c->stash->{problem}->id ], [] ); + } $c->stash->{submit_url} = '/report/update/text'; } |