diff --git a/app/models/person.rb b/app/models/person.rb index 6cc255e8b..8bd8aaa73 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -30,19 +30,11 @@ class Person before_destroy :remove_all_traces before_validation :clean_url - after_create :ensure_diaspora_handle validates_presence_of :url, :profile, :serialized_key validates_format_of :url, :with => /^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix - def ensure_diaspora_handle - if self.owner? - self.diaspora_handle = self.owner.diaspora_handle - self.save - end - end - def self.search(query) Person.all('$where' => "function() { return this.diaspora_handle.match(/^#{query}/i) || this.profile.first_name.match(/^#{query}/i) || diff --git a/app/models/user.rb b/app/models/user.rb index caf39d2f7..01c1b78f6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -22,7 +22,9 @@ class User key :pending_request_ids, Array key :visible_post_ids, Array key :visible_person_ids, Array - + + key :url, String + one :person, :class_name => 'Person', :foreign_key => :owner_id many :friends, :in => :friend_ids, :class_name => 'Person' @@ -32,7 +34,11 @@ class User many :aspects, :class_name => 'Aspect' - before_validation_on_create :setup_person + + after_create :setup_person + after_create :seed_aspects + + before_validation :do_bad_things before_save :downcase_username @@ -286,9 +292,13 @@ class User def self.instantiate!( opts = {} ) opts[:person][:diaspora_handle] = opts[:email] opts[:person][:serialized_key] = generate_key - User.create!( opts) + User.create!(opts) end - + + def self.create(opts ={}) + puts opts.inspect + end + def terse_url terse = self.url.gsub(/(https?:|www\.)\/\//, '') terse = terse.chop! if terse[-1, 1] == '/' @@ -305,7 +315,7 @@ class User def setup_person self.person.serialized_key ||= User.generate_key.export - #self.person.diaspora_handle ||= self.diaspora_handle + self.person.diaspora_handle ||= self.diaspora_handle self.person.save! end diff --git a/app/views/devise/registrations/new.html.haml b/app/views/devise/registrations/new.html.haml index 4b461fa01..212818f41 100644 --- a/app/views/devise/registrations/new.html.haml +++ b/app/views/devise/registrations/new.html.haml @@ -3,6 +3,7 @@ = form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| = devise_error_messages! + = f.hidden_field :url, :value => request.host %p = f.label :username = f.text_field :username diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 12b781b0f..715a310b9 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -26,7 +26,7 @@ describe Request do xml = request.to_xml.to_s xml.include?(@user.person.diaspora_handle).should be true - xml.include?(@user.url).should be true + xml.include?(@user.person.url).should be true xml.include?(@user.profile.first_name).should be true xml.include?(@user.profile.last_name).should be true end