[cgiapp] Adding a div of fixed content to evey page. Possible?
Gurunandan R. Bhat
guru at informationmatters.in
Sat Oct 31 02:25:29 EDT 2009
On Fri, 2009-10-30 at 16:22 -0400, Brad Van Sickle wrote:
> I see what your problem is now..
> (code snipped)
> It seemed a little hackish and messy to me at the time, but it was the
> best I could think of. There probably is a much better way. Let me
> know what method you end up going with.
>
Here is what I found to be suitable based on Jason Purdy's suggestion.
DISCLAMER: I am not a very knowledgeable perl programmer - so
suggestions to improve it would be deeply appreciated. This is tested
code;
I have two run-modes 'login' and 'logout' used in the usual
CAP::Authentication style. Here is my prerun in the super-class:
sub cgiapp_prerun {
my $app = shift;
my $rm = shift;
return if ($rm eq 'login') || ($rm eq 'logout');
my $set_status = sub {
my ($c, $ht_params, $tmpl_params, $tmpl_file) = @_;
%$tmpl_params = (
USERNAME => $app->authen->username,
LASTLOGIN => $app->authen->last_login,
THISURL => $app->query->url,
);
};
$app->add_callback('load_tmpl', $set_status);
}
And here is my template fragment embedded inside every page:
<p class="authentication">
<!-- TMPL_IF NAME=USERNAME -->
Logged In As: <!-- TMPL_VAR NAME=USERNAME --> (<a
href="index.cgi?authen_logout=1">Logout</a>)<br />
Last Login: <!-- TMPL_VAR NAME=LASTLOGIN -->
<!-- TMPL_ELSE -->
<form id="loginform" name="loginform" method="post" action="<!--
TMPL_VAR NAME=THISURL -->">
<p>
<!-- TMPL_IF NAME=ATTEMPTS -->
Username or Password is Incorrect. Please enter the Username and
Password assigned to you by the Administrator.
(Attempt #: <!-- TMPL_VAR NAME=ATTEMPTS -->)
<!-- /TMPL_IF -->
<label for="authen_username"><em>*</em>Username:</label>
<input class="textInput" tabindex="1" type="text"
name="authen_username" size="20" value="" /><br />
<label for="authen_password"><em>*</em>Password:</label>
<input class="textInput" tabindex="2" type="password"
name="authen_password" size="20" /><br />
<div class="submitblock"><input class="primaryAction" tabindex="4"
type="submit" name="authen_loginbutton" value="Sign In"
class="button" /> or <a href="#">Register</a></div>
</p>
<input type="hidden" name="destination" value="<!-- TMPL_VAR
NAME=THISURL -->" />
<input type="hidden" name="rm" value="authen_login" />
</form>
<!-- /TMPL_IF -->
</p>
Any suggestions would be welcome and deeply appreciated!
More information about the cgiapp
mailing list