Skip to content

Commit

Permalink
Added oauth2 routes
Browse files Browse the repository at this point in the history
  • Loading branch information
kisonecat committed Feb 8, 2016
1 parent 3e5dd5c commit f684445
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ def coursera
end
end

def google_oauth2
@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"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.google_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end

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

Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable
devise :omniauthable
devise :authentication_keys => [:coursera_id]
devise :omniauth_providers => [:google_oauth2]

# Coursera doesn't provide us with an email address
def email_required?
Expand Down

0 comments on commit f684445

Please sign in to comment.