Class: Users::OmniauthCallbacksController

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

Instance Method Summary collapse

Instance Method Details

#failureObject


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

def failure
  puts "*******FAILURE*****"
  puts params[:message]
  puts "*******FAILURE*****"
  flash[:notice] = params[:message] # if using sinatra-flash or rack-flash
  redirect_to root_url
end

#google_appsObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/users/omniauth_callbacks_controller.rb', line 12

def google_apps
  # You need to implement the method below in your model
  @user = User.find_for_google_apps_oauth(env["omniauth.auth"].except("extra"), current_user)

  omniauth = env["omniauth.auth"]
  email = switch_west_to_sv(omniauth["info"]["email"])

  if @user
    remember_me(@user)
    flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => omniauth['provider'], :email => email
     @user, :event => :authentication
  else
    flash[:error] = "Sorry, no user with this email (#{email}) exists in the system. [email protected] was just notified of this issue."
    options = {:to => "[email protected]",
               :from => "[email protected]",
               :subject => "Login problem to on whiteboard.sv.cmu.edu for user #{email}",
               :message => "A user tried to log into the rails application. They were authenticated by google, however, their email address does not exist as a person in the system. Either 1) the person is already in the system, but there is a typo with their email address or 2)the person needs to be added to the system. <br><br>The email address is #{email}",
               :url_label => "",
               :url => "",
               :cc => "[email protected]"
    }
    GenericMailer.email(options).deliver
    session["devise.google_apps_data"] = env["omniauth.auth"]
    redirect_to root_url
  end
end

#google_oauth2Object


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
# File 'app/controllers/users/omniauth_callbacks_controller.rb', line 39

def google_oauth2
  @user = User.find_for_google_oauth2(request.env['omniauth.auth'], current_user)

  omniauth = env['omniauth.auth']
  email = switch_west_to_sv(omniauth['info']['email'])

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

    flash[:error] = "Sorry, no user with this email (#{email}) exists in the system. [email protected] was just notified of this issue."
    options = {:to => '[email protected]',
      :from => '[email protected]',
      :subject => "Login problem to on whiteboard.sv.cmu.edu for user #{email}",
      :message => "A user tried to log into the rails application. They were authenticated by google, however, their email address does not exist as a person in the system. Either 1) the person is already in the system, but there is a typo with their email address or 2)the person needs to be added to the system. <br><br>The email address is #{email}",
      :url_label => '',
      :url => '',
      :cc => '[email protected]'
    }
    GenericMailer.email(options).deliver
    session['devise.google_apps_data'] = env['omniauth.auth']
    redirect_to root_url
  end
end

#passthruObject


67
68
69
# File 'app/controllers/users/omniauth_callbacks_controller.rb', line 67

def passthru
  render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end