use google user avatar as profile phone
This commit is contained in:
@@ -2,15 +2,20 @@ module Users
|
||||
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||
def google_oauth2
|
||||
# You need to implement the method below in your model (e.g. app/models/user.rb)
|
||||
@user = User.find_by!(email: request.env['omniauth.auth'].info['email'])
|
||||
@user = User.from_omniauth(
|
||||
request.env['omniauth.auth'].info['email'],
|
||||
request.env['omniauth.auth'].info['image']
|
||||
)
|
||||
|
||||
flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'Google'
|
||||
sign_in_and_redirect @user, event: :authentication
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
# Removing extra as it can overflow some session stores
|
||||
session['devise.google_data'] = request.env['omniauth.auth'].except('extra')
|
||||
if @user
|
||||
flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'Google'
|
||||
|
||||
redirect_to new_user_registration_url, alert: e.message
|
||||
sign_in_and_redirect @user, event: :authentication
|
||||
else
|
||||
session['devise.google_data'] = request.env['omniauth.auth'].except('extra')
|
||||
|
||||
redirect_to new_user_registration_url, alert: 'User not found.'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user