diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index 07cf63dc8..6f2b09c43 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -21,9 +21,11 @@ class PublicsController < ApplicationController end def webfinger - @person = Person.by_webfinger(params[:q]) + @person = Person.by_webfinger(params[:q], :local => true) unless @person.nil? || @person.owner.nil? render 'webfinger', :content_type => 'application/xrd+xml' + else + render :nothing => true end end diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index 5983c0e2e..6087ebe85 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -36,6 +36,7 @@ class RequestsController < ApplicationController begin rel_hash = relationship_flow(params[:request][:destination_url]) rescue Exception => e + raise e unless e.message.include? "not found" flash[:error] = "No diaspora seed found with this email!" respond_with :location => aspect return diff --git a/app/models/person.rb b/app/models/person.rb index 121fdde56..bed5bb246 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -78,18 +78,18 @@ class Person @serialized_key = new_key end - def self.by_webfinger( identifier ) + def self.by_webfinger( identifier, opts = {}) local_person = Person.first(:diaspora_handle => identifier.gsub('acct:', '')) if local_person local_person - elsif !identifier.include?("localhost") + elsif !identifier.include?("localhost") && !opts[:local] begin f = Redfinger.finger(identifier) rescue SocketError => e raise "Diaspora server for #{identifier} not found" if e.message =~ /Name or service not known/ end - raise "No webfinger profile found at #{identifier}" unless f + raise "No webfinger profile found at #{identifier}" if f.nil? || f.links.empty? Person.from_webfinger_profile(identifier, f ) end end @@ -97,7 +97,11 @@ class Person def self.from_webfinger_profile( identifier, profile) new_person = Person.new - public_key = profile.links.select{|x| x.rel == 'diaspora-public-key'}.first.href + public_key_entry = profile.links.select{|x| x.rel == 'diaspora-public-key'} + + return nil unless public_key_entry + + public_key = public_key_entry.first.href new_person.exported_key = Base64.decode64 public_key guid = profile.links.select{|x| x.rel == 'http://joindiaspora.com/guid'}.first.href diff --git a/app/models/user.rb b/app/models/user.rb index 6b029812c..942dd3e03 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -284,7 +284,7 @@ else ###Helpers############ def self.instantiate!( opts = {} ) - opts[:person][:diaspora_handle] = "#{opts[:username]}@#{opts[:url]}" + opts[:person][:diaspora_handle] = "#{opts[:username]}@#{URI::parse(opts[:url]).host}" opts[:person][:serialized_key] = generate_key User.create!(opts) end diff --git a/config/routes.rb b/config/routes.rb index b0ce8bbdf..12dd20ba7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,6 +31,7 @@ Diaspora::Application.routes.draw do match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session" match 'signup', :to => 'registrations#new', :as => "new_user_registration" + match 'get_to_the_choppa', :to => redirect("/signup") #public routes # match 'webfinger', :to => 'publics#webfinger' diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index 91f0e0371..bea772e20 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -35,6 +35,12 @@ describe PublicsController do end end + describe 'webfinger' do + it 'should not try to webfinger out on a request to webfinger' do + Redfinger.should_not_receive :finger + post :webfinger, :q => 'remote@example.com' + end + end describe 'friend requests' do before do