[ic] GRRRRRRR. (expiring user accounts vs [set members_only]?)

Daniel Davenport DDavenport at newagedigital.com
Tue Jan 3 09:14:32 EST 2006


I'm trying to implement a system for user accounts with expiration
dates.  In this case, users can extend their membership by buying items
that have membership days (a new field) set for them.

The adding-days part works fine.  An extra order route takes care of
adding up the days purchased and crediting them to the user.

My problem now....i have two tags, whose code follows this message.  One
does a redirect if the account is expired, and one just says "expired"
in the same case -- making it useful for [if type=explicit]'s and such.
The code seems routine enough to me...i've done things like it dozens of
times before (though not often with userdb).  

For some reason, though, this time IC hates it.  Once one of the tags
runs on a members_only page, IC seems to endlessly bounce to some page
in the catalog (i'm not yet sure which page).  After either the browser
or IC gets tired of doing redirects, i end up at
http://127.0.0.1/login.html.  (IC probably tires out first, as i have a
single POSSIBLE BAD ROBOT message in error.log for the request.)  This
happens for every page until i restart the browser, after which
everything is back to normal.

Some experimentation reveals that the members_only page control doesn't
play very well at all with my tags.  This makes some sense for the
bouncing tag...it and the members_only control both end up causing a
redirect, which can be quite confusing.  But for the life of me, i can't
see why the lighter tag (the second one in the code below) would cause
problems with members_only.  Once i remove the members_only setting,
everything works fine.

If i have to write my own version of members_only, that's fine.  But
it'd be good to know how/why a rather simple bit of code is giving IC
such a hard time.

BTW, this catalog runs under IC 5.3.3 (INET mode), using the standard
catalog template.  Using perl v5.8.7, Apache 2.0.48 with suexec, and
mysql 4.0.15. Bundle::InterchangeKitchenSink and DBD::mysql were
installed a week ago.  I'm browsing with IE6 SP2.  Haven't tested it
myself with Mozilla, but the web guy (who uses Firefox most of the time)
was having problems too.

Now the code, as promised.  :)  (BTW, pages/expired.html is currently a
single line of plain text.  No ITL whatsoever.)
I'd assume there's a precedence problem in line 15, but the fact that
$expdate is always set, even if to a zero-but-true value ("0000-00-00"),
should at most cause admin status to be ignored during the check.  Since
my latest tests were using non-users, that shouldn't make a difference.

UserTag expiry-check addAttr
UserTag expiry-check Routine   <<ENDPERL
sub
{
    my ($attr) = @_;
    my $id =
$attr->{username}||$Session->{username}||$Values->{mv_username};
    my $udb = database_exists_ref('userdb');
    my $expdate = $udb->field($id, 'expdate');
    #return '' unless $expdate;
    $expdate ||= '0000-00-00';
    my (undef, undef, undef, $tday, $tmon, $tyr) = localtime;
    $tyr += 1900;
    $tmon = "0$tmon" if $tmon < 10;
    $tday = "0$tday" if $tday < 10;
    return '' if ("$tyr-$tmon-$tday" lt $expdate || $Session->{admin});
    my $bounce = $Tag->area($attr->{expirepage} || 'expired');

    # The tag was set to Interpolate, and was returning a [bounce] tag.
When
    # that didn't work, i swiped this code from variables/PAGE_INIT.
    $Scratch->{mv_successpage} = $Tag->var('MV_PAGE', 1);
    $Tag->deliver({ location => $bounce });
    return '';
}
ENDPERL

UserTag expired addAttr
UserTag expired Routine   <<ENDPERL
sub
{
    my ($attr) = @_;
    my $id =
$attr->{username}||$Session->{username}||$Values->{mv_username};
    my $udb = database_exists_ref('userdb');
    my $expdate = $udb->field($id, 'expdate');
    $expdate ||= '0000-00-00';
    my (undef, undef, undef, $tday, $tmon, $tyr) = localtime;
    $tyr += 1900;
    $tmon = "0$tmon" if $tmon < 10;
    $tday = "0$tday" if $tday < 10;
    return '' if ("$tyr-$tmon-$tday" lt $expdate || $Session->{admin});

    return "expired";
}
ENDPERL


--
Daniel Davenport
New Age Digital
http://www.newagedigital.com



More information about the interchange-users mailing list