Forum OpenACS Q&A: Re: "Logged In?"-Datasource and Template

Collapse
Posted by Jarkko Laine on
Hi Tim,

I'm not familiar with the old ACS's, but in OpenACS you can find a good sample from the installation default home page:

index.adp:

      <p>
      <if @user_id@ gt 0>
        You are currently logged in as @name@ (<a href="/register/">change
        login</a>).
      </if>
      <else>
        Start by <b>logging in</b> in the box on the right, using the email
        address and password that you have just specified for the
        administrator.
      </else>
      </p>

In the <else> part you could have a link to yoursite.com/register or a form for the registration.

There might be a simple include that would render the login form, but I'm not sure of that. Maybe someone could confirm if this is true?

then, in index.tcl, you have to prepare the data source:

set user_id [ad_get_user_id]
if { $user_id == 0 } {
    set user_id ""
}

If you're not familiar with the adp/tcl file pairs, you might want to read the docs for ACS Templating (https://openacs.org/doc/acs-templating/).

Developer note: should user_id be also in acs_page_contract -properties of index.tcl? In the current implementation it doesn't seem to be.

Collapse
Posted by Tim Adler on
Hey thanks, that already did it. @user_id@ and @user_name@ seem to be set throughout the whole system.

@dirk 😉

Ok, and now for the Basics. I found the setting of user_id and user_name in /acs-subsite/www/master.tcl.
So now I'm eager to also set user_email throughout the system.

[cc_user_name $user_id] sets the user_name. I assume that everything between [] is a functin-call.
So is there a function to get the user's mail@?

master.tcl(/adp) is probably a template. If you use it as site-wide master template, you can set things like @user_id@ and @user_name@ there.

Yes, everything inside [] brackets is a procedure call with the first word being the name of the proc and subsequent ones being the attributes.

I don't know what you mean by user name (the screen name or the real name), but ad_get_user_info gets the basic info (first names, last name, email) for the current user and might thus do the job (see https://openacs.org/api-doc/proc-view?proc=ad_get_user_info&source_p=1).

It sets the $email variable automatically, so if you call it in your site-wide master template's tcl file, you can refer to @email@, @first_names@ and @last_name@ in any adp page which is using that template. I don't know if that's the best practice, though, maybe some wiser people could answer that.

Thanks again for the instant answer. I found that procedure (wow, haven't used that word for a while ;) exactly where u said it would be.

But me being an absolute newbie to TCL, I have no idea how I'm supposed to call it.

I tried just writing [ad_get_user_info] into master.tcl, but that supplies me with Request Error:

invalid command name ""
    while executing
"[ad_get_user_info]"
    ("uplevel" body line 107)
    invoked from within
"uplevel {
How do I do that right? Do I have to give any params or have to do an import of some kind?