#!/usr/bin/perl use strict; use Saffron; use DBU; use CGI; use HTML::Template; # Prepare variables my $cgi = new CGI; my %in = $cgi->Vars; my $cookie = 0; # Connect my $db = &Saffron::db_get_write(); $db->connect(); if ( !$in{C} ) { &show_form( \%in, $db ); } else { &refresh( \%in, $db ); } $db->disconnect(); ##### Subs #################### sub show_form { my ($in, $db) = @_; my $tmpl = HTML::Template->new(filename => 'show_form.html', path => 'tmpl/refresh_pass', die_on_bad_params => 0); print $cgi->header, $tmpl->output; } sub refresh { my ($in, $db) = @_; my $user = _verify($in, $db); # Then add if ( $user->{EDT} > time ) { &Saffron::api_call($user->{USERNAME}, $user->{PASSWORD}, 'add', $user->{SITE}); } &Saffron::api_call($user->{USERNAME}, $user->{PASSWORD}, 'add', $user->{SITE}); my $tmpl = HTML::Template->new(filename => 'refresh.html', path => 'tmpl/refresh_pass', die_on_bad_params => 0); print $cgi->header, $tmpl->output; } sub _verify { my ($in, $db) = @_; # Error checking if ( ! $in->{username} ) { &error('Enter your username') } if ( ! $in->{password} ) { &error('Enter your password') } if ( ! $in->{email} ) { &error('Enter your email address') } my $user = &Saffron::load_something($db, "select * from Users where USERNAME = '$in->{username}' order by DT desc limit 0, 1"); if (!$user->{USERNAME}) { &error("Username not found."); } # Find if we are responsible for rebills and cancellations my $merchant = &Saffron::load_something($db, "select * from Merchants where CODE = '$user->{MER}'"); if (! $merchant->{WE_REBILL}) { my $tmpl = HTML::Template->new(filename => 'thirdparty.html', path => 'tmpl/cancel', die_on_bad_params => 0); $tmpl->param(%{$merchant}); print $cgi->header, $tmpl->output; exit; } if ( $user->{PASSWORD} ne $in->{password} ) { &error('Wrong password') } if ( lc($user->{EMAIL}) ne lc($in->{email}) ) { &error('The email address is not the one on record', 'tmpl/cancel/error.html') } if ( $user->{CANCELLED} ) { &error('Your membership is already cancelled and your access to the site will stop on ' . &UnixDate(&ParseDate("epoch $user->{EDT}"), "%l")) } return $user; } sub error ($) { my ($error) = @_; my $tmpl = HTML::Template->new(filename => 'error.html', path => 'tmpl', die_on_bad_params => 0); $tmpl->param( err => $error, ); print $cgi->header, $tmpl->output; exit; }