Sha256: 77678b9007e33842bf9397ff825e89515f5f220dc985d2fc93e25181d59fa9ea

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

# The filters added to this controller will be run for all controllers in the application.
# Likewese will all the methods added be available for all controllers.

require 'login_engine'
require 'term/ansicolor'

class ApplicationController < ActionController::Base
	include LoginEngine
	include Term::ANSIColor
	model :user

  before_filter :set_charset
  before_filter :set_login_from_cookie
	after_filter :fix_unicode_for_safari
	after_filter OutputCompressionFilter

	# automatically and transparently fixes utf-8 bug 
	# with Safari when using xmlhttp
	def fix_unicode_for_safari 
		if @headers["Content-Type"] == "text/html; charset=utf-8" and
			@request.env['HTTP_USER_AGENT'].to_s.include? 'AppleWebKit' then
			@response.body = @response.body.gsub(/([^\x00-\xa0])/u) { |s| "&#x%x;" % $1.unpack('U')[0] }
		end
	end

	def set_charset
		#@headers["Content-Type"] = "text/html; charset=iso-8859-15" 
		@headers["Content-Type"] = "text/html; charset=utf-8" 
	end

	def set_login_from_cookie
		unless session[:person]
			if (person = Person.find_by_name(cookies[:person_name])) and \
				((!person.user and !cookies[:salted_password]) \
				 or (person.user \
						 and person.user.salted_password == cookies[:salted_password]))
				logger.info yellow { bold { "#{person.name} is back" } }
				session[:person] = person 
				session[:user] = person.user
			end
		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
parlement-0.10 app/controllers/application.rb