Index: openacs-4/packages/acs-tcl/tcl/security-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/security-procs.tcl,v diff -u -r1.13.2.6 -r1.13.2.7 --- openacs-4/packages/acs-tcl/tcl/security-procs.tcl 7 Jun 2003 01:47:32 -0000 1.13.2.6 +++ openacs-4/packages/acs-tcl/tcl/security-procs.tcl 2 Jul 2003 19:35:06 -0000 1.13.2.7 @@ -524,35 +524,82 @@ ad_proc -public ad_redirect_for_registration {} { - Redirects user to /register/index to require the user to + Redirects user to /register/index of the closest subsite to require the user to register. When registration is complete, the user will be returned to the current location. All variables in ns_getform (both posts and gets) will be maintained. +

+ + It's up to the caller to issue an ad_script_abort, if that's what you want. + + @see ad_get_login_url } { - set form [ns_getform] - set url_args "" + ad_returnredirect [ad_get_login_url -return] +} + +ad_proc -public ad_get_login_url { + -return:boolean +} { - # note that there is no built-in function that will change - # posted variables to url variables, so we write our own + Returns a URL to the login page of the closest subsite, or the main site, if there's no current connection. - if { ![empty_string_p $form] } { - set form_size [ns_set size $form] - set form_counter_i 0 - while { $form_counter_i<$form_size } { - if {[string compare $form_counter_i "0"] == 0} { - append url_args "?" - } else { - append url_args "&" - } - append url_args "[ns_set key $form $form_counter_i]=[ns_urlencode [ns_set value $form $form_counter_i]]" - incr form_counter_i - } + @option return If set, will export the current form, so when the registration is complete, + the user will be returned to the current location. All variables in + ns_getform (both posts and gets) will be maintained. + + @author Lars Pind (lars@collaboraid.biz) +} { + if { [ad_conn isconnected] } { + set url [site_node_closest_ancestor_package_url] + + # Check to see that the user (most likely "The Public" party, since there's probably no user logged in) + # actually have permission to view that subsite, otherwise we'll get into an infinite redirect loop + array set site_node [site_node::get_from_url -url $url] + set package_id $site_node(object_id) + if { ![permission::permission_p -object_id $site_node(object_id) -privilege read] } { + set url / + } + } else { + set url / } - ad_returnredirect "/register/?return_url=[ns_urlencode [ad_conn url]$url_args]" - return + + append url "register/" + + if { $return_p } { + set url [export_vars -base $url { { return_url [ad_return_url] } }] + } + + return $url } +ad_proc -public ad_get_logout_url { + -return:boolean +} { + + Returns a URL to the logout page of the closest subsite, or the main site, if there's no current connection. + + @option return If set, will export the current form, so when the logout is complete + the user will be returned to the current location. All variables in + ns_getform (both posts and gets) will be maintained. + + @author Lars Pind (lars@collaboraid.biz) +} { + if { [ad_conn isconnected] } { + set url [site_node_closest_ancestor_package_url] + } else { + set url / + } + + append url "register/logout" + + if { $return_p } { + set url [export_vars -base $url { { return_url [ad_return_url] } }] + } + + return $url +} + ad_proc -public ad_maybe_redirect_for_registration {} { Checks to see if a user is logged in. If not, redirects to @@ -563,6 +610,7 @@ not explicitly call "return". Returns the user id if login was succesful. + @see ad_redirect_for_registration } { set user_id [ad_conn user_id] if { $user_id != 0 } {