From: Chris W. <ch...@cw...> - 2004-05-27 17:56:04
|
> ... > Getting down to work, I tried to remove all of the "boxes" and such from > the /index.html document and create just a login box. The thing is, I > can't seem to figure out how to get the user information to display > anywhere other than in the user info box. I know there's something I'm > just not grokking here. So, I wanted the template to do something like > this pseudo-code: > > [%- IF user.authenticated -%] > ( Display boxes ) > ( Display default welcome page ) > [%- ELSE -%] > ( Display Login Form ) > [%- END -%] > > The entire admin app should be locked down, requiring the user to be > logged in before any page to be displayed. Check out the template toolkit plugin at: OI1: OpenInteract::Template::Plugin OI2: OpenInteract2::TT2::Plugin The plugin allows you to do something like this in your main template ('base_main'), using the plugin through the reserved 'OI' name: [% IF OI.logged_in %] Hello [% OI.login.full_name %], nice to see you! [% ELSE %] Login now! <form ...> </form> [% END %] You also don't have to use the login box for logging. in. For instance, on my website (http://www.cwinters.com/) I have a separate component called 'my_login_bar', which displays a thin fullscreen bar with your username and a link to edit your info if you're logged in, or a 'login' link if you're not. (It also displays a 'Printable' link for everything...) The template looks like this (apologies for wrapping issues): -------------------- <table width="100%" cellpadding="1" cellspacing="0" border="0"> [% IF OI.logged_in -%] [%- logout_url = OI.make_url( base = '/NoTmpl/Logout/', return = OI.return.url ) -%] [%- edit_url = OI.make_url( base = '/User/show/', user_id = OI.login.id ) -%] <tr valign="middle" bgcolor="#eeeeee"> <td align="left" width="50%"><font size="-1"> You are logged in as <b>[% OI.login.login_name %]</b> (<a href="[% edit_url %]">Edit my info</a>) </font></td> <td align="right" width="40%"><font size="-1"> <a href="[% logout_url %]">Logout</a> </font></td> <td align="right" width="10%"><font size="-1"> <a href="/NoTmpl[% path %]">Printable</a> </font></td> </tr> [% ELSE -%] <tr valign="middle" bgcolor="#cccccc"> <td align="right"><font size="-1"> <b><a href="/login.html">Login</a></b> </font></td> <td align="right"><font size="-1"> <a href="/NoTmpl[% path %]">Printable</a> </font></td> </tr> [% END -%] </table> -------------------- Hope this helps! Chris |