Module: Barjillo::BarjiHelpers::InstanceMethods

Defined in:
lib/barjillo/barji_helpers.rb

Instance Method Summary collapse

Instance Method Details

#authenticateObject



39
40
41
# File 'lib/barjillo/barji_helpers.rb', line 39

def authenticate
  deny_access if signed_out?
end

#current_userObject



21
22
23
# File 'lib/barjillo/barji_helpers.rb', line 21

def current_user
  @_current_user ||= user_from_cookie
end

#current_user=(user) ⇒ Object



25
26
27
# File 'lib/barjillo/barji_helpers.rb', line 25

def current_user=(user)
  @_current_user = user
end

#deny_access(flash_message = nil) ⇒ Object



62
63
64
65
66
# File 'lib/barjillo/barji_helpers.rb', line 62

def deny_access(flash_message = nil)
  store_location
  flash[:failure] = flash_message if flash_message
  redirect_to()
end

#sign_in(user) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/barjillo/barji_helpers.rb', line 44

def (user)
  if user
    cookies[:remember_token] = {
      :value   => user.remember_token,
      :expires => 1.month.from_now.utc
    }
    current_user = user
  end
end

#sign_outObject



55
56
57
58
59
# File 'lib/barjillo/barji_helpers.rb', line 55

def sign_out
  current_user.reset_remember_token! if current_user
  cookies.delete(:remember_token)
  current_user = nil
end

#signed_in?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/barjillo/barji_helpers.rb', line 30

def signed_in?
  current_user.present?
end

#signed_out?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/barjillo/barji_helpers.rb', line 35

def signed_out?
  current_user.nil?
end