Last active
August 29, 2015 14:17
-
-
Save paulghaddad/dcb5ae0ea45fcf1fab6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cnuapp-cnu_content-lib-ruby-cnu/content-action_controller | |
def locale | |
request_uri unless @locale | |
@locale | |
end | |
def locale_cd | |
locale.locale_cd | |
end | |
def lang_cd | |
locale.language_cd | |
end | |
def country_cd | |
locale.country_cd | |
end | |
# Attempt to match /#{lang_cd} for non-en languages at beginning of URI. | |
# Initialize CnuLocale and lang_cd. | |
# | |
def request_uri_with_cnu_content | |
# Cache: | |
return @request_uri_with_cnu_content if @request_uri_with_cnu_content | |
uri = orig_uri = request_uri_without_cnu_content | |
unless (langs = brand.non_default_languages).empty? | |
orig_uri = orig_uri.dup | |
if uri.sub!(/^\/(#{langs.join('|')})(\/|$)/, '/') | |
lang_cd = $1 | |
end | |
end | |
# Default lang_cd to Cnu::Brand default. | |
lang_cd ||= brand.language | |
# Default country_cd to Cnu::Brand default. | |
country_cd = brand.country_cd | |
locale_cd = "#{lang_cd}_#{country_cd}" | |
@locale = CnuLocale[locale_cd] | |
# $stderr.puts "\nrequest_uri_with_locale: #{self.object_id} locale = #{@locale.locale_cd.inspect} orig uri=#{orig_uri.inspect} uri=#{uri.inspect}" | |
# $stderr.puts "caller =\n #{caller.join("\n ")}" | |
@request_uri_with_cnu_content = uri # cache | |
uri | |
end | |
end # module | |
module Base | |
def self.included base | |
super | |
# $stderr.puts "#{self} included by #{base}" | |
# $stderr.puts " #{base.included_modules.inspect}" | |
require 'cnu/content' | |
base.class_eval do | |
unless self.instance_methods.include?("process_without_cnu_content") | |
alias :process_without_cnu_content :process | |
alias :process :process_with_cnu_content | |
end | |
end | |
end | |
# Sets the Content selector during processing of the request: | |
# | |
# brand | |
# country | |
# language | |
# | |
# Sets the locale during processing of the request: | |
# | |
# locale | |
# lang_cd | |
# country_cd | |
# | |
# Wraps the method invocation while making | |
# CnuLocale.current = request.locale. | |
# | |
# This will prevent CnuLocale.current from getting stuck | |
# the locale stuck during this and subsequent threads. | |
# | |
# Unfortunately this is a copy-and-paste from | |
# because Rails ActionController::Base#process | |
# does not provide | |
# a hook around "send(method, *arguments)" inside | |
# ActionController::Base#process. | |
def process_with_cnu_content(request, response, method = :perform_action, *arguments) #:nodoc: | |
initialize_template_class(response) | |
assign_shortcuts(request, response) | |
initialize_current_url | |
before_process_with_locale | |
before_process_with_cnu_content | |
with_locale do | |
assign_names | |
forget_variables_added_to_assigns | |
log_processing | |
send(method, *arguments) | |
assign_default_content_type_and_charset | |
end | |
response | |
ensure | |
with_locale do | |
process_cleanup | |
end | |
end | |
def with_locale request = nil | |
request ||= self.request || raise("no request") | |
locale = request.locale | |
locale.as_current do | |
Cnu::Content::Selector. | |
with(:brand => brand.code, | |
:country => locale.country.code, | |
:language => locale.language.code) do | |
yield | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update_customer_attributes | |
@customer.reload | |
person = @customer.person | |
if person.language_cd != LsUtil.lang_cd | |
begin | |
person.update_attribute :language_cd, LsUtil.lang_cd | |
rescue ActiveRecord::StaleObjectError | |
person.reload | |
person.update_attribute :language_cd, LsUtil.lang_cd | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CHECK LANGUAGE - session[:just_logged]: nil # This is not nil on Reg 1 though |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cnuapp-cnuapp-rub-web-FrontEnd-app-controllers-frontend_controller | |
def check_language | |
# TODO: login check really should happen elsewhere | |
if session[:just_logged] | |
session[:just_logged] = nil | |
if session[:customer] && session[:customer].person && session[:customer].person.language_cd != @language_cd | |
#redirect customer to proper location just he/she logged in | |
redirect_to generate_diff_lang_url(session[:customer].person.language_cd) | |
end | |
end | |
@language_cd = RequestHelper.language_cd(:request => request, | |
:person => session[:customer] && session[:customer].person) | |
end | |
# Check the browser language preference and redirect if necessary. | |
# | |
def check_accept_language | |
browser_lang = request.env['HTTP_ACCEPT_LANGUAGE'] | |
#logger.debug "browser_lang = #{browser_lang.inspect}" | |
#logger.debug "request.lang_cd = #{request.lang_cd.inspect}" | |
#logger.debug "LsUtil.lang_cd = #{LsUtil.lang_cd.inspect}" | |
if (non_en_langs = LsUtil.non_english_languages) && | |
(! non_en_langs.empty?) && | |
request.lang_cd == 'en' && | |
browser_lang && | |
browser_lang =~ /^(#{non_en_langs * '|'})/ then | |
redirect_to generate_diff_lang_url($1) | |
return false | |
end | |
end | |
def generate_diff_lang_url(lang_cd) | |
http_host_port = "%s#{request.host}%s" % | |
if request.ssl? then | |
[ 'https://', '' ] | |
else | |
# i18n REFACTOR: any reason this is not filtering out port 80? | |
# How is this working in production? -- Bruce 2008-02-11 | |
# [ 'http://', (":#{request.port}" unless request.port == 80) ] | |
[ 'http://', ":#{request.port}" ] | |
end | |
return http_host_port + | |
LsUtil.url_key(lang_cd) + | |
no_key_url_for( | |
{ :only_path => true, | |
:controller => params[:controller], | |
:action => params[:action] | |
}.merge request.query_parameters | |
) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Home page to Reg 1: | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:just_logged]: | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:customer].language_cd: | |
CHECK LANGUAGE BEFORE IF STATEMENT- language_cd: | |
language_cd: | |
Reg 1 to Reg 2: | |
OCCURS IN FIRST REQUEST: | |
request.post? is true | |
SECOND REQUEST: | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:just_logged]: true | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:customer].language_cd: en | |
CHECK LANGUAGE BEFORE IF STATEMENT- language_cd: | |
CHECK LANGUAGE - session[:customer]: #555:Tre kvkXVHlH Schroeder (active):test-335354@cashnetusa.com | |
CHECK LANGUAGE - session[:customer].person: #564:Tre kvkXVHlH Schroeder | |
CHECK LANGUAGE - session[:customer].language_cd: en | |
CHECK LANGUAGE - language_cd: | |
CHECK LANGUAGE - test: true | |
just_logged session is true | |
redirect customer to proper location just he/she logged in | |
https://www-us-trogdor-cnuapp.dev.enova.com/secure/customers/new2 | |
Reg 2 to Contract: | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:just_logged]: | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:customer].language_cd: en | |
CHECK LANGUAGE BEFORE IF STATEMENT- language_cd: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Check ES on Home Page: | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:just_logged]: | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:customer].language_cd: | |
CHECK LANGUAGE BEFORE IF STATEMENT- language_cd: | |
language_cd: | |
Home page to Reg 1: | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:just_logged]: | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:customer].language_cd: | |
CHECK LANGUAGE BEFORE IF STATEMENT- language_cd: | |
language_cd: | |
Reg 1 to Reg 2: | |
request.post? is true | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:just_logged]: | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:customer].language_cd: | |
CHECK LANGUAGE BEFORE IF STATEMENT- language_cd: | |
language_cd: | |
Reg 2 to Contract: | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:just_logged]: true | |
CHECK LANGUAGE BEFORE IF STATEMENT - session[:customer].language_cd: en | |
CHECK LANGUAGE BEFORE IF STATEMENT- language_cd: | |
CHECK LANGUAGE - session[:customer]: #556:Itzel coQeMotR Renner (active):test-268381@cashnetusa.com | |
CHECK LANGUAGE - session[:customer].person: #565:Itzel coQeMotR Renner | |
CHECK LANGUAGE - session[:customer].language_cd: en | |
CHECK LANGUAGE - language_cd: | |
CHECK LANGUAGE - test: true | |
just_logged session is true | |
redirect customer to proper location just he/she logged in | |
https://www-us-trogdor-cnuapp.dev.enova.com/secure/dispatcher/regappcomplete?loan_amount=650&new_us_reg_cust=true&payment_method_cd=bank_account_ach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cnuapp-cnuapp-ruby-shared-core-request_helper | |
module RequestHelper | |
def self.language_cd(options) | |
request = options[:request] | |
person = options[:person] | |
(request && request.lang_cd) || (person && person.language_cd) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CHECK LANGUAGE - session[:just_logged]: true | |
CHECK LANGUAGE - session[:customer]: #549:Zoie RhxhxdSK Russel (active):test-895220@cashnetusa.com | |
CHECK LANGUAGE - session[:customer].person: #558:Zoie RhxhxdSK Russel | |
CHECK LANGUAGE - session[:customer].language_cd: en | |
CHECK LANGUAGE - language_cd: | |
CHECK LANGUAGE - test: true | |
just_logged session is true | |
redirect customer to proper location just he/she logged in | |
https://www-us-trogdor-cnuapp.dev.enova.com/secure/dispatcher/regappcomplete?loan_amount=2300&new_us_reg_cust=true&payment_method_cd=bank_account_ach |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment