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-1.0.0 lib/adeia/helpers/sessions_helper.rb
adeia-0.15.4 lib/adeia/helpers/sessions_helper.rb
adeia-0.15.3 lib/adeia/helpers/sessions_helper.rb
adeia-0.15.2 lib/adeia/helpers/sessions_helper.rb
adeia-0.15.1 lib/adeia/helpers/sessions_helper.rb
adeia-0.15.0 lib/adeia/helpers/sessions_helper.rb
adeia-0.14.0 lib/adeia/helpers/sessions_helper.rb
adeia-0.13.1 lib/adeia/helpers/sessions_helper.rb
adeia-0.13.0 lib/adeia/helpers/sessions_helper.rb
adeia-0.12.0 lib/adeia/helpers/sessions_helper.rb
adeia-0.11.11 lib/adeia/helpers/sessions_helper.rb
adeia-0.11.10 lib/adeia/helpers/sessions_helper.rb
adeia-0.11.9 lib/adeia/helpers/sessions_helper.rb
adeia-0.11.8 lib/adeia/helpers/sessions_helper.rb
adeia-0.11.7 lib/adeia/helpers/sessions_helper.rb
adeia-0.11.6 lib/adeia/helpers/sessions_helper.rb
adeia-0.11.5 lib/adeia/helpers/sessions_helper.rb
adeia-0.11.4 lib/adeia/helpers/sessions_helper.rb
adeia-0.11.3 lib/adeia/helpers/sessions_helper.rb
adeia-0.11.2 lib/adeia/helpers/sessions_helper.rb