Module: Pasaporte::Helpers

Defined in:
lib/pasaporte.rb

Instance Method Summary collapse

Instance Method Details

#_collapse_checkbox_input(ha) ⇒ Object

Camping processes double values (hidden field with 0 and checkbox with 1) as an array. This collapses the [“0”,“1”] array to a single value of “1”



714
715
716
717
718
# File 'lib/pasaporte.rb', line 714

def _collapse_checkbox_input(ha)
  ha.each_pair do | k,v |
    (v == ["0", "1"]) ? (ha[k] = "1") : (v.is_a?(Hash) ? _collapse_checkbox_input(v) : true)
  end
end

#_csrf_tokenObject



720
721
722
723
# File 'lib/pasaporte.rb', line 720

def _csrf_token
 #input :name => :tok, :type => :hidden, :value => token_box.procure!(@env.REQUEST_URI)
 #LOGGER.warn "After token procurement #{token_box.inspect}"
end

#_todo(msg = nil) ⇒ Object



772
773
774
775
776
777
778
779
# File 'lib/pasaporte.rb', line 772

def _todo(msg=nil)
  # LOGGER.error " "
  # LOGGER.error("FIXME! - %s" % msg)
  # LOGGER.info caller[0..2].join("\n")  
  if self.respond_to?(:div) 
    div(:style=>'color:red;font-size:1.1em'){"TODO!"}
  end
end

#add_sreg(request, response) ⇒ Object

Add sreg details from the profile to the response



738
739
740
741
742
743
# File 'lib/pasaporte.rb', line 738

def add_sreg(request, response)
  when_sreg_is_required(request) do | fields, policy_url |
    addition = OpenID::SReg::Response.new(@profile.to_sreg_fields(fields))
    response.add_extension(addition)
  end
end

#is_logged_in?Boolean

Returns:

  • (Boolean)


702
703
704
# File 'lib/pasaporte.rb', line 702

def is_logged_in?
  (@state.nickname && (@state.nickname == @nickname))
end

#my_domainObject

Return a RELATIVELY reliable domain key



707
708
709
710
# File 'lib/pasaporte.rb', line 707

def my_domain
  server = env["SERVER_NAME"].gsub(/^www\./i, '')
  (server.mb_chars rescue server.chars).downcase.to_s
end

#openid_serverObject



725
726
727
728
729
730
731
732
733
734
735
# File 'lib/pasaporte.rb', line 725

def openid_server
  @store ||= PasaporteStore.new
  
  # Associations etc are sharded per domain on which Pasaporte sits
  @store.pasaporte_domain = @env['SERVER_NAME']
  
  # we also need to provide endopint URL - this is where Pasaporte is mounted.
  # Op-endpoint is the endpoint used by the server
  @server ||= OpenID::Server::Server.new(@store, _our_endpoint_uri)
  @server
end

#send_openid_response(oid_resp, keep_in_session = false) ⇒ Object

Convert from the absurd response object to something Camping can fret The second argument determines if the session needs to be cleared as well



759
760
761
762
763
764
765
766
767
768
769
770
# File 'lib/pasaporte.rb', line 759

def send_openid_response(oid_resp, keep_in_session = false)
  web_response = openid_server.encode_response(oid_resp)
  @state.delete(:pending_openid) unless keep_in_session
  case web_response.code
    when OpenID::Server::HTTP_OK
      @body = web_response.body           
    when OpenID::Server::HTTP_REDIRECT
      redirect web_response.headers['location']
    else # This is a 400 response, we do not support something
      @status, @body = 400, web_response.body
  end
end

#when_sreg_is_required(openid_request) ⇒ Object

Runs the block if the passed request contains an SReg requirement. Yields an array of fields and the policy URL



747
748
749
750
751
752
753
754
755
# File 'lib/pasaporte.rb', line 747

def when_sreg_is_required(openid_request)
  fetch_request = OpenID::SReg::Request.from_openid_request(openid_request)
  return unless fetch_request
  if block_given? && fetch_request.were_fields_requested?
    yield(fetch_request.all_requested_fields, fetch_request.policy_url)
  else
    false
  end
end