Commit f0fb8ffd by Mykhailo Makohin

fix facebook registration

parent 257b84a6
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.from_omniauth(request.env["omniauth.auth"]) @user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted? if @user.persisted?
sign_in_and_redirect @user, event: :authentication sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format? set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format?
else else
session["devise.facebook_data"] = request.env["omniauth.auth"] session["devise.facebook_data"] = request.env["omniauth.auth"]
......
...@@ -4,6 +4,11 @@ class User < ApplicationRecord ...@@ -4,6 +4,11 @@ class User < ApplicationRecord
:recoverable, :rememberable, :omniauthable, :recoverable, :rememberable, :omniauthable,
omniauth_providers: [:facebook, :google_oauth2] omniauth_providers: [:facebook, :google_oauth2]
before_create do
self.email = 'example123@gmail.com' if email.nil?
end
validates :email, presence: false
def self.new_with_session(params, session) def self.new_with_session(params, session)
super.tap do |user| super.tap do |user|
......
...@@ -26,12 +26,7 @@ Devise.setup do |config| ...@@ -26,12 +26,7 @@ Devise.setup do |config|
config.omniauth :facebook, "2429624190692901", "03da24c1517b0bfa4acc70852f61fb60", config.omniauth :facebook, "2429624190692901", "03da24c1517b0bfa4acc70852f61fb60",
callback_url: "http://localhost:3000/users/auth/facebook/callback", callback_url: "http://localhost:3000/users/auth/facebook/callback",
scope: 'public_profile,email', scope: 'email', info_fields: 'email,name'
info_fields: 'email,first_name,last_name,gender,birthday,location,picture',
client_options: {
site: 'https://graph.facebook.com/v2.11',
authorize_url: "https://www.facebook.com/v2.11/dialog/oauth"
}
config.omniauth :google_oauth2, "444952886435-8s76oeuc53otc8q84jork9mq4php7e7t.apps.googleusercontent.com", config.omniauth :google_oauth2, "444952886435-8s76oeuc53otc8q84jork9mq4php7e7t.apps.googleusercontent.com",
"vfJkP71fOkfDKVYa3RgXR3lW", {} "vfJkP71fOkfDKVYa3RgXR3lW", {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment