Permalink
Browse files

User is auto-created if the openid profile includes an email in the s…

…reg params.
  • Loading branch information...
schof committed Nov 10, 2008
1 parent 5b1fe7d commit 4ec82b7d5a4ca8514fa9224d55edd996c1fabf25
Showing with 10 additions and 2 deletions.
  1. +5 −2 app/controllers/account_controller.rb
  2. +5 −0 open_id_extension.rb
@@ -59,16 +59,19 @@ def open_id_authentication
if current_user = User.find_by_identity_url(identity_url)
session[:user_id] = current_user.id
else
- session[:openid_url] = identity_url
begin
email = registration["email"]
# check if a user ewith this email already exists
user = User.find_by_email(registration["email"])
if user
# user will need to authenticate first, then they associate this user with their account
+ session[:openid_url] = identity_url
redirect_to edit_user_url(user) and return
+ else
+ # no user but they did provide an email so we can create an account for them
+ user = User.create(:email => email, :identity_url => identity_url)
+ session[:user_id] = user.id
end
- # create a new user with this email
rescue
# do nothing - most likely user has no email in the profile or just not to send us one
end
View
@@ -21,6 +21,11 @@ def activate
# Add identity_url attribute to the user model
User.class_eval do
attr_accessible :identity_url
+ protected
+ def password_required?
+ return false if identity_url
+ crypted_password.blank? || !password.blank?
+ end
end
# Add a partial for adding the identity_url field to the user form

0 comments on commit 4ec82b7

Please sign in to comment.