2015-10-16 7 views
4

Вот мой контроллерRails, как создать Authlogic сессию OmniAuth Facebook

def social_login 
    user = User.from_omniauth(env["omniauth.auth"]) 
    session_params = user.attributes.merge("email" => user.email, "password" => user.crypted_password) 
    @user_session ||= UserSession.new(session_params, true) 
    if @user_session.save 
     user = User.where(email: @user_session.email).first 
     redirect_to root_path, :notice => "Signed in succesfully from #{env["omniauth.auth"].provider.titleize}. Greetings #{user.name.titleize} ;)"  
    else 
     flash.now[:alert] = "Sign in failed." 
     render "new" 
    end 
end 

вот модель для обработки OmniAuth процесса

def self.from_omniauth(auth) 
    where(provider: auth.provider, uid: auth.uid).first_or_create do |user| 
     user.provider = auth.provider 
     user.uid = auth.uid 
     user.name = auth.info.name 
     user.email = auth.info.email 
     user.password = auth.credentials.token 
     user.password_confirmation = auth.credentials.token 
     user.oauth_token = auth.credentials.token 
     user.oauth_expires_at = Time.at(auth.credentials.expires_at) 
     user.save! 
    end 
    end 

Я всегда получаю сообщение об ошибке при попытке сохранить сеанс. В нем говорится:

Authlogic::Session::Existence::SessionInvalidError: Your session is invalid and has the following errors: Email is not valid 

Помогите мне, ребята? спасибо

ответ

0

Включили ли вы разрешение электронной почты в своей настройке config/rails в facebook app?

Как это:

config.omniauth :facebook, "APP_ID", "APP_SECRET", {:scope => 'email,...'} 
Смежные вопросы