Sha256: d3e5712cbf7fe63c478a6ce3013aba89c6f9187cc468fffaa1836788e12f6e7d

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

module Castronaut
  module Presenters

    class Logout
      attr_reader :controller, :your_mission
      attr_accessor :messages

      delegate :params, :request, :to => :controller
      delegate :cookies, :env, :to => :request

      def initialize(controller)
        @controller = controller
        @messages = []
        @your_mission = nil
      end

      def url
        params['url']
      end

      def ticket_granting_ticket_cookie
        cookies['tgt']
      end

      def client_host
        env['HTTP_X_FORWARDED_FOR'] || env['REMOTE_HOST'] || env['REMOTE_ADDR']
      end
      
      def login_ticket
        Castronaut::Models::LoginTicket.generate_from(client_host).ticket
      end

      def represent!
        ticket_granting_ticket = Castronaut::Models::TicketGrantingTicket.find_by_ticket(ticket_granting_ticket_cookie) 
        
        cookies.delete 'tgt'
        controller.delete_cookie('tgt')

        if ticket_granting_ticket
          Castronaut::Models::ProxyGrantingTicket.clean_up_proxy_granting_tickets_for(ticket_granting_ticket.identifier)
          ticket_granting_ticket.destroy
        end
        
        messages << "You have successfully logged out."
        
        @your_mission = lambda { controller.erb :logout, :locals => { :presenter => self } }
                
        self
      end
    
    end

  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
masover-castronaut-0.4.4.5 lib/castronaut/presenters/logout.rb
masover-castronaut-0.5.0.1 lib/castronaut/presenters/logout.rb