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
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
# 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?