use google user avatar as profile phone

This commit is contained in:
João Geonizeli
2022-07-22 12:53:57 -03:00
parent 20781746e6
commit 9db59c071f
18 changed files with 72 additions and 252 deletions

View File

@@ -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