Make it easier to add new omniauth buttons

Since we're using the exact same logic for all existing buttons, we can
just get the list of available ones and loop through them.
This commit is contained in:
Javi Martín
2020-07-27 12:29:19 +02:00
parent ed2b217a08
commit b1c2a4a9f2
2 changed files with 13 additions and 31 deletions

View File

@@ -1,4 +1,13 @@
module SettingsHelper module SettingsHelper
def oauth_logins
[
(:twitter if feature?(:twitter_login)),
(:facebook if feature?(:facebook_login)),
(:google_oauth2 if feature?(:google_login)),
(:wordpress_oauth2 if feature?(:wordpress_login))
].compact
end
def feature?(name) def feature?(name)
setting["feature.#{name}"].presence || setting["process.#{name}"].presence setting["feature.#{name}"].presence || setting["process.#{name}"].presence
end end

View File

@@ -6,38 +6,11 @@
</div> </div>
</div> </div>
<% if feature? :twitter_login %> <% oauth_logins.each do |login| %>
<div class="small-12 medium-6 large-4 column end"> <div class="small-12 medium-6 large-4 column end">
<%= link_to t("omniauth.twitter.name"), user_twitter_omniauth_authorize_path, <%= link_to t("omniauth.#{login}.name"), send("user_#{login}_omniauth_authorize_path"),
title: t("omniauth.twitter.#{action}"), title: t("omniauth.#{login}.#{action}"),
class: "button-twitter button expanded", class: "button-#{login.to_s.delete_suffix("_oauth2")} button expanded",
method: :post %>
</div>
<% end %>
<% if feature? :facebook_login %>
<div class="small-12 medium-6 large-4 column end">
<%= link_to t("omniauth.facebook.name"), user_facebook_omniauth_authorize_path,
title: t("omniauth.facebook.#{action}"),
class: "button-facebook button expanded",
method: :post %>
</div>
<% end %>
<% if feature? :google_login %>
<div class="small-12 medium-6 large-4 column end">
<%= link_to t("omniauth.google_oauth2.name"), user_google_oauth2_omniauth_authorize_path,
title: t("omniauth.google_oauth2.#{action}"),
class: "button-google button expanded",
method: :post %>
</div>
<% end %>
<% if feature? :wordpress_login %>
<div class="small-12 medium-6 large-4 column end">
<%= link_to t("omniauth.wordpress_oauth2.name"), user_wordpress_oauth2_omniauth_authorize_path,
title: t("omniauth.wordpress_oauth2.#{action}"),
class: "button-wordpress button expanded",
method: :post %> method: :post %>
</div> </div>
<% end %> <% end %>