#!/usr/bin/perl
use strict;
use lib '/home/lib';
use CGI::Fast;
use webshots::SuperLogEvent;
use webshots::WebshotsUser;
use webshots::WebshotsUtility;
while (my $cgi = new CGI::Fast)
{
my $sIsPremium = WebshotsUtility::PeekIsPremiumUser($cgi) ? 1 : 0;
#print "Content-type: text/html\n\n";
#print "is premium $sIsPremium
";
#-----------------------------------------
# Update expired premium members
#-----------------------------------------
my $gpUser = new WebshotsUser;
#$gpUser->ReadFromDatabase('test_cedolin2');
#my $sResponse = $gpUser->GetCookieHTMLHeader($cgi);
#print "Set-Cookie: $sResponse\n";
#print "Content-type: text/plain\n\n";
#print "done script
$sResponse";
#exit;
if ($sIsPremium && $gpUser->LoginFromCookie($cgi)) # this just checks the status level in the cookie; skip the check if the login fails
{
#print "successful login
";
# Reset cookie for people who have expired (since logged in from cookie, this is just checking the SUB_END_DATE in the cookie)
if ( $gpUser->GetMembershipStatus(-sType=>'expired') )
{
$gpUser->SetServiceLevelExpired();
$gpUser->UpdateCookie($cgi);
}
else
{
#print "not expired
";
# Rewrite cookie 10% of the time to ensure that at some point manually expired users will have their cookies updated to free users
# if usercheck once per day/session--will catch after a few days on average
#######################
if (rand(10) < 1)
#if (rand(10) < 10)
{
$gpUser->ReadFromDatabase( $gpUser->GetUserName() );
$gpUser->UpdateCookie($cgi);
print "Content-type: text/html\n\n";
print "updated cookie";
}
}
}
# return something to the Javascript
print "Content-type: text/html\n\n";
print "done script";
}