]> git.openstreetmap.org Git - rails.git/commitdiff
Cache OpenID provider names on a per-locale basis
authorTom Hughes <tom@compton.nu>
Wed, 15 Apr 2020 21:48:28 +0000 (22:48 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 15 Apr 2020 21:48:28 +0000 (22:48 +0100)
Fixes #2591

app/views/users/account.html.erb
app/views/users/new.html.erb
lib/auth.rb

index fadb74f4c4abcec2cd1d88d813a14e6f476c8c61..51c933b5d51f7341dc2a0091f4b219ffdb19e4ae 100644 (file)
@@ -48,7 +48,7 @@
   <fieldset>
     <div class="standard-form-row">
       <label class="standard-label"><%= t ".external auth" %></label>
-      <%= f.select :auth_provider, Auth::PROVIDERS %>
+      <%= f.select :auth_provider, Auth.providers %>
       <%= f.text_field :auth_uid %>
       <span class="form-help deemphasize">(<a href="<%= t ".openid.link" %>" target="_new"><%= t ".openid.link text" %></a>)</span>
     </div>
index ba0987c33a85a3ef156a2b6404d781e1d468647f..6f97a284a583559d94c977fb2ab0de4f332c4ae6 100644 (file)
@@ -52,7 +52,7 @@
           <label for="openid_url" class="standard-label">
             <%= t ".external auth" %>
           </label>
-          <%= f.select(:auth_provider, Auth::PROVIDERS, :default => "", :tabindex => 4) %>
+          <%= f.select(:auth_provider, Auth.providers, :default => "", :tabindex => 4) %>
           <%= f.text_field(:auth_uid, :tabindex => 5) %>
           <%= f.error_message_on(:auth_uid) %>
         </div>
index ff9a226632358272b9214cfb361c8949022f03ec..bc1ee8ec6446e75a7d4d70e4710d5c522c8b3dc5 100644 (file)
@@ -1,12 +1,16 @@
 module Auth
-  PROVIDERS = {
-    I18n.t("auth.providers.none") => "",
-    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.windowslive")] = "windowslive" if Settings.key?(:windowslive_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 = {}
+
+  def self.providers
+    @providers[I18n.locale] ||= {
+      I18n.t("auth.providers.none") => "",
+      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.windowslive")] = "windowslive" if Settings.key?(:windowslive_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
+  end
 end