Module: CASino::SessionsHelper

Constant Summary

Constants included from ServiceTicketProcessor

CASino::ServiceTicketProcessor::RESERVED_CAS_PARAMETER_KEYS

Instance Method Summary collapse

Methods included from ServiceTicketProcessor

#acquire_service_ticket, #clean_service_url, #service_allowed?, #ticket_valid_for_service?, #validate_ticket_for_service

Methods included from TicketGrantingTicketProcessor

#acquire_ticket_granting_ticket, #cleanup_expired_ticket_granting_tickets, #find_valid_ticket_granting_ticket, #load_or_initialize_user, #remove_ticket_granting_ticket

Methods included from BrowserProcessor

#browser_info, #same_browser?

Instance Method Details

#create_login_attempt(user, successful) ⇒ Object


60
61
62
63
64
# File 'app/helpers/casino/sessions_helper.rb', line 60

def (user, successful)
  user..create! successful: successful,
                              user_ip: request.ip,
                              user_agent: request.user_agent
end

#current_ticket_granting_ticketObject


11
12
13
14
15
16
17
18
# File 'app/helpers/casino/sessions_helper.rb', line 11

def current_ticket_granting_ticket
  return nil unless cookies[:tgt]
  return @current_ticket_granting_ticket unless @current_ticket_granting_ticket.nil?
  find_valid_ticket_granting_ticket(cookies[:tgt], request.user_agent).tap do |tgt|
    cookies.delete :tgt if tgt.nil?
    @current_ticket_granting_ticket = tgt
  end
end

#current_ticket_granting_ticket?(ticket_granting_ticket) ⇒ Boolean

Returns:

  • (Boolean)

7
8
9
# File 'app/helpers/casino/sessions_helper.rb', line 7

def current_ticket_granting_ticket?(ticket_granting_ticket)
  ticket_granting_ticket.ticket == cookies[:tgt]
end

#current_userObject


20
21
22
23
24
# File 'app/helpers/casino/sessions_helper.rb', line 20

def current_user
  tgt = current_ticket_granting_ticket
  return nil if tgt.nil?
  tgt.user
end

#ensure_signed_inObject


26
27
28
# File 'app/helpers/casino/sessions_helper.rb', line 26

def ensure_signed_in
  redirect_to  unless signed_in?
end

#log_failed_login(username) ⇒ Object


54
55
56
57
58
# File 'app/helpers/casino/sessions_helper.rb', line 54

def (username)
  CASino::User.where(username: username).each do |user|
    (user, false)
  end
end

41
42
43
44
45
46
47
# File 'app/helpers/casino/sessions_helper.rb', line 41

def set_tgt_cookie(tgt)
  cookies[:tgt] = { value: tgt.ticket }.tap do |cookie|
    if tgt.long_term?
      cookie[:expires] = CASino.config.ticket_granting_ticket[:lifetime_long_term].seconds.from_now
    end
  end
end

#sign_in(authentication_result, options = {}) ⇒ Object


34
35
36
37
38
39
# File 'app/helpers/casino/sessions_helper.rb', line 34

def (authentication_result, options = {})
  tgt = acquire_ticket_granting_ticket(authentication_result, request.user_agent, request.remote_ip, options)
  (tgt.user, true)
  set_tgt_cookie(tgt)
  handle_signed_in(tgt, options)
end

#sign_outObject


49
50
51
52
# File 'app/helpers/casino/sessions_helper.rb', line 49

def sign_out
  remove_ticket_granting_ticket(cookies[:tgt], request.user_agent)
  cookies.delete :tgt
end

#signed_in?Boolean

Returns:

  • (Boolean)

30
31
32
# File 'app/helpers/casino/sessions_helper.rb', line 30

def signed_in?
  !current_ticket_granting_ticket.nil?
end