2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-10-11 21:56:51 +01:00
|
|
|
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|
|
|
def open_id
|
2011-10-13 11:19:42 +01:00
|
|
|
# raise env['omniauth.auth'].inspect
|
2011-10-11 21:56:51 +01:00
|
|
|
generic
|
|
|
|
end
|
|
|
|
|
|
|
|
def passthru
|
|
|
|
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def generic
|
|
|
|
authentication = Authentication.find_or_initialize_by_provider_and_uid(env['omniauth.auth']['provider'], env['omniauth.auth']['uid'])
|
|
|
|
if authentication.new_record?
|
|
|
|
if user_signed_in? # New authentication method for current_user
|
|
|
|
authentication.user = current_user
|
|
|
|
authentication.save
|
2011-10-13 11:19:42 +01:00
|
|
|
else # Register new user from session
|
2011-12-06 19:45:25 +00:00
|
|
|
session["devise.omniauth_data"] = env["omniauth.auth"].except('extra')
|
2011-10-13 11:19:42 +01:00
|
|
|
flash[:notice] = I18n.t "devise.omniauth_callbacks.register"
|
2011-10-11 21:56:51 +01:00
|
|
|
redirect_to new_user_registration_url
|
|
|
|
end
|
|
|
|
else
|
|
|
|
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => action_name.classify
|
|
|
|
sign_in_and_redirect authentication.user, :event => :authentication
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|