From b1c2a4a9f2fcbbb1686265666c237e70f39d8b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 27 Jul 2020 12:29:19 +0200 Subject: [PATCH] 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. --- app/helpers/settings_helper.rb | 9 ++++++ app/views/devise/_omniauth_form.html.erb | 35 +++--------------------- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index b03675c2c..7280f71f2 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -1,4 +1,13 @@ 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) setting["feature.#{name}"].presence || setting["process.#{name}"].presence end diff --git a/app/views/devise/_omniauth_form.html.erb b/app/views/devise/_omniauth_form.html.erb index d820e5e4e..516e32cbb 100644 --- a/app/views/devise/_omniauth_form.html.erb +++ b/app/views/devise/_omniauth_form.html.erb @@ -6,38 +6,11 @@ - <% if feature? :twitter_login %> + <% oauth_logins.each do |login| %>
- <%= link_to t("omniauth.twitter.name"), user_twitter_omniauth_authorize_path, - title: t("omniauth.twitter.#{action}"), - class: "button-twitter button expanded", - method: :post %> -
- <% end %> - - <% if feature? :facebook_login %> -
- <%= link_to t("omniauth.facebook.name"), user_facebook_omniauth_authorize_path, - title: t("omniauth.facebook.#{action}"), - class: "button-facebook button expanded", - method: :post %> -
- <% end %> - - <% if feature? :google_login %> -
- <%= 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 %> -
- <% end %> - - <% if feature? :wordpress_login %> -
- <%= link_to t("omniauth.wordpress_oauth2.name"), user_wordpress_oauth2_omniauth_authorize_path, - title: t("omniauth.wordpress_oauth2.#{action}"), - class: "button-wordpress button expanded", + <%= link_to t("omniauth.#{login}.name"), send("user_#{login}_omniauth_authorize_path"), + title: t("omniauth.#{login}.#{action}"), + class: "button-#{login.to_s.delete_suffix("_oauth2")} button expanded", method: :post %>
<% end %>