1 | # Copyright (c) 2010-2011, Diaspora Inc. This file is |
---|
2 | # licensed under the Affero General Public License version 3 or later. See |
---|
3 | # the COPYRIGHT file. |
---|
4 | |
---|
5 | class PublicsController < ApplicationController |
---|
6 | include Diaspora::Parser |
---|
7 | |
---|
8 | skip_before_action :set_header_data |
---|
9 | skip_before_action :set_grammatical_gender |
---|
10 | before_action :check_for_xml, :only => [:receive, :receive_public] |
---|
11 | before_action :authenticate_user!, :only => [:index] |
---|
12 | |
---|
13 | respond_to :html |
---|
14 | respond_to :xml, :only => :post |
---|
15 | |
---|
16 | caches_page :host_meta, :if => Proc.new{ Rails.env == 'production'} |
---|
17 | |
---|
18 | layout false |
---|
19 | |
---|
20 | def hcard |
---|
21 | @person = Person.find_by_guid_and_closed_account(params[:guid], false) |
---|
22 | |
---|
23 | if @person.present? && @person.local? |
---|
24 | render 'publics/hcard' |
---|
25 | else |
---|
26 | render :nothing => true, :status => 404 |
---|
27 | end |
---|
28 | end |
---|
29 | |
---|
30 | def host_meta |
---|
31 | render 'host_meta', :content_type => 'application/xrd+xml' |
---|
32 | end |
---|
33 | |
---|
34 | def webfinger |
---|
35 | @person = Person.local_by_account_identifier(params[:q]) if params[:q] |
---|
36 | |
---|
37 | if @person.nil? || @person.closed_account? |
---|
38 | render :nothing => true, :status => 404 |
---|
39 | return |
---|
40 | end |
---|
41 | |
---|
42 | FEDERATION_LOGGER.info("webfinger profile request for :#{@person.id}") |
---|
43 | render 'webfinger', :content_type => 'application/xrd+xml' |
---|
44 | end |
---|
45 | |
---|
46 | def hub |
---|
47 | render :text => params['hub.challenge'], :status => 202, :layout => false |
---|
48 | end |
---|
49 | |
---|
50 | def receive_public |
---|
51 | FEDERATION_LOGGER.info("recieved a public message") |
---|
52 | Workers::ReceiveUnencryptedSalmon.perform_async(CGI::unescape(params[:xml])) |
---|
53 | render :nothing => true, :status => :ok |
---|
54 | end |
---|
55 | |
---|
56 | def receive |
---|
57 | person = Person.find_by_guid(params[:guid]) |
---|
58 | |
---|
59 | if person.nil? || person.owner_id.nil? |
---|
60 | Rails.logger.error("Received post for nonexistent person #{params[:guid]}") |
---|
61 | render :nothing => true, :status => 404 |
---|
62 | return |
---|
63 | end |
---|
64 | |
---|
65 | @user = person.owner |
---|
66 | |
---|
67 | FEDERATION_LOGGER.info("recieved a private message for user:#{@user.id}") |
---|
68 | Workers::ReceiveEncryptedSalmon.perform_async(@user.id, CGI::unescape(params[:xml])) |
---|
69 | |
---|
70 | render :nothing => true, :status => 202 |
---|
71 | end |
---|
72 | |
---|
73 | private |
---|
74 | |
---|
75 | def check_for_xml |
---|
76 | if params[:xml].nil? |
---|
77 | render :nothing => true, :status => 422 |
---|
78 | return |
---|
79 | end |
---|
80 | end |
---|
81 | end |
---|