Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Supports Auto Registration of users using the auto_register method in…

… Session.

Fixes sreg support so it supports any amount of sreg fields.

Signed-off-by: Ben Johnson <bjohnson@binarylogic.com>
  • Loading branch information...
commit 23c5f5da44a04745b137451ba5bacf31c464a709 1 parent 9a95f15
@pelle pelle authored committed
View
15 lib/authlogic_openid/acts_as_authentic.rb
@@ -71,6 +71,8 @@ def openid_identifier=(value)
# if their OpenID provider supports it.
def save(perform_validation = true, &block)
return false if perform_validation && block_given? && authenticate_with_openid? && !authenticate_with_openid
+
+ return false if new_record? && !openid_complete?
result = super
yield(result) if block_given?
result
@@ -90,7 +92,7 @@ def authenticate_with_openid
options = {}
options[:required] = self.class.openid_required_fields
options[:optional] = self.class.openid_optional_fields
- options[:return_to] = session_class.controller.url_for(:for_model => "1")
+ options[:return_to] = session_class.controller.url_for(:for_model => "1",:controller=>"users",:action=>"create")

Why is :controller=>"users",:action=>"create" hardcoded?

ditto. this breaks applications that use people instead of users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
session_class.controller.send(:authenticate_with_open_id, openid_identifier, options) do |result, openid_identifier, registration|
if result.unsuccessful?
@@ -102,7 +104,6 @@ def authenticate_with_openid
return true
end
-
return false
end
@@ -112,9 +113,13 @@ def authenticate_with_openid
# Basically you will get a hash of values passed as a single argument. Then just map them as you see fit. Check out
# the source of this method for an example.
def map_openid_registration(registration) # :doc:
- self.name ||= registration[:fullname] if respond_to?(:name) && !registration[:fullname].blank?
- self.first_name ||= registration[:fullname].split(" ").first if respond_to?(:first_name) && !registration[:fullname].blank?
- self.last_name ||= registration[:fullname].split(" ").last if respond_to?(:last_name) && !registration[:last_name].blank?
+ registration.symbolize_keys!
+ [self.class.openid_required_fields+self.class.openid_optional_fields].flatten.each do |field|
+ setter="#{field.to_s}=".to_sym
+ if respond_to?(setter)
+ send setter,registration[field]
+ end
+ end
end
# This method works in conjunction with map_saved_attributes.
View
41 lib/authlogic_openid/session.rb
@@ -28,6 +28,17 @@ def find_by_openid_identifier_method(value = nil)
rw_config(:find_by_openid_identifier_method, value, :find_by_openid_identifier)
end
alias_method :find_by_openid_identifier_method=, :find_by_openid_identifier_method
+
+ # Add this in your Session object to Auto Register a new user using openid via sreg
+ def auto_register(value=true)
+ auto_register_value(value)
+ end
+
+ def auto_register_value(value=nil)
+ rw_config(:auto_register,value,false)
+ end
+
+ alias_method :auto_register=,:auto_register
end
module Methods
@@ -70,21 +81,39 @@ def authenticating_with_openid?
def find_by_openid_identifier_method
self.class.find_by_openid_identifier_method
end
+
+ def find_by_openid_identifier_method
+ self.class.find_by_openid_identifier_method
+ end
+
+ def auto_register?
+ self.class.auto_register_value
+ end
def validate_by_openid
self.remember_me = controller.params[:remember_me] == "true" if controller.params.key?(:remember_me)
+ self.attempted_record = klass.send(find_by_openid_identifier_method, openid_identifier)
+ if !attempted_record
+ if auto_register?
+ self.attempted_record = klass.new :openid_identifier=>openid_identifier
+ attempted_record.save do |result|
+ if result
+ true
+ else
+ false
+ end
+ end
+ else
+ errors.add(:openid_identifier, "did not match any users in our database, have you set up your account to use OpenID?")
+ end
+ return
+ end
controller.send(:authenticate_with_open_id, openid_identifier, :return_to => controller.url_for(:for_session => "1", :remember_me => remember_me?)) do |result, openid_identifier|
if result.unsuccessful?
errors.add_to_base(result.message)
return
end
- self.attempted_record = klass.send(find_by_openid_identifier_method, openid_identifier)
-
- if !attempted_record
- errors.add(:openid_identifier, "did not match any users in our database, have you set up your account to use OpenID?")
- return
- end
end
end
View
2  lib/authlogic_openid/version.rb
@@ -41,7 +41,7 @@ def to_a
MAJOR = 1
MINOR = 0
- TINY = 4
+ TINY = 5
# The current version as a Version instance
CURRENT = new(MAJOR, MINOR, TINY)

3 comments on commit 23c5f5d

@skrat

I'm getting validation errors, the one about password bugs me since it's not needed while using OpenID:

4 errors prohibited this user from being saved

There were problems with the following fields:

Login is too short (minimum is 3 characters)
Login should use only letters, numbers, spaces, and .-_@ please.
Password is too short (minimum is 4 characters)
Password confirmation is too short (minimum is 4 characters)

@mreinsch

Have a look at my fork (http://github.com/mreinsch/authlogic_openid/), there is an alternative implementation based on patches by gaizka and cpjolicoeur.

Regarding the login, please have a look at the readme, step 5. The password field is already handled by authlogic_openid.

@mreinsch

Have a look at my fork (http://github.com/mreinsch/authlogic_openid), I'm using an implementation based on patches by gaizka and cpjolicoeur. Regarding the login field, have a look at the readme, Step 5. The password field is already taken care of by authlogic_openid.

Please sign in to comment.
Something went wrong with that request. Please try again.