diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 525feb412211a22bac244f364f530bef7d830125..c836fb581fe809f0e37856c8a5f71b964dff258a 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -1,7 +1,7 @@ class Notifier < ActionMailer::Base - + default :from => APP_CONFIG[:smtp_sender_address] - + ATTACHMENT = File.read("#{Rails.root}/public/images/diaspora_white_on_grey.png") def self.admin(string, recipients, opts = {}) @@ -18,7 +18,7 @@ class Notifier < ActionMailer::Base @string = string.html_safe attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT mail(:to => @recipient.email, - :subject => I18n.t('notifier.single_admin.subject'), :host => APP_CONFIG[:terse_pod_url]) + :subject => I18n.t('notifier.single_admin.subject'), :host => APP_CONFIG[:pod_uri].host) end def new_request(recipient_id, sender_id) @@ -30,7 +30,7 @@ class Notifier < ActionMailer::Base attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT mail(:to => "\"#{@receiver.name}\" <#{@receiver.email}>", - :subject => I18n.t('notifier.new_request.subject', :from => @sender.name), :host => APP_CONFIG[:terse_pod_url]) + :subject => I18n.t('notifier.new_request.subject', :from => @sender.name), :host => APP_CONFIG[:pod_uri].host) end def request_accepted(recipient_id, sender_id, aspect_id) @@ -40,10 +40,10 @@ class Notifier < ActionMailer::Base log_mail(recipient_id, sender_id, 'request_accepted') - attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT + attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT mail(:to => "\"#{@receiver.name}\" <#{@receiver.email}>", - :subject => I18n.t('notifier.request_accepted.subject', :name => @sender.name), :host => APP_CONFIG[:terse_pod_url]) + :subject => I18n.t('notifier.request_accepted.subject', :name => @sender.name), :host => APP_CONFIG[:pod_uri].host) end private diff --git a/app/models/user.rb b/app/models/user.rb index d992fc0ebed6ff9498e2fdca9c79961493287e01..c09d9ef3b77397d844846048c4dc1cbe4d4ce7c4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -357,13 +357,13 @@ class User opts[:person][:profile] ||= Profile.new self.person = Person.new(opts[:person]) - self.person.diaspora_handle = "#{opts[:username]}@#{APP_CONFIG[:terse_pod_url]}" + self.person.diaspora_handle = "#{opts[:username]}@#{APP_CONFIG[:pod_uri].host}" self.person.url = APP_CONFIG[:pod_url] self.serialized_private_key ||= User.generate_key self.person.serialized_public_key = OpenSSL::PKey::RSA.new(self.serialized_private_key).public_key - + self end diff --git a/app/views/devise/sessions/new.haml b/app/views/devise/sessions/new.haml index 7ef5c2f10685cdf9ead715c27d793f79c1983ed7..52849eb663d6daa0efa4c99386492a6a5bd79377 100644 --- a/app/views/devise/sessions/new.haml +++ b/app/views/devise/sessions/new.haml @@ -4,7 +4,7 @@ .span-10.append-1.last .floating - %h3 + %h3 = t('.login') = form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| #user @@ -12,7 +12,7 @@ = f.label :username , t('username') = f.text_field :username %p.user_network - ="@#{APP_CONFIG[:terse_pod_url]}" + ="@#{APP_CONFIG[:pod_uri].host}/" %p = f.label :password , t('password') @@ -22,7 +22,7 @@ / = f.check_box :remember_me / = f.label :remember_me , t('.remember_me') = f.submit t('.sign_in') - + %p = render :partial => "devise/shared/links" %p @@ -39,5 +39,5 @@ %span.brandon DIASPORA* = t('.modern_browsers') = image_tag('modern_browsers.png') - + diff --git a/app/views/devise/sessions/new.mobile.haml b/app/views/devise/sessions/new.mobile.haml index 41fb9038a9624caeef5e29e44f79ed92e87cf555..486372005d71d11b11b944320032cb1fa4437806 100644 --- a/app/views/devise/sessions/new.mobile.haml +++ b/app/views/devise/sessions/new.mobile.haml @@ -11,7 +11,7 @@ = f.label :username , t('username') = f.text_field :username %p.user_network - ="@#{APP_CONFIG[:terse_pod_url]}" + ="@#{APP_CONFIG[:pod_uri].host}/" %p = f.label :password , t('password') @@ -26,4 +26,4 @@ = t('.alpha_software') %h3 - = t('.bugs_and_feedback_mobile') \ No newline at end of file + = t('.bugs_and_feedback_mobile') diff --git a/app/views/publics/host_meta.erb b/app/views/publics/host_meta.erb index 8ad35f36f89959803ba375b22bec880aff5ba9c2..e8e1d59d350c2bccc2a5635835c689b59bb141da 100644 --- a/app/views/publics/host_meta.erb +++ b/app/views/publics/host_meta.erb @@ -1,9 +1,9 @@ <?xml version='1.0' encoding='UTF-8'?> <XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0' xmlns:hm='http://host-meta.net/xrd/1.0'> - <hm:Host><%= APP_CONFIG[:terse_pod_url] %></hm:Host> + <hm:Host><%= APP_CONFIG[:pod_uri].host %></hm:Host> <Link rel='lrdd' - template='<%= APP_CONFIG[:pod_url] %>webfinger?q={uri}'> + template='<%= APP_CONFIG[:pod_uri].host %>/webfinger?q={uri}'> <Title>Resource Descriptor</Title> </Link> </XRD> diff --git a/config/initializers/_load_app_config.rb b/config/initializers/_load_app_config.rb index 33897ab69559ad7e61f2275f685c38305d889d1f..8b4eda713bf6140541c3979bc9081b59a3cf431f 100644 --- a/config/initializers/_load_app_config.rb +++ b/config/initializers/_load_app_config.rb @@ -1,6 +1,15 @@ # Copyright (c) 2010, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. +# +# Sets up APP_CONFIG. Unless stated below, each entry is a the string in +# the file app_config.yml, as applicable for current environment. +# +# Specific items +# * pod_url: As in app_config.yml, normalized with a trailing /. +# * pod_uri: An uri object derived from pod_url. + +require 'uri' def load_config_yaml filename YAML.load(File.read(filename)) @@ -20,10 +29,14 @@ else APP_CONFIG = all_envs['default'].symbolize_keys end -APP_CONFIG[:terse_pod_url] = APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '') -APP_CONFIG[:terse_pod_url].chop! if APP_CONFIG[:terse_pod_url][-1, 1] == '/' +begin + APP_CONFIG[:pod_uri] = URI.parse( APP_CONFIG[:pod_url]) +rescue + puts "WARNING: pod url " + APP_CONFIG[:pod_url] + " is not a legal URI" +end -APP_CONFIG[:pod_url].chop! if APP_CONFIG[:pod_url][-1, 1] == '/' -APP_CONFIG[:pod_url] = APP_CONFIG[:pod_url] + '/' +APP_CONFIG[:pod_url] = APP_CONFIG[:pod_uri].normalize.to_s -puts "WARNING: Please modify your app_config.yml to have a proper pod_url!" if APP_CONFIG[:terse_pod_url] == "example.org" && Rails.env != "test" +if APP_CONFIG[:pod_uri].host == "example.org" && Rails.env != "test" + puts "WARNING: Please modify your app_config.yml to have a proper pod_url!" +end diff --git a/config/initializers/mailer_config.rb b/config/initializers/mailer_config.rb index 25cd82ce51fe196d6f3c1d5b359b22ced285f43a..c91a99f3dae4543211eb367d41c50d688195b8c5 100644 --- a/config/initializers/mailer_config.rb +++ b/config/initializers/mailer_config.rb @@ -3,7 +3,7 @@ # the COPYRIGHT file. Diaspora::Application.configure do - config.action_mailer.default_url_options = {:host => APP_CONFIG[:terse_pod_url]} + config.action_mailer.default_url_options = {:host => APP_CONFIG[:pod_uri].host} unless Rails.env == 'test' || APP_CONFIG[:mailer_on] != true config.action_mailer.delivery_method = :smtp if APP_CONFIG[:smtp_authentication] == "none" diff --git a/spec/config/config_spec.rb b/spec/config/config_spec.rb index de5c1f7559256dc5cf02dc5735d555f315231867..b84758a078399fe981b46e688e8aceedf1adfe9a 100644 --- a/spec/config/config_spec.rb +++ b/spec/config/config_spec.rb @@ -12,6 +12,6 @@ describe 'making sure the config is parsed as should' do describe 'terse_pod_url' it 'should be correctly parsed' do - APP_CONFIG[:terse_pod_url].should == 'example.org' + APP_CONFIG[:pod_uri].host.should == 'example.org' end end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 841cbed70b9629fb8ab1568bcf8a4f68101726fb..9f422055a07dd023841b22a01055acca3f9f5b5d 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -38,13 +38,13 @@ describe Person do context 'local people' do it 'uses the pod config url to set the diaspora_handle' do new_user = Factory.create(:user) - new_user.person.diaspora_handle.should == new_user.username + "@" + APP_CONFIG[:terse_pod_url] + new_user.person.diaspora_handle.should == new_user.username + "@" + APP_CONFIG[:pod_uri].host end end context 'remote people' do it 'stores the diaspora_handle in the database' do - @person.diaspora_handle.include?(APP_CONFIG[:terse_pod_url]).should be false + @person.diaspora_handle.include?(APP_CONFIG[:pod_uri].host).should be false end end