Class: Pasaporte::Models::Profile

Inherits:
Base
  • Object
show all
Defined in:
lib/pasaporte/models.rb

Overview

Minimal info we store about people. It’s the container for the sreg data in the first place.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_or_create_by_nickname_and_domain_name(nick, domain) ⇒ Object Also known as: find_or_create_by_domain_name_and_nickname

We have to override that because we want our protected attributes



160
161
162
163
164
# File 'lib/pasaporte/models.rb', line 160

def self.find_or_create_by_nickname_and_domain_name(nick, domain)
  returning(super(nick, domain)) do | me |
    ((me.nickname, me.domain_name = nick, domain) && me.save) if me.new_record?
  end
end

Instance Method Details

#delegates_openid=(nv) ⇒ Object



182
183
184
# File 'lib/pasaporte/models.rb', line 182

def delegates_openid=(nv)
  (self.openid_server, self.openid_delegate = nil, nil) if [false, '0', 0, 'no'].include?(nv) 
end

#delegates_openid?Boolean Also known as: delegates_openid

Check if this profile wants us to delegate his openid to a different identity provider. If both delegate and server are filled in properly this will return true

Returns:

  • (Boolean)


178
179
180
# File 'lib/pasaporte/models.rb', line 178

def delegates_openid?
  Pasaporte::ALLOW_DELEGATION && (!openid_server.blank? && !openid_delegate.blank?)
end

#generate_sess_keyObject



170
171
172
173
174
# File 'lib/pasaporte/models.rb', line 170

def generate_sess_key
  self.secret_salt ||= rand(Time.now)
  s = [nickname, secret_salt, Time.now.year, Time.now.month].join('|')
  OpenSSL::Digest::SHA1.new(s).hexdigest.to_s
end

#to_sObject



187
# File 'lib/pasaporte/models.rb', line 187

def to_s; nickname; end

#to_sreg_fields(fields_to_extract = nil) ⇒ Object

Convert the profile to sreg according to the spec (YYYY-MM-DD for dob and such)



151
152
153
154
155
156
157
# File 'lib/pasaporte/models.rb', line 151

def to_sreg_fields(fields_to_extract = nil)
  fields_to_extract ||= %w( nickname email fullname dob gender postcode country language timezone )
  fields_to_extract.inject({}) do | out, field |
    v = self[field]
    v.blank? ? out : (out[field.to_s] = v.to_s; out)
  end
end