#!C:/perl/bin/perl.exe
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$query = new CGI;
# Read in the pin and password
$pin= $query->param('pin');
$password= $query->param('password');
# Get date and time of account creation
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = 1900 + $year;
$mon= $mon+1;
$hour = $hour-1;
$ampm = "a.m.";
if($hour > 12){
$hour= $hour - 12;
$ampm = "p.m.";
}
$date1= "$mon/$mday/$year";
$date2= "$hour:$min" . "-" . "$ampm";
print $query->header;
print $query->start_html(-title=>'Create account ');
print " \n\n";
print "Welcome $pin
";
#--------------------------------------------
# Check to see if the username already exists. If so, reject it.
#--------------------------------------------
$error = 0;
open(INFO, "$ENV{'DOCUMENT_ROOT'}/P593/data/userlist.txt");
@passdata = ;
close(INFO);
foreach $key (@passdata){
@a=split(/,/,$key);
if($a[0] eq $pin){
print "That username has already been taken. Please click the back button on your browser and try creating a different user name.
";
$error=1;
}
}
#--------------------------------------------
# If no errors, save username and password to a database and provide link to login page
#--------------------------------------------
if ($error == 0){
open(INFO, ">>$ENV{'DOCUMENT_ROOT'}/P593/data/userlist.txt");
print INFO "$pin,$password,$date1,$date2,endline\n";
close(INFO);
print "Your username will be $pin.
";
print "You can login to the study by clicking on this link
";
} # end error == 0
if ($error == 1){
print "There was an error. Please try again.";
}
print $query->end_html;