Skip to content

Commit

Permalink
Convert Auth.providers into array
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Jan 3, 2025
1 parent 7286ad0 commit 615a669
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 5 additions & 1 deletion app/views/accounts/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
<fieldset class="mb-3">
<label for="user_auth_provider" class="form-label"><%= t(".external auth") %></label>
<div class="row">
<%= f.select(:auth_provider, { t("auth.providers.none") => "" }.merge(Auth.providers), :hide_label => true, :wrapper => { :class => "col-auto mb-0" }) %>
<%= f.select :auth_provider,
Auth.providers.map { |provider| [I18n.t("auth.providers.#{provider}"), provider] },
:include_blank => t("auth.providers.none"),
:hide_label => true,
:wrapper => { :class => "col-auto mb-0" } %>
<%= f.text_field(:auth_uid, :hide_label => true, :wrapper => { :class => "col mb-0" }) %>
</div>
<small class="form-text text-body-secondary">(<a href="<%= t ".openid.link" %>" target="_new"><%= t ".openid.link text" %></a>)</small>
Expand Down
4 changes: 2 additions & 2 deletions app/views/application/_auth_providers.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% prefered_auth_button_available = @preferred_auth_provider != "openid" && Auth.providers.value?(@preferred_auth_provider) %>
<% prefered_auth_button_available = @preferred_auth_provider != "openid" && Auth.providers.include?(@preferred_auth_provider) %>

<div>
<%= tag.div :id => "login_auth_buttons",
Expand All @@ -11,7 +11,7 @@
<% end %>

<div class="col justify-content-center d-flex align-items-center flex-wrap gap-2">
<% Auth.providers.each_value do |provider| %>
<% Auth.providers.each do |provider| %>
<% if provider == "openid" %>
<%= button_tag image_tag("auth_providers/openid.svg",
:alt => t(".openid.alt"),
Expand Down
18 changes: 8 additions & 10 deletions lib/auth.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
module Auth
@providers = {}
@providers = ["openid"]
@providers << "google" if Settings.key?(:google_auth_id)
@providers << "facebook" if Settings.key?(:facebook_auth_id)
@providers << "microsoft" if Settings.key?(:microsoft_auth_id)
@providers << "github" if Settings.key?(:github_auth_id)
@providers << "wikipedia" if Settings.key?(:wikipedia_auth_id)
@providers.freeze

def self.providers
@providers[I18n.locale] ||= {
I18n.t("auth.providers.openid") => "openid"
}.tap do |providers|
providers[I18n.t("auth.providers.google")] = "google" if Settings.key?(:google_auth_id)
providers[I18n.t("auth.providers.facebook")] = "facebook" if Settings.key?(:facebook_auth_id)
providers[I18n.t("auth.providers.microsoft")] = "microsoft" if Settings.key?(:microsoft_auth_id)
providers[I18n.t("auth.providers.github")] = "github" if Settings.key?(:github_auth_id)
providers[I18n.t("auth.providers.wikipedia")] = "wikipedia" if Settings.key?(:wikipedia_auth_id)
end.freeze
@providers
end
end

0 comments on commit 615a669

Please sign in to comment.