Skip to content

Commit

Permalink
If text auth on, ask which method they wish to use
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Sep 23, 2020
1 parent 12cfaca commit 7f0cdce
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 36 deletions.
13 changes: 12 additions & 1 deletion perllib/FixMyStreet/App/Controller/Report/New.pm
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ 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' );
qw( email name phone password_register fms_extra_title update_method );

# Report form includes two username fields: #form_username_register and #form_username_sign_in
$params{username} = (first { $_ } $c->get_param_list('username')) || '';
Expand Down Expand Up @@ -896,6 +896,17 @@ sub process_user : Private {
$params{username} = $params{phone};
}

# Code to deal with SMS being switched on and so the user being asked to
# pick a method and no username field
if (!$params{username} && $params{update_method}) {
if ($params{update_method} eq 'phone') {
$params{username} = $params{phone};
} else {
$params{username} = $params{email};
}
$c->stash->{update_method} = $params{update_method};
}

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};
Expand Down
6 changes: 4 additions & 2 deletions t/app/controller/report_new_text.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ foreach my $test (
msg => 'invalid number',
pc => 'EH1 1BB',
fields => {
username => '0121 4960000000', email => '', phone => '',
update_method => 'phone',
phone => '0121 4960000000', email => '',
title => 'Title', detail => 'Detail', name => 'Bob Jones',
category => 'Street lighting',
may_show_name => '1',
Expand All @@ -37,7 +38,8 @@ foreach my $test (
msg => 'landline number',
pc => 'EH1 1BB',
fields => {
username => '0121 4960000', email => '', phone => '',
update_method => 'phone',
phone => '0121 4960000', email => '',
title => 'Title', detail => 'Detail', name => 'Bob Jones',
category => 'Street lighting',
may_show_name => '1',
Expand Down
56 changes: 36 additions & 20 deletions templates/web/base/report/form/user_loggedout_by_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
[% INCLUDE 'report/form/user_name.html' %]
[% INCLUDE 'report/_show_name_label.html' %]

[% IF type != 'update' %]
[% IF NOT c.cobrand.call_hook('disable_phone_number_entry') AND NOT c.config.SMS_AUTHENTICATION %]
<div id="js-hide-if-username-phone">
<label for="form_phone">[% loc('Phone number (optional)') %]</label>
[% IF field_errors.phone %]
<p class='form-error'>[% field_errors.phone %]</p>
[% END %]
<input class="form-control" type="text" value="[% phone | html %]" name="phone" id="form_phone">
</div>
[% IF type != 'update' AND NOT c.config.SMS_AUTHENTICATION %]
[% UNLESS c.cobrand.call_hook('disable_phone_number_entry') %]
<label for="form_phone">[% loc('Phone number (optional)') %]</label>
[% IF field_errors.phone %]
<p class='form-error'>[% field_errors.phone %]</p>
[% END %]
<input class="form-control" type="text" value="[% phone | html %]" name="phone" id="form_phone">
[% END %]
[% END %]

Expand All @@ -25,19 +23,37 @@
</div>
[% END %]

[% PROCESS 'report/form/user_loggedout_email.html' name='username_register' %]
[% IF type != 'update' AND c.config.SMS_AUTHENTICATION AND NOT c.cobrand.call_hook('disable_phone_number_entry') %]

[% IF type != 'update' AND c.config.SMS_AUTHENTICATION %]
[% UNLESS c.cobrand.call_hook('disable_phone_number_entry') %]
<div id="js-hide-if-username-phone" class="hidden-js">
<label for="form_phone">[% loc('Phone number (optional)') %]</label>
<input class="form-control" type="text" value="[% phone | html %]" name="phone" id="form_phone">
</div>
<fieldset>
<legend>How would you like to receive updates?</legend>

<p class="segmented-control segmented-control--radio">
<input type="radio" name="update_method" id="update_method_email"
data-show="#js-optional-phone" data-hide="#js-optional-email"
value="email"[% ' checked' IF update_method == 'email' %]>
<label class="btn" for="update_method_email">[% loc('Email') %]</label>
<input type="radio" name="update_method" id="update_method_phone"
data-show="#js-optional-email" data-hide="#js-optional-phone"
value="phone"[% ' checked' IF update_method == 'phone' %]>
<label class="btn" for="update_method_phone">[% loc('Phone') %]</label>
</p>
</fieldset>

<label for="form_email">[% loc('Your email') %]<span class="hidden-js" id="js-optional-email"> [% loc('(optional)') %]</span></label>
[% IF field_errors.email %]
<p class='form-error'>[% field_errors.email %]</p>
[% END %]
<div id="js-hide-if-username-email" class="hidden-js">
<label for="form_email">[% loc('Email address (optional)') %]</label>
<input class="form-control" type="text" value="[% email | html %]" name="email" id="form_email">
</div>
<input type="email" name="email" id="form_email" value="[% email %]" class="form-control">

<label for="form_phone">[% loc('Phone number') %]<span class="hidden-js" id="js-optional-phone"> [% loc('(optional)') %]</span></label>
[% IF field_errors.phone %]
<p class='form-error'>[% field_errors.phone %]</p>
[% END %]
<input class="form-control" type="text" value="[% phone %]" name="phone" id="form_phone">

[% ELSE %]
[% PROCESS 'report/form/user_loggedout_email.html' name='username_register' %]
[% END %]

[% IF type == 'update' %]
Expand Down
13 changes: 0 additions & 13 deletions web/cobrands/fixmystreet/fixmystreet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,19 +1094,6 @@ $.extend(fixmystreet.set_up, {
});
},

reporting_hide_phone_email: function() {
$('#form_username_register').on('keyup change', function() {
var username = $(this).val();
if (/^[^a-z]+$/i.test(username)) {
$('#js-hide-if-username-phone').hide();
$('#js-hide-if-username-email').show();
} else {
$('#js-hide-if-username-phone').show();
$('#js-hide-if-username-email').hide();
}
});
},

fancybox_images: function() {
// Fancybox fullscreen images
if (typeof $.fancybox == 'function') {
Expand Down

0 comments on commit 7f0cdce

Please sign in to comment.