|
From: Chris W. <la...@us...> - 2001-10-24 16:21:36
|
Update of /cvsroot/openinteract/OpenInteract/OpenInteract
In directory usw-pr-cvs1:/tmp/cvs-serv11689
Modified Files:
Auth.pm
Log Message:
added 'is_admin()' method so we can determine once if a user is an
administrator and then use that throughout the request
Index: Auth.pm
===================================================================
RCS file: /cvsroot/openinteract/OpenInteract/OpenInteract/Auth.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** Auth.pm 2001/10/11 03:55:39 1.10
--- Auth.pm 2001/10/24 16:21:33 1.11
***************
*** 17,20 ****
--- 17,22 ----
my ( $class ) = @_;
my $R = OpenInteract::Request->instance;
+ my $apr = $R->apache;
+
if ( my $uid = $R->{session}{user_id} ) {
$R->DEBUG && $R->scrib( 1, "Found session and uid ($uid); creating user." );
***************
*** 82,88 ****
}
! my $login_name = $R->apache->param( $login_field );
unless ( $login_name ) {
! $R->{auth}{user} = $class->create_nologin_user();
return undef;
}
--- 84,91 ----
}
! my $login_name = $apr->param( $login_field );
unless ( $login_name ) {
! $R->DEBUG && $R->scrib( 1, "Creating the not-logged-in user." );
! $R->{auth}{user} = $class->create_nologin_user;
return undef;
}
***************
*** 98,102 ****
$R->scrib( 0, "User with login ($login_name) not found. Throwing auth error" );
$R->throw({ code => 401,
! type => 'authenticate',
extra => { login_name => $login_name } });
return undef;
--- 101,105 ----
$R->scrib( 0, "User with login ($login_name) not found. Throwing auth error" );
$R->throw({ code => 401,
! type => 'authenticate',
extra => { login_name => $login_name } });
return undef;
***************
*** 173,176 ****
--- 176,203 ----
}
+
+ sub is_admin {
+ my ( $class ) = @_;
+ my $R = OpenInteract::Request->instance;
+
+ return unless ( $R->{auth}{logged_in} );
+ return unless ( ref $R->{auth}{group} eq 'ARRAY' );
+
+ my $CONFIG = $R->CONFIG;
+
+ if ( $R->{auth}{user}->id eq $CONFIG->{default_objects}{superuser} ) {
+ return $R->{auth}{is_admin}++;
+ }
+
+ my $site_admin_id = $CONFIG->{default_objects}{site_admin_group};
+ my $supergroup_id = $CONFIG->{default_objects}{supergroup};
+ foreach my $group ( @{ $R->{auth}{group} } ) {
+ my $group_id = $group->id;
+ if ( $group_id eq $site_admin_id or $group_id eq $supergroup_id ) {
+ return $R->{auth}{is_admin}++ ;
+ }
+ }
+ }
+
1;
***************
*** 194,202 ****
OpenInteract::Auth->group;
=head1 DESCRIPTION
! This class is responsible for authenticating users to the system. It
! does this in one of two ways:
=over 4
--- 221,238 ----
OpenInteract::Auth->group;
+ # See whether this user is an administrator
+
+ OpenInteract::Auth->is_admin;
+
=head1 DESCRIPTION
! This class/interface is responsible for authenticating users to the
! system and other authentication checks. If you have custom
! authentication needs you can specify your class in the server
! configuration and create your own or subclass this class and use
! pieces of it as needed.
+ This class tries to create a user in one of two ways:
+
=over 4
***************
*** 280,283 ****
--- 316,338 ----
$R->{auth}{group}
+ B<create_nologin_user()>
+
+ If a user is not logged in, we create transient user object so that
+ $R->{auth}{user} has something in it. It is not a valid user and it
+ gets created anew with every request where the user is not logged in.
+
+ If you want to rename the login_name, first/last name, etc, just
+ subclass this class, create your own method, then specify your class
+ in the server configuration.
+
+ B<is_admin()>
+
+ Looks at the user and groups and determines whether the user is an
+ administrator. If the user is an administrator, then:
+
+ $R->{auth}{is_admin}
+
+ is set to a true value.
+
=head1 TO DO
***************
*** 295,301 ****
=head1 SEE ALSO
! L<OpenInteract::User>
! L<OpenInteract::Group>
=head1 COPYRIGHT
--- 350,356 ----
=head1 SEE ALSO
! L<OpenInteract::User|OpenInteract::User>
! L<OpenInteract::Group|OpenInteract::Group>
=head1 COPYRIGHT
|