Sha256: ef502f6e438b7361b7e92b8e1ea5f554a2aec23dc5a5599e2e86999f19d339df

Contents?: true

Size: 856 Bytes

Versions: 1

Compression:

Stored size: 856 Bytes

Contents

# this concern gets put into ApplicationController

module Opro
  module Controllers
    module ApplicationControllerHelper
      extend ActiveSupport::Concern
      
      included do
        around_filter      :oauth_auth!
        skip_before_filter :verify_authenticity_token, :if => :valid_oauth?
      end

      def opro_authenticate_user!
        Opro.authenticate_user_method.call(self)
      end

      protected
      def oauth?
        params[:access_token].present?
      end

      def oauth_user
        @oauth_user ||= Oauth::AccessGrant.find_user_for_token(params[:access_token])
      end

      def valid_oauth?
        oauth? && oauth_user.present?
      end

      def oauth_auth!
        ::Opro.login(self, oauth_user)  if valid_oauth?
        yield
        ::Opro.logout(self, oauth_user) if valid_oauth?
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opro-0.0.1.pre lib/opro/controllers/application_controller_helper.rb