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