diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index c0be19a..8e84a00 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -1,4 +1,4 @@ class Affiliation < ActiveRecord::Base - belongs_to :user + belongs_to :person belongs_to :profile end diff --git a/app/models/user.rb b/app/models/user.rb index b3393f1..15f60c0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,12 +5,10 @@ require 'digest/sha1' class User < ActiveRecord::Base after_create do |user| - Person.create!(:identifier => user.login, :profile_owner_id => user.id, :profile_owner_type => 'User') + Person.create!(:identifier => user.login, :user_id => user.id) end - has_one :personal_profile, :class_name => 'Profile', :as => :profile_owner - has_many :affiliations - has_many :profiles, :through => :affiliations + has_one :person # Virtual attribute for the unencrypted password attr_accessor :password @@ -41,12 +39,10 @@ class User < ActiveRecord::Base self.class.encrypt(password, salt) end - # returns +true+ if the +password+ is the correct one for the user def authenticated?(password) crypted_password == encrypt(password) end - # tells if the user has an authentication cookie def remember_token? remember_token_expires_at && Time.now.utc < remember_token_expires_at end @@ -58,7 +54,6 @@ class User < ActiveRecord::Base save(false) end - # throws the auth cookie away def forget_me self.remember_token_expires_at = nil self.remember_token = nil @@ -90,9 +85,7 @@ class User < ActiveRecord::Base self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--") if new_record? self.crypted_password = encrypt(password) end - - # auxiliary method to test if a password must be supplied (i.e. returns - # +true+ when creating an user without supplying a password) + def password_required? crypted_password.blank? || !password.blank? end diff --git a/test/fixtures/profiles.yml b/test/fixtures/profiles.yml index 1e79b9e..2f573b9 100644 --- a/test/fixtures/profiles.yml +++ b/test/fixtures/profiles.yml @@ -4,8 +4,7 @@ johndoe: name: 'John Doe' identifier: johndoe virtual_community_id: 1 - profile_owner_id: 1 - profile_owner_type: 'User' + user_id: 1 flexible_template_template: 'default' flexible_template_icon_theme: 'default' flexible_template_theme: 'default' @@ -14,8 +13,7 @@ joerandomhacker: name: 'Joe Random Hacker' identifier: joerandomhacker virtual_community_id: 1 - profile_owner_id: 2 - profile_owner_type: 'User' + user_id: 2 flexible_template_template: 'simple' flexible_template_icon_theme: 'simple' flexible_template_theme: 'simple' -- libgit2 0.21.2