Commit 8b7c1068044649d18ec8f10f300790a94254984b

Authored by Alexandre Barbosa
1 parent 06016c22
Exists in webfinger_server

Create federation controler

Signed-off-by: Alexandre Barbosa <alexandreab@live.com>
Signed-off-by: Victor Arnaud <victorhad@gmail.com>
app/controllers/public/federation_controller.rb 0 → 100644
@@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
  1 +class FederationController < PublicController
  2 +
  3 + def webfinger
  4 +
  5 + @people = nil
  6 + if params[:resource]
  7 + if(params[:resource].start_with?('acct:'))
  8 + result = params[:resource].match(/(?<scheme>^.*[^:]):(?<user>.*[^@])@(?<host>.*$)/i)
  9 + if result.nil?
  10 + render :nothing => true, :status => 400
  11 + return
  12 + end
  13 +
  14 + domain = result['host']
  15 +
  16 + if environment.domains.find {|x| x.name == domain}
  17 +
  18 + user = Profile[result['user']]
  19 +
  20 + if user.nil?
  21 + render :nothing => true, :status => 404
  22 + return
  23 + end
  24 + else
  25 + render :nothing => true, :status => 404
  26 + return
  27 + end
  28 +
  29 + else
  30 + render :nothing => true, :status => 400
  31 + return
  32 + end
  33 +
  34 +
  35 + resource_data = {
  36 + 'subject': params[:resource]
  37 + }
  38 +
  39 + render :json => resource_data
  40 +
  41 + #respond_to do |format|
  42 + # format.html
  43 + # format.json { render :json => @people.to_json }
  44 + #end
  45 + end
  46 + end
  47 +end
app/controllers/public/search_controller.rb
@@ -135,21 +135,6 @@ class SearchController &lt; PublicController @@ -135,21 +135,6 @@ class SearchController &lt; PublicController
135 end 135 end
136 end 136 end
137 137
138 - def webfinger  
139 -  
140 - @people = nil  
141 - if params[:resource]  
142 - @people = Profile[params[:resource]]  
143 - end  
144 -  
145 - render :json => @people.to_json  
146 -  
147 - #respond_to do |format|  
148 - # format.html  
149 - # format.json { render :json => @people.to_json }  
150 - #end  
151 - end  
152 -  
153 def tag 138 def tag
154 @tag = params[:tag] 139 @tag = params[:tag]
155 tag_str = @tag.kind_of?(Array) ? @tag.join(" ") : @tag.to_str 140 tag_str = @tag.kind_of?(Array) ? @tag.join(" ") : @tag.to_str
config/routes.rb
@@ -16,7 +16,7 @@ Noosfero::Application.routes.draw do @@ -16,7 +16,7 @@ Noosfero::Application.routes.draw do
16 ###################################################### 16 ######################################################
17 17
18 # webfinger route 18 # webfinger route
19 - match '/.well-known/webfinger', controller: 'search', action: 'webfinger', via: :all 19 + match '/.well-known/webfinger', controller: 'federation', action: 'webfinger', via: :all
20 20
21 match 'test/:controller(/:action(/:id))', controller: /.*test.*/, via: :all 21 match 'test/:controller(/:action(/:id))', controller: /.*test.*/, via: :all
22 22