Skip to content

Instantly share code, notes, and snippets.

@bdmac
Created June 1, 2009 20:39
Show Gist options
  • Save bdmac/121766 to your computer and use it in GitHub Desktop.
Save bdmac/121766 to your computer and use it in GitHub Desktop.
class UserSessionsController < ApplicationController
def rpx_create
RPXNow.api_key = [YOUR RPX KEY]
data = RPXNow.user_data(params[:token], :extended => 'true')
if data.blank?
@user_session = UserSession.new
flash[:error] = "Authentication failed."
respond_to do |format|
format.html { render :action => :new }
end
else
# Authentication good.. check if need to "sign up"...
primary_key = data[:id]
unless primary_key
# Need to "sign up", store the token so we can get the data again later...
session[:rpx_token] = params[:token]
redirect_to rpx_signup_path
else
# This OpenID has already "signed up" and been associated to a local user. They are already
# authenticated so just create their session for them.
@user = User.find(primary_key)
if @user
UserSession.create(@user)
respond_to do |format|
format.html { redirect_back_or_default home_path }
end
else
flash[:error] = "Unable to find the user that your third-party account maps to. Please contact support@cafecourses.com for help."
respond_to do |format|
format.html { render :action => :new }
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment