Class: Users::OmniauthCallbacksController

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

Instance Method Summary collapse

Instance Method Details

#createObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/users/omniauth_callbacks_controller.rb', line 36

def create
  unless params.has_key?(:confirm)
    omniauth = request.env["omniauth.auth"]
    authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
    if authentication
      flash[:success] = "Welcome back!"
      (:user, authentication.user)
      return

    elsif user_signed_in?
      current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
      flash[:success] = "Successfully linked account.  You can now use this account to log into Gameface."
      redirect_to authentications_url and return

    else
      session[:omniauth] = omniauth.except('extra')
      redirect_to auth_confirm_path and return
    end
  else
    omniauth = session[:omniauth]
    user = User.new
    user.apply_omniauth(omniauth)
    if params.has_key?(:email)
      user.email = params[:email]
    end
    if user.save
      flash[:success] = "Welcome to Gameface!  We're excited to have you!"
      (:user, user) and return
    else
      session[:omniauth] = omniauth.except('extra')
      raise "failed to save user record"
      redirect_to auth_finalize_path and return
    end
  end
end

#googleObject



2
3
4
5
6
7
8
9
10
11
12
# File 'app/controllers/users/omniauth_callbacks_controller.rb', line 2

def google
  @user = User.find_for_open_id(request.env["omniauth.auth"], current_user)

  if @user.persisted?
    flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
     @user, :event => :authentication
  else
    session["devise.google_data"] = request.env["omniauth.auth"]
    redirect_to new_user_registration_url
  end
end

#twitterObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/users/omniauth_callbacks_controller.rb', line 24

def twitter
  @user = User.find_for_open_id(request.env["omniauth.auth"], current_user)

  if @user.persisted?
    flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Twitter"
     @user, :event => :authentication
  else
    session["devise.twitter_data"] = request.env["omniauth.auth"]
    redirect_to new_user_registration_url
  end
end

#yahooObject



13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/users/omniauth_callbacks_controller.rb', line 13

def yahoo
  @user = User.find_for_open_id(request.env["omniauth.auth"], current_user)

  if @user.persisted?
    flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Yahoo"
     @user, :event => :authentication
  else
    session["devise.yahoo_data"] = request.env["omniauth.auth"]
    redirect_to new_user_registration_url
  end
end