Skip to content

Instantly share code, notes, and snippets.

@rubenfonseca
Created June 16, 2009 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubenfonseca/130921 to your computer and use it in GitHub Desktop.
Save rubenfonseca/130921 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
acts_as_authentic do |c|
c.validate_login_field = false
# optional, but if a user registers by openid, he should at least share his email-address with the app
c.validate_email_field = false
# fetch email by ax
c.openid_required_fields = [:email, "http://axschema.org/contact/email"]
# fetch email by sreg
c.openid_optional_fields = ["email"]
end
def self.find_by_openid_identifier(identifier)
u = User.first(:conditions => { :openid_identifier => identifier })
u ||= User.create(:openid_identifier => identifier)
u
end
private
def map_openid_registration(registration)
if registration.empty?
# no email returned
self.email_autoset = false
else
# email by sreg
unless registration["email"].nil? && registration["email"].blank?
self.email = registration["email"]
self.email_autoset = true
else
# email by ax
unless registration['http://axschema.org/contact/email'].nil? && registration['http://axschema.org/contact/email'].first.blank?
self.email = registration['http://axschema.org/contact/email'].first
self.email_autoset = true
else
# registration-hash seems to contain information other than the email-address
self.email_autoset = false
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment