Skip to content

Instantly share code, notes, and snippets.

@EvanBurchard
Created June 22, 2011 08:46
Show Gist options
  • Save EvanBurchard/1039715 to your computer and use it in GitHub Desktop.
Save EvanBurchard/1039715 to your computer and use it in GitHub Desktop.
file above, trace below
=================================This is the file=================================
class UserSessionsController < ApplicationController
before_filter :login_required, :only => [ :destroy ]
# omniauth callback method
def create
omniauth = request.env['omniauth.auth']
user = User.find_by_uid(omniauth['uid'])
if not user
@user = User.build(:person => Person.new(:profile => Profile.new))
@user.username="lajsdfk#{rand(1000)}"
@user.email="some@emafs#{rand(1000)}djlkil.com"
@user.uid = omniauth['uid'];
@user.password = "sekrit007";
@user.password_confirmation = "sekrit007";
@user.invites = 20
if @user.save
flash[:notice] = I18n.t 'registrations.create.success'
@user.seed_aspects
sign_in_and_redirect(:user, @user)
Rails.logger.info("event=registration status=successful user=#{@user.diaspora_handle}")
else
@user.errors.delete(:person)
flash[:error] = @user.errors.full_messages.join(";")
Rails.logger.info("event=registration status=failure errors=#{@user.errors}")
Rails.logger.info("event=registration status=failure errors='#{@user.errors.full_messages.join(', ')}'")
end
# Default from oauth client code
#user = User.create!(:uid => omniauth['uid'],
#:username => "blahblah",
#:email => "[email protected]",
#:first_name => omniauth['extra']['first_name'],
#:last_name => omniauth['extra']['last_name'])
end
# Currently storing all the info
session[:user_id] = omniauth
flash[:notice] = "Successfully logged in"
redirect_to root_path
end
# Omniauth failure callback
def failure
flash[:notice] = params[:message]
redirect_to root_path
end
# logout - Clear our rack session BUT essentially redirect to the provider
# to clean up the Devise session from there too !
def destroy
session[:user_id] = nil
flash[:notice] = 'You have successfully signed out!'
redirect_to "#{CUSTOM_PROVIDER_URL}/users/sign_out"
end
end
=============================Trace starts here============================================
Started GET "/auth/josh_id/callback?code=f97cb37d46737cac58634b47c0bd2519&response_type=code" for 127.0.0.1 at 2011-06-22 04:29:16 -0400 pid=43054
Processing by UserSessionsController#create as HTML pid=43054
Parameters: {"code"=>"f97cb37d46737cac58634b47c0bd2519", "response_type"=>"code", "provider"=>"josh_id"} pid=43054
User Load (0.6ms) SELECT `users`.* FROM `users` WHERE (`users`.`uid` = '31') LIMIT 1 pid=43054
CACHE (0.0ms) SELECT `users`.* FROM `users` WHERE (`users`.`uid` = '31') LIMIT 1 pid=43054
CACHE (0.0ms) SELECT `users`.* FROM `users` WHERE (`users`.`uid` = '31') LIMIT 1 pid=43054
event=request_with_user controller=UserSessionsController action=create uid=nil pid=43054
CACHE (0.0ms) SELECT `users`.* FROM `users` WHERE (`users`.`uid` = '31') LIMIT 1 pid=43054
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE (`users`.`uid` = '34') LIMIT 1 pid=43054
SQL (1.1ms) SHOW TABLES pid=43054
WARNING: Can't mass-assign protected attributes: person pid=43054
User Load (0.5ms) SELECT `users`.`id` FROM `users` WHERE (`users`.`username` IS NULL) LIMIT 1 pid=43054
AAAAAAAAAAAAAAAAAAAAAAAAA pid=43054
provider='josh_id' uid='34' credentials='{"token"=>"6fdf11ab6d0598c93cf937085e24b0ec"}' user_info='{"name"=>"[email protected]"}' extra='{"first_name"=>nil, "last_name"=>nil}' pid=43054
BBBBBBBBBBBBBBBBBBBBBBBBB pid=43054
SQL (0.1ms) BEGIN pid=43054
User Load (0.3ms) SELECT `users`.`id` FROM `users` WHERE (LOWER(`users`.`email`) = LOWER('[email protected]')) LIMIT 1 pid=43054
User Load (0.2ms) SELECT `users`.`id` FROM `users` WHERE (`users`.`username` = BINARY 'lajsdfk910') LIMIT 1 pid=43054
SQL (0.2ms) ROLLBACK pid=43054
event=registration status=failure errors={} pid=43054
event=registration status=failure errors='' pid=43054
Redirected to http://localhost:3000/ pid=43054
Completed 302 Found in 593ms pid=43054
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment