Sha256: 964eec9e95f48656acf9de8de8032f1f74cf616d7fbac561ea85ceb26023be4b

Contents?: true

Size: 956 Bytes

Versions: 8

Compression:

Stored size: 956 Bytes

Contents

module ExvoAuth::Rails::ControllerHelpers
  def self.included(base)
    base.send :include, ExvoAuth::PathHelpers
    base.helper_method :current_user, :signed_in?
  end
  
  def authenticate_user!
    if !signed_in?
      store_location!

      callback_key   = ExvoAuth::Config.callback_key
      callback_value = params[callback_key]

      if request.xhr?
        redirect_to non_interactive_sign_in_path
      elsif callback_value.present?
        redirect_to non_interactive_sign_in_path(callback_key => callback_value)
      else
        redirect_to interactive_sign_in_path
      end
    end
  end
  
  def current_user
    return @current_user if defined?(@current_user)
    @current_user = session[:user_id] && User.find_by_id(session[:user_id])
  end

  def signed_in?
    !!current_user
  end
  
  def store_location!
    session[:return_to] = request.url if request.get?
  end
  
  def stored_location
    session.delete(:return_to)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
exvo-auth-0.2.1 lib/exvo_auth/rails/controller_helpers.rb
exvo-auth-0.2.0 lib/exvo_auth/rails/controller_helpers.rb
exvo-auth-0.1.7 lib/exvo_auth/rails/controller_helpers.rb
exvo-auth-0.1.6 lib/exvo_auth/rails/controller_helpers.rb
exvo-auth-0.1.5 lib/exvo_auth/rails/controller_helpers.rb
exvo-auth-0.1.4 lib/exvo_auth/rails/controller_helpers.rb
exvo-auth-0.1.3 lib/exvo_auth/rails/controller_helpers.rb
exvo-auth-0.1.2 lib/exvo_auth/rails/controller_helpers.rb