Skip to content

Instantly share code, notes, and snippets.

@venetanji
Created July 29, 2011 11:08
Show Gist options
  • Save venetanji/1113624 to your computer and use it in GitHub Desktop.
Save venetanji/1113624 to your computer and use it in GitHub Desktop.
def set_current_user
if @signed_request
if @signed_request['user_id']
@current_user = User.find_or_initialize_by(id: @signed_request['user_id'])
@current_user.token = @signed_request['oauth_token']
if @current_user.new_record?
@current_user.beard ||= Beard.new
@current_user.fetch_info
end
@current_user.save
session[:user_id] = @signed_request['user_id']
else
@redirect = oauth.url_for_oauth_code
render :template => "shared/redirect", :layout => nil
end
elsif oauth.get_user_info_from_cookies(cookies)
uid = oauth.get_user_info_from_cookies(cookies)['uid']
session[:user_id] = uid
@current_user = User.find_or_initialize_by(id: uid)
if @current_user.new_record?
@current_user.beard ||= Beard.new
@current_user.save
end
elsif session[:user_id]
session[:user_id] = session[:user_id]
@current_user = User.find_or_initialize_by(id: session[:user_id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment