This commit was generated by cvs2svn to compensate for changes in r2526,
[freeside.git] / rt / webrt / autohandler
1 %# $Header: /home/cvs/cvsroot/freeside/rt/webrt/Attic/autohandler,v 1.1 2002-08-12 06:17:08 ivan Exp $
2 <& /Elements/Footer, %ARGS &>
3
4 <%INIT>
5
6 $m->{'rt_base_time'} = time;
7
8 #if it's a noauth file, don't ask for auth.
9 if ($m->base_comp->path =~ '^/+NoAuth/') {
10         $m->call_next();
11         $m->abort();
12 }
13
14 # If RT is configured for external auth, let's get REMOTE_USER
15 # We intentionally don't test for REMOTE_USER to meet our policy
16 elsif ($RT::WebExternalAuth){
17
18     $user = $ENV{'REMOTE_USER'};
19     $session{'CurrentUser'} = RT::CurrentUser->new();
20     $session{'CurrentUser'}->Load($user);
21     unless ($session{'CurrentUser'}->id() ) {
22         delete $session{'CurrentUser'};
23         $m->comp('/Elements/Login', %ARGS, Error=> 'You are not an authorized user');
24         $m->abort();
25     }
26 }
27  
28 # If the user is loging in, let's authenticate
29 elsif (defined ($user) && defined ($pass)){
30     
31     $session{'CurrentUser'} = RT::CurrentUser->new();
32     $session{'CurrentUser'}->Load($user);
33     unless ($session{'CurrentUser'}->id() ) {
34         delete $session{'CurrentUser'};
35         $m->comp('/Elements/Login', %ARGS, Error=> 'Your username or password is incorrect');
36         $m->abort();
37     };
38     unless ($session{'CurrentUser'}->IsPassword($pass)) {
39         delete $session{'CurrentUser'};
40         
41         $m->comp('/Elements/Login', Error => 'Your username or password is incorrect', %ARGS);
42         $m->abort();
43     }
44 }
45   
46
47 #If we've got credentials, lets serve the file up.
48 if ( (defined $session{'CurrentUser'}) and 
49      ( $session{'CurrentUser'}->Id) ) {
50     
51     # If the user isn\'t privileged, they can only see SelfService
52     if ((! $session{'CurrentUser'}->Privileged) and
53         ($m->base_comp->path !~ '^/+SelfService/') ) {
54         $m->comp('/SelfService/index.html');
55         $m->abort();
56     }
57     else {
58         $m->call_next;
59     }
60 }
61
62 #If we have no credentials
63 else {
64     $m->comp('/Elements/Login', %ARGS);
65     $m->abort();
66 }
67
68 </%INIT>
69
70 <%ARGS>
71 $user => undef
72 $pass => undef
73 </%ARGS>