Class: Users::OmniauthCallbacksController

Inherits:
Devise::OmniauthCallbacksController
  • Object
show all
Defined in:
app/controllers/users/omniauth_callbacks_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.provides_callback_for(*providers) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/users/omniauth_callbacks_controller.rb', line 3

def self.provides_callback_for(*providers)
  providers.each do |provider|
    class_eval %{
      def #{provider}
        if not current_user.blank?
          current_user.bind_service(env["omniauth.auth"])#Add an auth to existing
          redirect_to edit_user_registration_path, notice: "成功绑定了 #{provider} 帐号。"
        else
          @user = User.find_or_create_for_#{provider}(env["omniauth.auth"])

          if @user.persisted?
            flash[:notice] = "Signed in with #{provider.to_s.titleize} successfully."
            sign_in_and_redirect @user, event: :authentication, notice: "登陆成功。"
          else
            redirect_to new_user_registration_url
          end
        end
      end
    }
  end
end

Instance Method Details

#handle_unverified_requestObject

This is solution for existing accout want bind Google login but current_user is always nil github.com/intridea/omniauth/issues/185


29
30
31
# File 'app/controllers/users/omniauth_callbacks_controller.rb', line 29

def handle_unverified_request
  true
end