ad_partner_verify_cookie

one of the documented procedures in this installation of the ACS
Usage:
ad_partner_verify_cookie   { redirect_if_not_logged_in "0" }
What it does:
Makes sure the user's appropriate cookie is set and if not, redirects to the same page to set the cookie. A special flag is set so we avoid an infinite loop when someone's cookies are off
Defined in: /web/philip/tcl/ad-partner-defs.tcl

Source code:


    # ns_log Notice "ad_partner_verify_cookie: starting"
    set return_url "[ns_conn url]?c=1"
    set query [export_ns_set_vars url]
    if { ![empty_string_p $query] } {
	append return_url "&$query"
    }
    set user_id [ad_get_user_id]
    # ns_log Notice "USER ID: $user_id"
    if { $user_id == 0 } {
	# We wouldn't know how to set the cookie without a user id!
	if { $redirect_if_not_logged_in } {
	    ad_returnredirect /register/index?[export_url_vars return_url]
	    ad_script_abort
	} else {
	    return
	}
    }
    set partner_cookie [ad_partner_from_cookie]
    # ns_log NOTICE "COOKIE: $partner_cookie"
    if { [empty_string_p $partner_cookie] ||  [string compare $partner_cookie [ad_parameter CookieDefault partner]] == 0  || [string compare $partner_cookie "expired"] == 0 } {
	set form_setid [ns_getform]
	if { [empty_string_p $form_setid] } {
	    set c 0 
	} else {
	    set c [ns_set get $form_setid c]
	}
	if { $c == 1 } {
	    ad_return_error "Your cookies are turned off" "You must turn on your cookies to use this site. Sorry for the inconvenience"
	    ad_script_abort
	}
	set db [ns_db gethandle subquery]
	set cookie [ad_partner_cookie_from_user_id $db $user_id]
	ns_db releasehandle $db
	ad_returnredirect "/$cookie$return_url"
	ad_script_abort
    }


philg@mit.edu