|
|
|
новичок
      
участник
Last Login: 13.10.2005 21:27
Сообщ.: 3,
Visits: 34
|
|
Помогите подправить код. Что бы авторизация проводилась один раз, записывалась в сессию каждый раз при переходи от одного линка к другому не спрашивалась.
sub show_student_login {
print "$header
$error
Авторизация:
$footer";
exit();
}
sub check_student_auth {
# If there is no authorized users setting, then they are just
# authorized by default.
if($authorized_users eq "no" && $overall_quiz_password eq "no"){
$auth = 1;
return $auth;
}
elsif($data{''student''} eq "" || $data{''studpass''} eq ""){ $auth = 0; }
else {
open(FILE, "<$authorized_users_file") ||
&debug("Could not read authorized_users_file $authorized_users_file: $!");
($student,$studpass,$studname,$studquizzes) =
split(/\|/, (grep(/^$data{''student''}\|/, ))[0]);
close(FILE);
chomp($studpass);
if($student eq &unpipe($data{''student''}) &&
$studpass eq &unpipe($data{''studpass''})){
# Check to see if they can take this particular quiz
chomp($studquizzes);
@s_quizzes = split(/%/, $studquizzes);
# They are authorized for no quizzes.
if($#s_quizzes < 0){
$auth = -1;
}
elsif(-f "$basedir/$quizdir/quizdb"){
open(FILE, "<$basedir/$quizdir/quizdb") ||
&debug("Could not read quizdb file $basedir/$quizdir/quizdb: $!");
$quiztitle = (split(/\|/, ))[0];
close(FILE);
}
foreach $s_quiz (@s_quizzes){
if ($quiz eq $s_quiz || $quiztitle eq $s_quiz){ $auth = 1; last; }
else { $auth = -1; }
}
}
}
if($auth != 1){
# First, check to see if global pw is enabled.
if($overall_quiz_password eq "yes" &&
$data{''overall_quiz_password_text''} eq $overall_quiz_password_text &&
$overall_quiz_password_text ne ""){
$auth = 1;
}
else {
# Check to see if it''s an instructor trying out the quiz.
$data{''admlogin''} = &unpipe($data{''admlogin''});
$data{''admpass''} = &unpipe($data{''admpass''});
open(FILE, "<$instructors_file") ||
&debug("Could not read instructors file $instructors_file: $!");
($instructor,$inspass) =
(split(/\|/, (grep(/^$data{''admlogin''}\|/, ))[0]))[0,1];
close(FILE);
chomp($inspass);
if($instructor eq $data{''admlogin''} && $inspass eq $data{''admpass''}
&& $data{''admlogin''} ne "" && $data{''admpass''} ne ""){
$auth = 2;
}
}
}
$auth;
Спасибо.
Полный код можно загрузить сдесь:
http://tesol.net/scripts/quiztest.zip
Спасибо.
|
|
|
|