]> git.openstreetmap.org Git - rails.git/commitdiff
Extract 3rd party login buttons from login screen
authorMilan Cvetkovic <mcvetkovic@microsoft.com>
Mon, 18 Mar 2024 12:37:28 +0000 (12:37 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 27 Apr 2024 11:44:09 +0000 (12:44 +0100)
app/assets/javascripts/auth_providers.js [new file with mode: 0644]
app/assets/javascripts/login.js
app/helpers/user_helper.rb
app/views/application/_auth_providers.html.erb [new file with mode: 0644]
app/views/sessions/new.html.erb
config/locales/en.yml

diff --git a/app/assets/javascripts/auth_providers.js b/app/assets/javascripts/auth_providers.js
new file mode 100644 (file)
index 0000000..35da7b5
--- /dev/null
@@ -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();
+});
index 43e2cf6606361e83b74408ef998f2cf54ae534ae..83ca4d440dd3b238797529b252a6684b5729dca6 100644 (file)
@@ -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);
   }
 $(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();
 });
 });
index 19bb8e0d6fb2d9da218c3cd3e67d17cfcec3319d..d0b2f0be550a47874e150eef4be3c1cb94d722e5 100644 (file)
@@ -53,19 +53,19 @@ module UserHelper
   # External authentication support
 
   def openid_logo
   # 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",
   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",
                 :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
 
     )
   end
 
diff --git a/app/views/application/_auth_providers.html.erb b/app/views/application/_auth_providers.html.erb
new file mode 100644 (file)
index 0000000..9c72d7a
--- /dev/null
@@ -0,0 +1,33 @@
+<div>
+  <div class="mb-3">
+    <label class="form-label"><%= t ".with external" %></label>
+
+    <ul class='list-inline' id="login_auth_buttons">
+      <li class="list-inline-item me-3">
+        <%= 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") %>
+      </li>
+
+      <% %w[google facebook microsoft github wikipedia].each do |provider| %>
+        <% if Settings.key?("#{provider}_auth_id".to_sym) -%>
+          <li class="list-inline-item me-3"><%= auth_button provider, provider %></li>
+        <% end -%>
+      <% end -%>
+    </ul>
+
+    <%= form_tag(auth_path(:provider => "openid"), :id => "openid_login_form") do %>
+      <div id='login_openid_url' class="mb-3">
+        <label for='openid_url' class="form-label"><%= t ".openid_html", :logo => openid_logo %></label>
+        <%= hidden_field_tag("referer", params[:referer], :autocomplete => "off") %>
+        <%= text_field_tag("openid_url", "", :tabindex => 5, :autocomplete => "on", :class => "openid_url form-control") %>
+        <span class="form-text text-muted">(<a href="<%= t "accounts.edit.openid.link" %>" target="_new"><%= t "accounts.edit.openid.link text" %></a>)</span>
+      </div>
+
+      <%= submit_tag t(".openid_login_button"), :tabindex => 6, :id => "openid_login_button", :class => "btn btn-primary" %>
+    <% end %>
+  </div>
+</div>
index 08ab872aa8420c20184eeaaece9ef17f76b89f44..b64801e16ae991195bc7064ab75506d596b0dc96 100644 (file)
@@ -1,5 +1,6 @@
 <% content_for :head do %>
   <%= javascript_include_tag "login" %>
 <% content_for :head do %>
   <%= javascript_include_tag "login" %>
+  <%= javascript_include_tag "auth_providers" %>
 <% end %>
 
 <% content_for :heading_class, "p-0 mw-100" %>
 <% end %>
 
 <% content_for :heading_class, "p-0 mw-100" %>
 
   <hr>
 
 
   <hr>
 
-  <div id="loginForm">
-    <div class="mb-3">
-      <label class="form-label"><%= t ".with external" %></label>
-
-      <ul class='list-inline' id="login_auth_buttons">
-        <li class="list-inline-item me-3">
-          <%= link_to image_tag("openid.png",
-                                :alt => t(".auth_providers.openid.title"),
-                                :size => "36"),
-                      "#",
-                      :id => "openid_open_url",
-                      :title => t(".auth_providers.openid.title") %>
-        </li>
-
-        <% %w[google facebook microsoft github wikipedia].each do |provider| %>
-          <% if Settings.key?("#{provider}_auth_id".to_sym) -%>
-            <li class="list-inline-item me-3"><%= auth_button provider, provider %></li>
-          <% end -%>
-        <% end -%>
-      </ul>
-
-      <%= form_tag(auth_path(:provider => "openid"), :id => "openid_login_form") do %>
-        <div id='login_openid_url' class="mb-3">
-          <label for='openid_url' class="form-label"><%= t ".openid_html", :logo => openid_logo %></label>
-          <%= hidden_field_tag("referer", params[:referer], :autocomplete => "off") %>
-          <%= text_field_tag("openid_url", "", :tabindex => 5, :autocomplete => "on", :class => "openid_url form-control") %>
-          <span class="form-text text-muted">(<a href="<%= t "accounts.edit.openid.link" %>" target="_new"><%= t "accounts.edit.openid.link text" %></a>)</span>
-        </div>
-
-        <%= submit_tag t(".login_button"), :tabindex => 6, :id => "login_openid_submit", :class => "btn btn-primary" %>
-      <% end %>
-    </div>
-  </div>
+  <%= render :partial => "auth_providers" %>
 </div>
 </div>
index 25bab6cf0b38ddc472d6a54a4994fe2a2135bc7c..f6d79369beaabaf7bafa80c7c8ce8a399621b493 100644 (file)
@@ -1850,7 +1850,6 @@ en:
       heading: "Log in"
       email or username: "Email Address or Username"
       password: "Password"
       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"
       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."
       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"
     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
       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"
   oauth:
     authorize:
       title: "Authorize access to your account"