Permalink
Browse files

Auto-registration is working now

Inspired by pelle's code, now auto-registration is working (at least for me).
I was not able to make pelle's code work
  • Loading branch information...
gaizka authored and mreinsch committed Nov 15, 2009
1 parent d350dce commit 65c7eff73f84c6cbf898c7f14e76f7994e07e61c
Showing with 32 additions and 4 deletions.
  1. +32 −4 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,7 +81,15 @@ 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)
@@ -87,8 +106,17 @@ def validate_by_openid
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
+ if auto_register?
+ self.attempted_record = klass.new :openid_identifier=>openid_identifier
+
+ if ! attempted_record.save
+ errors.add(:openid_identifier, "error auto-registering new openid account")
+ end
+ return
+ else
+ 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
end
@@ -98,4 +126,4 @@ def validate_openid_error
end
end
end
-end
+end

0 comments on commit 65c7eff

Please sign in to comment.