Module: Intra::Authentication

Included in:
SessionsController
Defined in:
lib/intra/authentication.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/intra/authentication.rb', line 3

def self.included(base)
  base.class_eval do
    if respond_to?(:helper_method)
      helper_method :current_user, :signed_in?, :signed_out?
    end

    private(
      :authenticate!,
      :current_user,
      :handle_unverified_request,
      :sign_in,
      :sign_out,
      :signed_in?,
      :signed_out?
    )
  end
end

Instance Method Details

#authenticate!Object



21
22
23
24
# File 'lib/intra/authentication.rb', line 21

def authenticate!
  Intra.logger.debug 'Intra::Authentication authenticate!'
  redirect_to Intra. unless signed_in?
end

#current_userObject



26
27
28
# File 'lib/intra/authentication.rb', line 26

def current_user
  intra_session&.current_user
end

#handle_unverified_requestObject



49
50
51
52
# File 'lib/intra/authentication.rb', line 49

def handle_unverified_request
  super
  sign_out
end

#intra_sessionObject



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

def intra_session
  request.env[:intra]
end

#sign_in(hash) ⇒ Object



30
31
32
33
34
# File 'lib/intra/authentication.rb', line 30

def (hash)
  Intra.logger.debug 'Intra::Authentication sign_in'
  user = Intra.user_class.constantize.authenticate(hash)
  intra_session. user
end

#sign_outObject



36
37
38
39
# File 'lib/intra/authentication.rb', line 36

def sign_out
  Intra.logger.debug 'Intra::Authentication sign_out'
  intra_session&.sign_out
end

#signed_in?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/intra/authentication.rb', line 41

def signed_in?
  intra_session&.signed_in?
end

#signed_out?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/intra/authentication.rb', line 45

def signed_out?
  intra_session&.signed_out?
end