Module: Egalite::Keitai::Session
- Included in:
- Controller
- Defined in:
- lib/egalite/keitai/keitai.rb
Instance Method Summary collapse
- #do_after_filter_for_keitai(response, session) ⇒ Object
- #load_keitai_session(sessionid) ⇒ Object
- #modify_url_for_keitai(url, sstr) ⇒ Object
- #redirector_url ⇒ Object
- #replace_url_for_keitai(body, sstr) ⇒ Object
Instance Method Details
#do_after_filter_for_keitai(response, session) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/egalite/keitai/keitai.rb', line 58 def do_after_filter_for_keitai(response,session) code = response[0] headers = response[1] body = response[2].join if session and session.sstr sstr = session.sstr if headers['Location'] headers['Location'] = modify_url_for_keitai(headers['Location'],sstr) end replace_url_for_keitai(body,sstr) response[2] = [body] end response end |
#load_keitai_session(sessionid) ⇒ Object
28 29 30 |
# File 'lib/egalite/keitai/keitai.rb', line 28 def load_keitai_session(sessionid) session.load_from_param(sessionid) end |
#modify_url_for_keitai(url, sstr) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/egalite/keitai/keitai.rb', line 31 def modify_url_for_keitai(url,sstr) uri = URI.parse(URI.escape(URI.unescape(url))) return url if not uri.scheme.blank? and uri.scheme !~ /(http|https)/ if uri.host and uri.host !~ my_host crypted_url = URLSession.encrypt(url,redirector_crypt_key) File.join(redirector_url,crypted_url) else array = uri.query.to_s.split('&') qhash = array.inject({}) { |a,s| (k,v) = s.split('=',2); a[k] = v; a } qhash['sessionid']=sstr uri.query = qhash.map {|k,v| "#{k}=#{v}"}.join('&') uri.to_s end end |
#redirector_url ⇒ Object
55 56 57 |
# File 'lib/egalite/keitai/keitai.rb', line 55 def redirector_url "/redirector" end |
#replace_url_for_keitai(body, sstr) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/egalite/keitai/keitai.rb', line 45 def replace_url_for_keitai(body,sstr) body.gsub!(/<a.+?href=(?:'(.+?)'|"(.+?)").+?>/) { |s| url = ($1 || $2) url_after = modify_url_for_keitai(url,sstr) s.sub(url,url_after) } body.gsub!(/(<form.+?>)/) { |s| s + "\n<input type='hidden' name='sessionid' value='#{sstr}'/>\n" } end |