Created
May 27, 2009 12:19
-
-
Save czottmann/118618 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserSessionsController < ApplicationController | |
# ... | |
def rpx_token | |
data = RPXNow.user_data( params[:token], RPX_API_KEY ) | |
if data.blank? | |
flash[:error] = I18n.t("auth.failed") | |
redirect_to(new_user_session_path) | |
else | |
session = UserSession.find | |
# Fresh log in | |
if session.blank? | |
rpx_mapping_id = data[:id] unless data[:id] == "0" | |
@user = User.find_or_initialize_by_id( rpx_mapping_id ) | |
if @user.new_record? | |
@user.name = data[:name] || data[:displayName] || data[:nickName] | |
@user.rpx = true | |
@user.save! | |
end | |
RPXNow.map( data[:identifier], @user.id, RPX_API_KEY ) | |
session = UserSession.new(@user) | |
session.save | |
flash[:notice] = I18n.t("auth.logged_in") | |
redirect_to( user_path(session.user) ) | |
# User already logged in | |
else | |
user = session.user | |
RPXNow.map( data[:identifier], user.id, RPX_API_KEY ) | |
user.rpx = true | |
user.save | |
flash[:notice] = I18n.t("auth.rpx_mapped") | |
redirect_to( edit_user_path(session.user) ) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment