diff options
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Westminster.pm | 6 | ||||
-rw-r--r-- | t/cobrand/westminster.t | 74 | ||||
-rw-r--r-- | templates/web/westminster/auth/general.html | 2 | ||||
-rw-r--r-- | templates/web/westminster/report/form/user.html | 30 |
4 files changed, 111 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Westminster.pm b/perllib/FixMyStreet/Cobrand/Westminster.pm index 6076b9caf..a62295aa3 100644 --- a/perllib/FixMyStreet/Cobrand/Westminster.pm +++ b/perllib/FixMyStreet/Cobrand/Westminster.pm @@ -26,4 +26,10 @@ sub enter_postcode_text { sub send_questionnaires { 0 } +sub social_auth_enabled { + my $self = shift; + + return $self->feature('oidc_login') ? 1 : 0; + } + 1; diff --git a/t/cobrand/westminster.t b/t/cobrand/westminster.t new file mode 100644 index 000000000..64e93be47 --- /dev/null +++ b/t/cobrand/westminster.t @@ -0,0 +1,74 @@ +use FixMyStreet::TestMech; + +ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' ); + +FixMyStreet::override_config { + ALLOWED_COBRANDS => 'westminster', + MAPIT_URL => 'http://mapit.uk/', + COBRAND_FEATURES => { + oidc_login => { + westminster => { + client_id => 'example_client_id', + secret => 'example_secret_key', + auth_uri => 'http://oidc.example.org/oauth2/v2.0/authorize', + token_uri => 'http://oidc.example.org/oauth2/v2.0/token', + display_name => 'MyWestminster' + } + } + } +}, sub { + subtest 'Cobrand allows social auth' => sub { + my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('westminster')->new(); + ok $cobrand->social_auth_enabled; + }; + + subtest 'Login button displayed correctly' => sub { + $mech->get_ok("/auth"); + $mech->content_contains("Login with MyWestminster"); + }; +}; + +for ( + { + ALLOWED_COBRANDS => 'westminster', + MAPIT_URL => 'http://mapit.uk/', + COBRAND_FEATURES => { + oidc_login => { + westminster => 0 + } + } + }, + { + ALLOWED_COBRANDS => 'westminster', + MAPIT_URL => 'http://mapit.uk/', + COBRAND_FEATURES => { + oidc_login => { + hounslow => { + client_id => 'example_client_id', + secret => 'example_secret_key', + auth_uri => 'http://oidc.example.org/oauth2/v2.0/authorize', + token_uri => 'http://oidc.example.org/oauth2/v2.0/token', + display_name => 'MyHounslow' + } + } + } + }, + { + ALLOWED_COBRANDS => 'westminster', + MAPIT_URL => 'http://mapit.uk/', + } +) { + FixMyStreet::override_config $_, sub { + subtest 'Cobrand disallows social auth' => sub { + my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('westminster')->new(); + ok !$cobrand->social_auth_enabled; + }; + + subtest 'Login button not displayed' => sub { + $mech->get_ok("/auth"); + $mech->content_lacks("Login with MyWestminster"); + }; + }; +} + +done_testing(); diff --git a/templates/web/westminster/auth/general.html b/templates/web/westminster/auth/general.html index 381e8ff24..4fb639345 100644 --- a/templates/web/westminster/auth/general.html +++ b/templates/web/westminster/auth/general.html @@ -21,7 +21,7 @@ [% IF NOT oauth_need_email AND c.cobrand.social_auth_enabled %] [% IF c.cobrand.feature('oidc_login') %] <div class="form-box"> - <button name="oidc_sign_in" id="oidc_sign_in" value="oidc_sign_in" class="btn btn--block btn--social btn--oidc"> + <button name="social_sign_in" id="oidc_sign_in" value="oidc" class="btn btn--block btn--social btn--oidc"> [% tprintf(loc('Login with %s'), c.cobrand.feature('oidc_login').display_name) %] </button> </div> diff --git a/templates/web/westminster/report/form/user.html b/templates/web/westminster/report/form/user.html new file mode 100644 index 000000000..dd4770430 --- /dev/null +++ b/templates/web/westminster/report/form/user.html @@ -0,0 +1,30 @@ +<!-- report/form/user.html --> +<div class="js-new-report-user-hidden form-section-preview form-section-preview--next + [%~ ' hidden-nojs' IF c.user_exists OR NOT c.cobrand.social_auth_enabled %]"> + <h2 class="form-section-heading form-section-heading--private hidden-nojs"> + [% loc('Next:') %] [% loc('Tell us about you') %] + </h2> +[% IF c.user_exists OR NOT c.cobrand.social_auth_enabled %] + <button class="btn btn--block hidden-nojs js-new-report-user-show">[% loc('Continue') %]</button> +[% ELSE %] + [% IF c.config.FACEBOOK_APP_ID %] + <button name="social_sign_in" id="facebook_sign_in" value="facebook" class="btn btn--block btn--social btn--facebook"> + <img alt="" src="/i/facebook-icon-32.png" width="17" height="32"> + [% loc('Log in with Facebook') %] + </button> + [% END %] + [% IF c.cobrand.feature('oidc_login') %] + <button name="social_sign_in" id="oidc_sign_in" value="oidc" class="btn btn--block btn--social btn--oidc"> + [% tprintf(loc('Login with %s'), c.cobrand.feature('oidc_login').display_name) %] + </button> + [% END %] + [% IF c.config.TWITTER_KEY %] + <button name="social_sign_in" id="twitter_sign_in" value="twitter" class="btn btn--block btn--social btn--twitter"> + <img alt="" src="/i/twitter-icon-32.png" width="17" height="32"> + [% loc('Log in with Twitter') %] + </button> + [% END %] + <button class="btn btn--block hidden-nojs js-new-report-user-show">Confirm by email</button> +[% END %] +</div> +<!-- /report/form/user.html --> |