Module: OpenidRegistrable::InstanceMethods

Defined in:
lib/openid_registrable/openid_registrable.rb

Instance Method Summary collapse

Instance Method Details

#assign_openid_fields(openid_fields, ignored_fields = []) ⇒ Object

Using with open_id_authentication (github.com/Velir/open_id_authentication)

authenticate_with_open_id(@openid_identifier, :required => User.openid_required_fields, :optional => User.openid_optional_fields) do |result, identity_url, sreg_data, ax_data|

if result.successful?
  if self.current_user = User.find_by_identity_url(identity_url)
    current_user.assign_openid_fields(ax_data, [:username])

    current_user.changes.empty? ?  : (edit_user_path(:user => current_user.attributes))
  else
    self.current_user = User.new(:identity_url => identity_url)
    current_user.assign_openid_fields(ax_data)

    (registration_via_openid_path(:user => current_user.attributes))
  end
else
   result.message
end

end



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/openid_registrable/openid_registrable.rb', line 77

def assign_openid_fields(openid_fields, ignored_fields=[])
  if self.class.respond_to?(:openid_fields_to_model_fields_mapping)
    self.class.openid_fields_to_model_fields_mapping.each do |model_field, openid_field|

      if openid_fields[openid_field].kind_of?(Array)
        value = openid_fields[openid_field].first
      else
        value = openid_fields[openid_field]
      end

      if value.present? and not ignored_fields.include?(model_field)
        self.send("#{model_field}=", value)
      end
    end
  end
end