ruby on rails - Integrate facebook login for already registered users -
i integrating facebook login in application using example code omniauth documentation
https://github.com/plataformatec/devise/wiki/omniauth:-overview
def self.from_omniauth(hash) where(email: hash.info.email).first_or_create |user| user.email = hash.info.email user.password = devise.friendly_token[0,20] user.username = hash.info.name # assuming user model has name end end class users::omniauthcallbackscontroller < devise::omniauthcallbackscontroller def facebook # render :text => request.env['omniauth.auth'].to_yaml # need implement method below in model (e.g. app/models/user.rb) @user = user.from_omniauth(request.env["omniauth.auth"]) if @user.persisted? sign_in_and_redirect @user, :event => :authentication #this throw if @user not activated set_flash_message(:notice, :success, :kind => "facebook") if is_navigational_format? else session["devise.facebook_data"] = request.env["omniauth.auth"] redirect_to new_user_registration_url end end end
i followed example is. code in omniauth_callbacks_controller i'd if user new application should follow else statement , redirected user registration url. happens new user created in database always. shouldn't fall in else statement in case user has no account yet in app?
according suggested implementation of method from_omniauth understand first_or_create creates new user in db using information facebook. if that's case, use of else option redirecting new_user_registration_url?
anything not seeing?
Comments
Post a Comment