Module: ActiveAuthentication::Controller::Authenticatable

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_authentication/controller/authenticatable.rb

Instance Method Summary collapse

Instance Method Details

#active_authentication_controller?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/active_authentication/controller/authenticatable.rb', line 11

def active_authentication_controller?
  is_a? ::ActiveAuthenticationController
end

#authenticate_user!Object



15
16
17
# File 'lib/active_authentication/controller/authenticatable.rb', line 15

def authenticate_user!
  redirect_to new_session_path, alert: t("active_authentication.failure.unauthenticated") unless user_signed_in?
end

#current_userObject



19
20
21
# File 'lib/active_authentication/controller/authenticatable.rb', line 19

def current_user
  Current.user ||= user_from_session
end

#require_no_authenticationObject



23
24
25
# File 'lib/active_authentication/controller/authenticatable.rb', line 23

def require_no_authentication
  redirect_to root_path, alert: t("active_authentication.failure.already_signed_in") if user_signed_in?
end

#sign_in(user) ⇒ Object



27
28
29
30
31
# File 'lib/active_authentication/controller/authenticatable.rb', line 27

def (user)
  reset_session
  Current.user = user
  session[:user_id] = user.id
end

#sign_outObject



33
34
35
36
# File 'lib/active_authentication/controller/authenticatable.rb', line 33

def sign_out
  reset_session
  Current.user = nil
end

#user_signed_in?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/active_authentication/controller/authenticatable.rb', line 38

def user_signed_in?
  current_user.present?
end