#!/usr/bin/perl use strict; use warnings; use mydb; use CGI; use CGI::Session; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use utf8; my $db=mydb->new('test.db'); my $form = CGI->new(); my $session = CGI::Session->new("driver:File", $form, { Directory=>"/tmp" }) or die CGI::Session->errstr; my $sname=$ENV{SCRIPT_NAME}||'login.pl'; print $session->header(); warningsToBrowser(1); my $login=$session->param("loggedin"); my $name=$form->param('name'); my $pass=$form->param('pass'); if($form->param('logout')) { $session->delete('loggedin','name','pass'); print_login($sname,$form); # <== print_ vergessen... } elsif($login) { my $name=$session->param('name'); login_ok($sname,$form,$name); } elsif($db->chk($name, $pass)) { $session->param("loggedin",1); $session->param('name',$name); print_ok($sname,$form,$name); } else { print_login($sname,$form); } ######################################################################## sub print_login { my $sname=shift; my $form=shift; print $form->start_html("LOGIN"), $form->h1("Login | Ausleihe MMSZ.org"), $form->h4("LOGIN"), $form->startform(-action => $sname, -method => 'POST' ), $form->table({-border=>0}, $form->Tr({-align=>"LEFT", -valign=>"TOP"},[ $form->td(['Name' , $form->textfield( -name=>'name', -size=>30, -maxlength=>30, -value=>$form->param('name'))]), $form->td(['Passwort' , $form->password_field(-name=>'pass', -size=>30, -maxlength=>30 )]), ]), ), $form->br(), $form->submit("Login"), " ", $form->reset("Löschen"), $form->endform(), $form->end_html(); } sub print_ok { my $sname=shift; my $form=shift; my $name=shift; print $form->start_html("LOGIN OK!"), $form->h1("Login erfolgreich!"), $form->p("Willkommen $name"), $form->h4( $form->a({href=>"$sname?logout=1"},"LOGOUT"), ), $form->end_html(); }