Sha256: 2ae6e9ee7f540154bc911158a633c188f1d1475e99e1a0ecb675789a8557437c

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

module Socialite
  module Controllers
    module Helpers
      extend ActiveSupport::Concern

      included do
        helper_method :current_user, :user_signed_in?
      end

      def current_user
        @current_user ||= if session.has_key?(:user_id)
                            Socialite.user_class.find(session[:user_id])
                          end
      rescue ActiveRecord::RecordNotFound
        session[:user_id] = nil
      end

      def ensure_user
        if defined?(super)
          super
        else
          unless user_signed_in?
            redirect_to login_path, :alert => 'You must be logged in to use this feature.'
          end
        end
      end

      def logout!
        self.current_user = nil and session.destroy
      end

      def user_signed_in?
        !!current_user
      end

      def current_user=(user)
        @current_user = user
        session[:user_id] = user.nil? ? user : user.id
      end

      def after_link_path
        main_app.root_path
      end

      def after_signup_path
        main_app.root_path
      end

      def after_failure_path
        main_app.root_path
      end

      def after_login_path
        main_app.root_path
      end

      def after_logout_path
        main_app.root_path
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
socialite-0.1.0.pre.5 lib/socialite/controllers/helpers.rb
socialite-0.1.0.pre.4 lib/socialite/controllers/helpers.rb