0

我正在开发一个应用程序,该应用程序允许您通过 Facebook 进行身份验证以注册和登录该应用程序。由于某种原因,在使用多个测功机时,会话管理似乎没有被继承。

我可以看到我的日志让用户登录,但是当用户被重定向时,应用程序会出于某种原因将用户注销

这是我的授权控制器:

class AuthorizationsController < ApplicationController
  skip_before_filter :redirect_to_signed_in_path, :prepare_for_mobile, :redirect_to_https, :force_www!

  def create
    authentication = Authorization.find_by_provider_and_uid(auth['provider'], auth['uid'])

    if authentication
      flash[:notice] = "Signed In Successfully"
      sign_in authentication.user, event: :authentication
      redirect_to root_path
    elsif user_signed_in?
      current_user.apply_omniauth(auth)

      if current_user.save
        current_user.update_attribute(:"allow_#{auth['provider']}_sync", true)
        PullSocialActionsWorker.perform_async(current_user.id, auth["provider"])
        redirect_to edit_social_profile_path, flash: { error: "#{auth["provider"]} Integration is processing" }
      else
        redirect_to edit_social_profile_path, flash: { error: "An error has occurred. Please try again." }
      end

    else
      password = Devise.friendly_token[0,20]
      athlete = Athlete.new(email: generate_auth_email(params[:provider]), password: password, password_confirmation: password )
      athlete.apply_omniauth(auth)

      begin
        athlete.subscriptions.build(trial_expiry: DateTime.now + 30, active: true, account_type_id: AccountType.free.id)
        if athlete.save(validate: false)
          sign_in athlete, event: :authentication
          redirect_to root_path, notice: "Account created and signed in successfully"
        else
          redirect_to root_path, flash: { error: "An error has occurred. Please try again." }
        end
      rescue ActiveRecord::RecordNotUnique
        redirect_to root_path, flash: { error: "The email address you are trying to connect already exists. Perhaps you #{ActionController::Base.helpers.link_to "Forgot Your Password?", new_user_password_path}".html_safe }
      end
    end
  end

  def failure
    redirect_to root_url, notice: "An Error has occurred. Please try again!"
  end

  private

    def auth
      request.env["omniauth.auth"]
    end

    def generate_auth_email(provider)
      if provider == "twitter"
        "#{auth.uid}@twitter.com"
      else
        auth.info.try(:email)
      end
    end

end

宝石文件:

gem 'omniauth'
gem 'omniauth-facebook', '1.4.0'

我也在使用 Memcache/Dalli 进行缓存...

gem 'memcachier'
gem 'dalli'

其他人之前遇到过这个问题吗?

4

0 回答 0