From: Milan Cvetkovic Date: Mon, 18 Mar 2024 12:37:28 +0000 (+0000) Subject: Extract 3rd party login buttons from login screen X-Git-Tag: live~577^2~7 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/ae87d2ca7f602cd6005efb2ad41f2c580eb6406f?ds=sidebyside Extract 3rd party login buttons from login screen --- diff --git a/app/assets/javascripts/auth_providers.js b/app/assets/javascripts/auth_providers.js new file mode 100644 index 000000000..35da7b5e4 --- /dev/null +++ b/app/assets/javascripts/auth_providers.js @@ -0,0 +1,23 @@ +//= require qs/dist/qs + +$(document).ready(function () { + // Attach referer to authentication buttons + $(".auth_button").each(function () { + var params = Qs.parse(this.search.substring(1)); + params.referer = $("#referer").val(); + this.search = Qs.stringify(params); + }); + + // Add click handler to show OpenID field + $("#openid_open_url").click(function (e) { + e.preventDefault(); + $("#openid_url").val("http://"); + $("#login_auth_buttons").hide(); + $("#login_openid_url").show(); + $("#openid_login_button").show(); + }); + + // Hide OpenID field for now + $("#login_openid_url").hide(); + $("#openid_login_button").hide(); +}); diff --git a/app/assets/javascripts/login.js b/app/assets/javascripts/login.js index 43e2cf660..83ca4d440 100644 --- a/app/assets/javascripts/login.js +++ b/app/assets/javascripts/login.js @@ -1,28 +1,6 @@ -//= qs/dist/qs - $(document).ready(function () { // Preserve location hash in referer if (window.location.hash) { $("#referer").val($("#referer").val() + window.location.hash); } - - // Attach referer to authentication buttons - $(".auth_button").each(function () { - var params = Qs.parse(this.search.substring(1)); - params.referer = $("#referer").val(); - this.search = Qs.stringify(params); - }); - - // Add click handler to show OpenID field - $("#openid_open_url").click(function (e) { - e.preventDefault(); - $("#openid_url").val("http://"); - $("#login_auth_buttons").hide(); - $("#login_openid_url").show(); - $("#login_openid_submit").show(); - }); - - // Hide OpenID field for now - $("#login_openid_url").hide(); - $("#login_openid_submit").hide(); }); diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb index 19bb8e0d6..d0b2f0be5 100644 --- a/app/helpers/user_helper.rb +++ b/app/helpers/user_helper.rb @@ -53,19 +53,19 @@ module UserHelper # External authentication support def openid_logo - image_tag "openid_small.png", :alt => t("sessions.new.openid_logo_alt"), :class => "align-text-bottom" + image_tag "openid_small.png", :alt => t("application.auth_providers.openid_logo_alt"), :class => "align-text-bottom" end def auth_button(name, provider, options = {}) link_to( image_tag("#{name}.svg", - :alt => t("sessions.new.auth_providers.#{name}.alt"), + :alt => t("application.auth_providers.#{name}.alt"), :class => "rounded-3", :size => "36"), auth_path(options.merge(:provider => provider)), :method => :post, :class => "auth_button", - :title => t("sessions.new.auth_providers.#{name}.title") + :title => t("application.auth_providers.#{name}.title") ) end diff --git a/app/views/application/_auth_providers.html.erb b/app/views/application/_auth_providers.html.erb new file mode 100644 index 000000000..9c72d7aa0 --- /dev/null +++ b/app/views/application/_auth_providers.html.erb @@ -0,0 +1,33 @@ +
+
+ + +
    +
  • + <%= link_to image_tag("openid.png", + :alt => t("application.auth_providers.openid.title"), + :size => "36"), + "#", + :id => "openid_open_url", + :title => t("application.auth_providers.openid.title") %> +
  • + + <% %w[google facebook microsoft github wikipedia].each do |provider| %> + <% if Settings.key?("#{provider}_auth_id".to_sym) -%> +
  • <%= auth_button provider, provider %>
  • + <% end -%> + <% end -%> +
+ + <%= form_tag(auth_path(:provider => "openid"), :id => "openid_login_form") do %> +
+ + <%= hidden_field_tag("referer", params[:referer], :autocomplete => "off") %> + <%= text_field_tag("openid_url", "", :tabindex => 5, :autocomplete => "on", :class => "openid_url form-control") %> + (" target="_new"><%= t "accounts.edit.openid.link text" %>) +
+ + <%= submit_tag t(".openid_login_button"), :tabindex => 6, :id => "openid_login_button", :class => "btn btn-primary" %> + <% end %> +
+
diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 08ab872aa..b64801e16 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -1,5 +1,6 @@ <% content_for :head do %> <%= javascript_include_tag "login" %> + <%= javascript_include_tag "auth_providers" %> <% end %> <% content_for :heading_class, "p-0 mw-100" %> @@ -37,37 +38,5 @@
-
-
- - -
    -
  • - <%= link_to image_tag("openid.png", - :alt => t(".auth_providers.openid.title"), - :size => "36"), - "#", - :id => "openid_open_url", - :title => t(".auth_providers.openid.title") %> -
  • - - <% %w[google facebook microsoft github wikipedia].each do |provider| %> - <% if Settings.key?("#{provider}_auth_id".to_sym) -%> -
  • <%= auth_button provider, provider %>
  • - <% end -%> - <% end -%> -
- - <%= form_tag(auth_path(:provider => "openid"), :id => "openid_login_form") do %> -
- - <%= hidden_field_tag("referer", params[:referer], :autocomplete => "off") %> - <%= text_field_tag("openid_url", "", :tabindex => 5, :autocomplete => "on", :class => "openid_url form-control") %> - (" target="_new"><%= t "accounts.edit.openid.link text" %>) -
- - <%= submit_tag t(".login_button"), :tabindex => 6, :id => "login_openid_submit", :class => "btn btn-primary" %> - <% end %> -
-
+ <%= render :partial => "auth_providers" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 25bab6cf0..f6d79369b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1850,7 +1850,6 @@ en: heading: "Log in" email or username: "Email Address or Username" password: "Password" - openid_html: "%{logo} OpenID" remember: "Remember me" lost password link: "Lost your password?" login_button: "Log in" @@ -1858,32 +1857,6 @@ en: with external: "Alternatively, use a third party to log in:" no account: Don't have an account? auth failure: "Sorry, could not log in with those details." - openid_logo_alt: "Log in with an OpenID" - auth_providers: - openid: - title: Log in with OpenID - alt: Log in with an OpenID URL - google: - title: Log in with Google - alt: Log in with a Google OpenID - facebook: - title: Log in with Facebook - alt: Log in with a Facebook Account - microsoft: - title: Log in with Microsoft - alt: Log in with a Microsoft Account - github: - title: Log in with GitHub - alt: Log in with a GitHub Account - wikipedia: - title: Log in with Wikipedia - alt: Log in with a Wikipedia Account - wordpress: - title: Log in with Wordpress - alt: Log in with a Wordpress OpenID - aol: - title: Log in with AOL - alt: Log in with an AOL OpenID destroy: title: "Logout" heading: "Logout from OpenStreetMap" @@ -2598,6 +2571,35 @@ en: oauth2_applications: OAuth 2 applications oauth2_authorizations: OAuth 2 authorizations muted_users: Muted Users + auth_providers: + openid_logo_alt: "Log in with an OpenID" + openid_html: "%{logo} OpenID" + openid_login_button: "Continue" + with external: "Alternatively, use a third party to login:" + openid: + title: Log in with OpenID + alt: Log in with an OpenID URL + google: + title: Log in with Google + alt: Log in with a Google OpenID + facebook: + title: Log in with Facebook + alt: Log in with a Facebook Account + microsoft: + title: Log in with Microsoft + alt: Log in with a Microsoft Account + github: + title: Log in with GitHub + alt: Log in with a GitHub Account + wikipedia: + title: Log in with Wikipedia + alt: Log in with a Wikipedia Account + wordpress: + title: Log in with Wordpress + alt: Log in with a Wordpress OpenID + aol: + title: Log in with AOL + alt: Log in with an AOL OpenID oauth: authorize: title: "Authorize access to your account"