Module: BlueLightSpecial::Authentication::InstanceMethods

Defined in:
lib/blue_light_special/authentication.rb

Instance Method Summary collapse

Instance Method Details

#authenticateObject

Deny the user access if they are signed out.

Examples:

before_filter :authenticate


54
55
56
# File 'lib/blue_light_special/authentication.rb', line 54

def authenticate
  deny_access unless signed_in?
end

#current_userUser?

User in the current cookie

Returns:



25
26
27
# File 'lib/blue_light_special/authentication.rb', line 25

def current_user
  @_current_user ||= user_from_cookie
end

#current_user=(user) ⇒ Object

Set the current user

Parameters:



32
33
34
# File 'lib/blue_light_special/authentication.rb', line 32

def current_user=(user)
  @_current_user = user
end

#deny_access(flash_message = nil) ⇒ Object

Store the current location and redirect to sign in. Display a failure flash message if included.

Parameters:

  • optional (String)

    flash message to display to denied user



88
89
90
91
92
# File 'lib/blue_light_special/authentication.rb', line 88

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

#impersonating?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/blue_light_special/authentication.rb', line 94

def impersonating?
  !session[:admin_user_id].blank?
end

#sign_in(user) ⇒ Object

Sign user in to cookie.

Examples:

(@user)

Parameters:



64
65
66
67
68
69
70
71
72
# File 'lib/blue_light_special/authentication.rb', line 64

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

#sign_outObject

Sign user out of cookie.

Examples:

sign_out


78
79
80
81
82
# File 'lib/blue_light_special/authentication.rb', line 78

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

#signed_in?true, false

Is the current user signed in?

Returns:

  • (true, false)


39
40
41
# File 'lib/blue_light_special/authentication.rb', line 39

def signed_in?
  ! current_user.nil?
end

#signed_out?true, false

Is the current user signed out?

Returns:

  • (true, false)


46
47
48
# File 'lib/blue_light_special/authentication.rb', line 46

def signed_out?
  current_user.nil?
end