]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/user_controller.rb
Use start.html.erb views instead of _sidebar.html.erb partials
[rails.git] / app / controllers / user_controller.rb
index bccd5d5cb499480ccf1055cbaa75075631159312..620ab5090a64b8d17f4808462e7fd610f2a21073 100644 (file)
@@ -397,47 +397,55 @@ class UserController < ApplicationController
   end
 
   def make_friend
-    if params[:display_name]
-      name = params[:display_name]
-      new_friend = User.active.where(:display_name => name).first
-      friend = Friend.new
-      friend.user_id = @user.id
-      friend.friend_user_id = new_friend.id
-      unless @user.is_friends_with?(new_friend)
-        if friend.save
-          flash[:notice] = t 'user.make_friend.success', :name => name
-          Notifier.friend_notification(friend).deliver
+    @new_friend = User.find_by_display_name(params[:display_name])
+
+    if @new_friend
+      if request.post?
+        friend = Friend.new
+        friend.user_id = @user.id
+        friend.friend_user_id = @new_friend.id
+        unless @user.is_friends_with?(@new_friend)
+          if friend.save
+            flash[:notice] = t 'user.make_friend.success', :name => @new_friend.display_name
+            Notifier.friend_notification(friend).deliver
+          else
+            friend.add_error(t('user.make_friend.failed', :name => @new_friend.display_name))
+          end
         else
-          friend.add_error(t('user.make_friend.failed', :name => name))
+          flash[:warning] = t 'user.make_friend.already_a_friend', :name => @new_friend.display_name
         end
-      else
-        flash[:warning] = t 'user.make_friend.already_a_friend', :name => name
-      end
 
-      if params[:referer]
-        redirect_to params[:referer]
-      else
-        redirect_to :controller => 'user', :action => 'view'
+        if params[:referer]
+          redirect_to params[:referer]
+        else
+          redirect_to :controller => 'user', :action => 'view'
+        end
       end
+    else
+      render_unknown_user params[:display_name]
     end
   end
 
   def remove_friend
-    if params[:display_name]
-      name = params[:display_name]
-      friend = User.active.where(:display_name => name).first
-      if @user.is_friends_with?(friend)
-        Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{friend.id}"
-        flash[:notice] = t 'user.remove_friend.success', :name => friend.display_name
-      else
-        flash[:error] = t 'user.remove_friend.not_a_friend', :name => friend.display_name
-      end
+    @friend = User.find_by_display_name(params[:display_name])
 
-      if params[:referer]
-        redirect_to params[:referer]
-      else
-        redirect_to :controller => 'user', :action => 'view'
+    if @friend
+      if request.post?
+        if @user.is_friends_with?(@friend)
+          Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{@friend.id}"
+          flash[:notice] = t 'user.remove_friend.success', :name => @friend.display_name
+        else
+          flash[:error] = t 'user.remove_friend.not_a_friend', :name => @friend.display_name
+        end
+
+        if params[:referer]
+          redirect_to params[:referer]
+        else
+          redirect_to :controller => 'user', :action => 'view'
+        end
       end
+    else
+      render_unknown_user params[:display_name]
     end
   end
 
@@ -517,7 +525,7 @@ private
         if user = User.find_by_openid_url(identity_url)
           case user.status
             when "pending" then
-              failed_login t('user.login.account not active')
+              failed_login t('user.login.account not active', :reconfirm => url_for(:action => 'confirm_resend', :display_name => user.display_name))
             when "active", "confirmed" then
               successful_login(user)
             when "suspended" then
@@ -534,8 +542,8 @@ private
           # to the create account page with username and email filled
           # in if they have been given by the OpenID provider through
           # the simple registration protocol.
-          nickname = sreg["nickname"] || ax["http://axschema.org/namePerson/friendly"]
-          email = sreg["email"] || ax["http://axschema.org/contact/email"]
+          nickname = sreg["nickname"] || ax["http://axschema.org/namePerson/friendly"].first
+          email = sreg["email"] || ax["http://axschema.org/contact/email"].first
           redirect_to :controller => 'user', :action => 'new', :nickname => nickname, :email => email, :openid => identity_url
         end
       elsif result.missing?