Extract 3rd party login buttons from login screen

This commit is contained in:
Milan Cvetkovic 2024-03-18 12:37:28 +00:00 committed by Tom Hughes
parent c4347c8d9a
commit ae87d2ca7f
6 changed files with 90 additions and 85 deletions

View file

@ -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();
});

View 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);
}
// 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();
});

View file

@ -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

View file

@ -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>

View file

@ -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 @@
<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>

View file

@ -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"