This signin.pl has been implemented because users got mixed up
between the top and the bottom of the screen, since the output message
appeared near the appropriate submit button, which many people did not
properly observe.
This new method has the output messages appearing in a separate frame,
one which is always on the screen, so that apparent what is going on.
The text is taken from Stein's frameset.cgi example, customized to
perform the tasks that the original signin.pl undertook.
The original frameset.cgi code has been commented out.
Also, inappropriate lines from the original signin have been commented out.
#!/usr/local/bin/perl
require "count.pl";
use CGI;
$query = new CGI;
print $query->header;
$TITLE="Chem263 Sign In Menu (Old, New or Guest)";
# called via html?owner=Jones
$faculty_id = $query->param('owner');
if($faculty_id ne ''){
print "This panel allows access to examinations of Prof. $faculty_id <br>";}
#&count($query->script_name());
#last_name+first_name+password+counter, where '+' is the delimter
$filename = "../students_fall_96.dat";
#now we abandon pseudo FORTRAN/BASIC/etc codes, and do it in Perl fashion
$i = 1;
open ( STUD_FILE , $filename) ;
while(<STUD_FILE>){
chop;
if($_ ne ''){
$line = $_;
$safety_line[$i] = $line;
# print "<br>DEBUG",$i,"->",$safety_line[$i];
$i++;
($last_name,$first_name,$password,$counter) = split(/+/,$line);
if($last_name ne ''){ $id{$last_name} = $password;}
push(@last_name,$last_name);
# print $id($last_name),"
";
}
}
$i--;
$nrec = $i;
close(STUD_FILE);
# We use the path information to distinguish between calls
# to the script to:
# (1) create the frameset
# (2) create the query form
# (3) create the query response
$path_info = $query->path_info;
# If no path information is provided, then we create
# a side-by-side frame set
if (!$path_info) {
&print_frameset;
exit 0;
}
# If we get here, then we either create the query form
# or we create the response.
&print_html_header;
&print_query if $path_info=~/query/;
&print_response if $path_info=~/response/;
&print_end;
# Create the frameset
sub print_frameset {
$script_name = $query->script_name;
print <<EOF;
<html><head><title>$TITLE</title></head>
<frameset cols="50,50">
<frame src="$script_name/query" name="query">
<frame src="$script_name/response" name="response">
</frameset>
EOF
;
exit 0;
}
sub print_html_header {
print $query->start_html($TITLE);
}
sub print_end {
# print qq{<P><hr><A HREF="cgi_docs.html">Go to the documentation</A>};
print $query->end_html;
}
sub print_query {
$script_name = $query->script_name;
print "<H1>Old Student Query</H1>
";
print $query->start_form(-action=>"$script_name/response",-TARGET=>"response");
# print "What's your name? ",$query->textfield('name');
# print "<P>What's the combination?<P>",
# $query->checkbox_group(-name=>'words',
# -values=>['eenie','meenie','minie','moe']);
# print "<P>What's your favorite color? ",
# $query->popup_menu(-name=>'color',
# -values=>['red','green','blue','chartreuse']),
# "<P>";
# print $query->submit;
# print $query->end_form;
# here is signin
#print $query->start_form;
print $query->hidden('fac',$query->param('owner'));
$faculty_id = $query->param('fac');
#print $query->radio_group('choice_of_login_mode',['from list',
# 'adding new student'],'from list','true');
print $query->scrolling_list('student_list', @last_name);
$msg = "Student Registration";
print "<br>Enter your password here:",$query->password_field('pswd','',5,8);
$entered_passwd = $query->param('pswd');
print $query->submit('sub1',$msg);
print $query->end_form;
print "<hr>
";
print $query->start_form(-action=>"$script_name/response",-TARGET=>"response");
print $query->hidden('fac',$query->param('owner'));
$faculty_id = $query->param('fac');
print "<H1>New Student Query</H1>
";
print "This panel allows access to examinations as a new student. ";
print "<br>Last Name (no spaces) = ",$query->textfield('new_student_last_name','',20,40);
print "<br>First Name (no spaces) = ",$query->textfield('new_student_first_name','',20,40);
print $query->submit('sub2','New Student Registration');
print $query->end_form;
print "<hr>
";
print $query->start_form(-action=>"$script_name/response",-TARGET=>"response");
print $query->hidden('fac',$query->param('owner'));
$faculty_id = $query->param('fac');
print "<H1>Guest Query</H1>
";
print "This panel allows access to examinations as a guest. ";
#this is the guest login
print <<EOF;
There are two parts to guest registration, one part (obviously optional)
involves writing in a
guestbook, the second part allows the actual access. I would prefer if you use
the guestbook, but, feel free to do what you like.
No matter what you choose, you need to place something into the box marked `Last Name = ' and you need to press the `Guest Registration' button to continue.
<br>
<a href="./guestbook.pl">Please register in the guestbook.</a><br>
EOF
print "Last Name = ",$query->textfield('guest_last_name','',20,40);
print $query->submit('sub3','Guest Registration');
print $query->end_form;
print $query->end_html;
#print "password = ",&make_rno(7);
# credit to shelden@spoke.law.cornell.edu
#
#srand;#this initializes the random number generator
# at the outset, while debugging, comment this out
#srand($$|time);#this initializes the random number generator
#$ascii_passwd = &make_rno(5);
#print $ascii_passwd;
sub make_rno{
srand($$|time);#this initializes the random number generator
local(@passset,$rnd_passwd,$randum_num);
local ($randum_num);
#since l = both el and one, do not use
#since 0 = both oh and zero, do not use
@passset = ('a'..'k','m'..'z','A'..'N','P'..'Z','2'..'9');
$rnd_passwd = "";
for ($i = 0; $i<$_[0];$i++){
$randum_num = int(rand($#passset+1));
$rnd_passwd .= @passset[$randum_num];
}
return $rnd_passwd;
}
}
sub print_response {
print "<H1>Login Result</H1>
";
unless ($query->param) {
print "<b>No login action submitted yet.</b>";
return;
}
# print "<br><a href=./main_menu.pl?owner=$faculty_id&name=$name>Entry to Main Menu</a>";
# print "<br>Your password next time will be (note it down): $new_passwd";
# print $query->dump;
if ($query->param('sub3')){
if ($query->param('guest_last_name') ne ''){
print $query->hidden('fac',$faulty_id);
$name = $query->param('guest_last_name').'GUEST';
$faculty_id = $query->param('fac');
print "<br><a href=./main_menu.pl?owner=$faculty_id&name=$name>Entry to Main Menu</a>";
}
}
if ($query->param('sub1')) {
$chosen_name = $query->param('student_list');
# print "<br>Enter your password here:",$query->password_field('pswd','',5,8), " and resubmit by pressing `Student Registration' button.";
$entered_passwd = $query->param('pswd');
# print "<br>(DEBUG)$chosen_name $entered_passwd , $id{$chosen_name}";
if($entered_passwd eq $id{$chosen_name}){
# print "Got it";
# generate new password
$new_psswd = &make_rno(5);
# report it to student
print "<br>Your password next time will be (note it down): <strong>$new_psswd</strong> ";
$id{$last_name} = $new_psswd;
open ( STUD_FILE , "> $filename")||die"Can't open newfile:$!" ;#open to over-write!
for($j=1;$j<$nrec+1;$j++){
($last_name,$first_name,$password) = split(/+/,$safety_line[$j]);
if ($last_name eq $chosen_name){$password = $new_psswd;
$counter++;};
$new_record = join('+',$last_name,$first_name,$password,$counter);
print STUD_FILE $new_record,"
";
# print "<br>",$j," ->",$new_record;
}
close (STUD_FILE);
# give clickable address for table of contents
$name = "$chosen_name".&make_rno(3);
$faculty_id = $query->param('fac');
print "<br>Entry to <a href=./main_menu.pl?owner=$faculty_id&name=$name>Main Menu</a> is now available.";
# write new password to student file
}
}
if ($query->param('sub2')){
$new_passwd = &make_rno(5);
print "<br>Your password next time will be (note it down): $new_passwd";
$id{$last_name} = $new_psswd;
$new_name = $query->param('new_student_last_name').", ".$query->param('new_student_first_name');
$new_1name = $query->param('new_student_first_name');
open ( STUD_FILE , ">>$filename") ;#open to append!
$new_record = join('+',$new_name,$new_1name,$new_passwd,'1');
print STUD_FILE $new_record,"
";
# print "<br>DEBUG",$new_record,"
";
close (STUD_FILE);
$faculty_id = $query->param('fac');
print "<br><a href=main_menu.pl?owner=$faculty_id&name=$new_name>Entry to Main Menu</a>";
}
}