TABOO/Handler/Login.pm untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 90 CC 5 SCAR 24.8
CC
5
Cov
0%
handler
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 12.0
1 package AxKit::App::TABOO::Handler::Login;
2  
3 # This is a simple mod_perl Handler to implement session tracking,
4 # just for the purpose of login users in.
5  
6 use Apache::Constants qw(:common);
7 use Apache;
8 use Apache::Request;
9 #use Apache::Cookie;
10 use Session;
11 use AxKit::App::TABOO::Data::User::Contributor;
12 use AxKit::App::TABOO;
13 use strict;
14 use warnings;
15 use Carp;
16  
17  
18 our $VERSION = '0.2';
19  
20 sub handler {
21 my $r = shift;
22  
23 my %session_config = AxKit::App::TABOO::session_config($r);
24  
25 my $cookie = $r->header_in('Cookie');
26 if (defined($cookie) && $cookie =~ m/VID=(\w*)/) {
27 # so, the user is logged in allready. Kill that session, then
28 my $session = new Session $1, %session_config;
29 $session->delete if defined $session;
30 }
31 my $outtext = '<html><head>';
32 my $req = Apache::Request->instance($r);
33 my $user = AxKit::App::TABOO::Data::User::Contributor->new();
34 my $authlevel = $user->load_authlevel($req->param('username'));
35 if ($authlevel) { # So, the user exists
36 my $encrypted = $user->load_passwd($req->param('username'));
37 if ($req->param('clear') && $encrypted && (crypt($req->param('clear'),$encrypted) eq $encrypted)) {
38 my $redirect = $r->header_in("Referer") || '/';
39 my $session = new Session undef, %session_config;
40 $r->header_out("Set-Cookie" => 'VID='.$session->session_id());
41 $session->set(authlevel => $authlevel);
42 $session->set(loggedin => $req->param('username'));
43 $outtext .= '<meta http-equiv="refresh" content="1;url='.$redirect.'">';
44 $outtext .= '<title>Log in</title></head><body><h1>Logged in</h1><p>Password is valid, go to <a href="/">main page</a>.</p>';
45 } else {
46 $outtext .= '<title>Log in</title></head><body><h1>Log in</h1><p>Password is invalid, go back and try again!</p>';
47 }
48 } else {
49 $outtext .= '<title>Log in</title></head><body><h1>Log in</h1><p>Username was not found, go back and try again!</p>';
50 }
51 $r->send_http_header('text/html');
52 $r->print($outtext."\n</body></html>\n");
53 return OK;
54 }
55  
56 1;
57 __END__