Skip to content

Instantly share code, notes, and snippets.

@bdmac
Created June 1, 2009 20:41
Show Gist options
  • Save bdmac/121770 to your computer and use it in GitHub Desktop.
Save bdmac/121770 to your computer and use it in GitHub Desktop.
def rpx_new
# Token should be in the session from UserSessionsController.rpx_create...
data = RPXNow.user_data(session[:rpx_token], :extended => 'true')
if data.blank?
flash[:error] = "Unable to retrieve data from your third-party account. Please try again."
redirect_to login_path
else
identifier = data[:identifier]
session[:rpx_identifier] = identifier
name = params[:name] || data[:name] || data[:displayName] || data[:nickName]
email = params[:email] || data[:verifiedEmail] || data[:email]
login = params[:preferredUsername]
@user = User.new
@user.name = name
@user.email = email
existing_user = User.find_by_email(email) || (User.find_by_login(login) unless login.blank?)
if existing_user
# Handle associating an existing account found by email or login to an OpenID.
@login = existing_user.nil? ? login : existing_user.login
@user_session = UserSession.new(:login => @login)
@show_openid_association = true
if existing_user.login == login
@association_message = "We found an existing account that is already using the username '#{login}'."
else
@association_message = "We found an existing account that is already using the email address '#{email}'."
end
#flash[:notice] = "An account with that email address or username already exists. We are working on allowing you to associate your third-party account to the existing CaféCourses account. For now, please login with your existing account."
#redirect_to login_path
end
respond_to do |format|
format.html { render :layout => 'no_sidebar' }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment