Sha256: 1e8d8a8f5b0daa7362c13a5e336f59c9ce5d779409e90d495acf56f069dd42c3

Contents?: true

Size: 1.09 KB

Versions: 51

Compression:

Stored size: 1.09 KB

Contents

module Adeia
  module Helpers
    module SessionsHelper
      extend ActiveSupport::Concern

      included do
        helper_method :current_user, :signed_in?
      end

      # Sign in a user with a cookie
      # 
      # * *Args*    :
      #   - a user to sign in
      # * *Returns* :
      #
      def sign_in(user, permanent: false)
        cookies[:remember_token] = { value: user.remember_token, expires: (Time.now + 2592000 if permanent) }
        self.current_user = user
      end

      def current_user=(user)
        @current_user = user
      end

      # Provid the user currently signed in.
      # 
      # * *Returns* :
      #   - the user currently signed in
      def current_user
        @current_user ||= User.find_by_remember_token(cookies[:remember_token])
      end


      # Check if there is a user signed in.
      # 
      # * *Returns* :
      #   - boolean
      def signed_in?
        !current_user.nil?
      end

      # Sign out a user by removing the cookie.
      def sign_out
        self.current_user = nil
        cookies.delete(:remember_token)
      end

    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
adeia-0.11.0 lib/adeia/helpers/sessions_helper.rb
adeia-0.10.5 lib/adeia/helpers/sessions_helper.rb
adeia-0.10.4 lib/adeia/helpers/sessions_helper.rb
adeia-0.10.3 lib/adeia/helpers/sessions_helper.rb
adeia-0.10.2 lib/adeia/helpers/sessions_helper.rb
adeia-0.10.1 lib/adeia/helpers/sessions_helper.rb
adeia-0.10.0 lib/adeia/helpers/sessions_helper.rb
adeia-0.9.2 lib/adeia/helpers/sessions_helper.rb
adeia-0.9.1 lib/adeia/helpers/sessions_helper.rb
adeia-0.9.0 lib/adeia/helpers/sessions_helper.rb
adeia-0.8.6 lib/adeia/helpers/sessions_helper.rb
adeia-0.8.5 lib/adeia/helpers/sessions_helper.rb
adeia-0.8.4 lib/adeia/helpers/sessions_helper.rb
adeia-0.8.3 lib/adeia/helpers/sessions_helper.rb
adeia-0.8.2 lib/adeia/helpers/sessions_helper.rb
adeia-0.8.1 lib/adeia/helpers/sessions_helper.rb
adeia-0.8.0 lib/adeia/helpers/sessions_helper.rb
adeia-0.7.1 lib/adeia/helpers/sessions_helper.rb
adeia-0.7.0 lib/adeia/helpers/sessions_helper.rb
adeia-0.6.2 lib/adeia/helpers/sessions_helper.rb