]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/user_controller.rb
Fixed tests + Altered migration file + Added reporting strings + Added update method
[rails.git] / app / controllers / user_controller.rb
index a7fcdb26d802b8d5ffb50f086ccb29289b7b3f2c..d250cf21c457a0687e0d2b58c7bf311b7194f474 100644 (file)
@@ -297,7 +297,7 @@ class UserController < ApplicationController
         user = token.user
         user.status = "active"
         user.email_valid = true
-        gravatar_enable(user)
+        flash[:notice] = gravatar_status_message(user) if gravatar_enable(user)
         user.save!
         referer = token.referer
         token.destroy
@@ -349,9 +349,13 @@ class UserController < ApplicationController
         @user.email = @user.new_email
         @user.new_email = nil
         @user.email_valid = true
-        gravatar_enable(@user)
+        gravatar_enabled = gravatar_enable(@user)
         if @user.save
-          flash[:notice] = t "user.confirm_email.success"
+          flash[:notice] = if gravatar_enabled
+                             t("user.confirm_email.success") + " " + gravatar_status_message(@user)
+                           else
+                             t("user.confirm_email.success")
+                           end
         else
           flash[:errors] = @user.errors
         end
@@ -806,18 +810,22 @@ class UserController < ApplicationController
   # check if this user has a gravatar and set the user pref is true
   def gravatar_enable(user)
     # code from example https://en.gravatar.com/site/implement/images/ruby/
-    return if user.image.present?
+    return false if user.image.present?
     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))
     oldsetting = user.image_use_gravatar
     user.image_use_gravatar = response.success?
-    if oldsetting != user.image_use_gravatar
-      flash[:warning] = if user.image_use_gravatar
-                          t "user.account.gravatar.enabled"
-                        else
-                          t "user.account.gravatar.disabled"
-                        end
+    oldsetting != user.image_use_gravatar
+  end
+
+  ##
+  # display a message about th current status of the gravatar setting
+  def gravatar_status_message(user)
+    if user.image_use_gravatar
+      return t "user.account.gravatar.enabled"
+    else
+      return t "user.account.gravatar.disabled"
     end
   end
 end