Module: ActiveRecord::Acts::ActsAsCentralAuthenticationUser::InstanceMethods

Defined in:
lib/central_authentication/acts_as_central_authentication_user.rb

Instance Method Summary collapse

Instance Method Details

#create_cauth_userObject



43
44
45
# File 'lib/central_authentication/acts_as_central_authentication_user.rb', line 43

def create_cauth_user
  CentralAuthentication::User.create(:email => self.email, :password => self.password, :password_expires_on => Date.today + 30.days, :persistence_token => self.persistence_token)
end

#create_or_set_cauth_userObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/central_authentication/acts_as_central_authentication_user.rb', line 55

def create_or_set_cauth_user
  cauth_user = CentralAuthentication::User.find_by_email(self.email)
  if cauth_user.nil?
    cauth_user = create_cauth_user
    self.central_auth_user_id = cauth_user.id
  else
    self.central_authentication_user = cauth_user if self.central_auth_user_id.nil?
    update_cauth_user(cauth_user)
  end
end

#persistence_tokenObject



66
67
68
69
70
# File 'lib/central_authentication/acts_as_central_authentication_user.rb', line 66

def persistence_token
  # This method returns the persistence_token from the central authentication user. If this user does not exist yet it returns a arbitrary string otherwise it fails validation.
  return Authlogic::Random.hex_token if central_authentication_user.nil?
  central_authentication_user.persistence_token
end

#persistence_token=(value) ⇒ Object



72
73
74
75
# File 'lib/central_authentication/acts_as_central_authentication_user.rb', line 72

def persistence_token=(value)
  return value if central_authentication_user.nil?
  central_authentication_user.update_attribute(persistence_token, value)
end

#persistence_token_changed?Boolean

Returns:

  • (Boolean)


77
78
79
80
# File 'lib/central_authentication/acts_as_central_authentication_user.rb', line 77

def persistence_token_changed?
  return false if central_authentication_user.nil?
  central_authentication_user.persistence_token_changed?
end

#update_cauth_user(cauth_user) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/central_authentication/acts_as_central_authentication_user.rb', line 47

def update_cauth_user(cauth_user)
  if self.password.blank?
    cauth_user.update_attributes(:email => self.email)
  else
    cauth_user.update_attributes(:password => self.password, :email => self.email)
  end
end