1 class UserSessionsController < ApplicationController
2 before_filter :login_required, :only => [ :destroy ]
4 skip_before_filter :uncamelcase_params_hash_keys
5 skip_before_filter :find_object_by_uuid
6 skip_before_filter :authenticate_api_token
10 # omniauth callback method
12 omniauth = env['omniauth.auth']
13 #logger.debug "+++ #{omniauth}"
15 identity_url_ok = (omniauth['info']['identity_url'].length > 0) rescue false
16 unless identity_url_ok
17 # Whoa. This should never happen.
19 @title = "UserSessionsController.create: omniauth object missing/invalid"
20 @body = "omniauth.pretty_inspect():\n\n#{omniauth.pretty_inspect()}"
22 view_context.fatal_error(@title,@body)
23 return redirect_to openid_login_error_url
26 user = User.find_by_identity_url(omniauth['info']['identity_url'])
28 # New user registration
29 user = User.create!(:email => omniauth['info']['email'],
30 :first_name => omniauth['info']['first_name'],
31 :last_name => omniauth['info']['last_name'],
32 :identity_url => omniauth['info']['identity_url'])
34 user.email = omniauth['info']['email']
35 user.first_name = omniauth['info']['first_name']
36 user.last_name = omniauth['info']['last_name']
40 omniauth.delete('extra')
42 session[:user_id] = user.id
44 @redirect_to = root_path
45 if session.has_key?('redirect_to') then
46 @redirect_to = session[:redirect_to]
47 session.delete(:redirect_to)
49 redirect_to @redirect_to
52 # Omniauth failure callback
54 flash[:notice] = params[:message]
57 # logout - Clear our rack session BUT essentially redirect to the provider
58 # to clean up the Devise session from there too !
60 session[:user_id] = nil
62 flash[:notice] = 'You have logged off'
63 redirect_to "#{CUSTOM_PROVIDER_URL}/users/sign_out?redirect_uri=#{root_url}"
66 # login - Just bounce to /auth/joshid. The only purpose of this function is
67 # to save the redirect_to parameter (if it exists; see the application
68 # controller). /auth/joshid bypasses the application controller.
70 redirect_to "/auth/joshid"