]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/users_controller.rb
Handle errors checking for gravatars
[rails.git] / app / controllers / users_controller.rb
index cc8f46d23cb8212479d75d98f38b76443945e7fb..e4dd1b2dc96247c30d612909f2d35502a65c311c 100644 (file)
@@ -271,7 +271,7 @@ class UsersController < ApplicationController
 
   def login
     append_content_security_policy_directives(
-      :form_action => %w[accounts.google.com *.facebook.com login.live.com github.com meta.wikimedia.org]
+      :form_action => %w[*]
     )
 
     session[:referer] = safe_referer(params[:referer]) if params[:referer]
@@ -753,11 +753,17 @@ class UsersController < ApplicationController
     # code from example https://en.gravatar.com/site/implement/images/ruby/
     return false if user.avatar.attached?
 
-    hash = Digest::MD5.hexdigest(user.email.downcase)
-    url = "https://www.gravatar.com/avatar/#{hash}?d=404" # without d=404 we will always get an image back
-    response = OSM.http_client.get(URI.parse(url))
+    begin
+      hash = Digest::MD5.hexdigest(user.email.downcase)
+      url = "https://www.gravatar.com/avatar/#{hash}?d=404" # without d=404 we will always get an image back
+      response = OSM.http_client.get(URI.parse(url))
+      available = response.success?
+    rescue StandardError
+      available = false
+    end
+
     oldsetting = user.image_use_gravatar
-    user.image_use_gravatar = response.success?
+    user.image_use_gravatar = available
     oldsetting != user.image_use_gravatar
   end