[LON-CAPA-cvs] cvs: modules /gerd/loncapa_lernmodule/loncapa studip.pm
www
www at source.lon-capa.org
Thu Aug 30 10:25:53 EDT 2012
www Thu Aug 30 14:25:53 2012 EDT
Modified files:
/modules/gerd/loncapa_lernmodule/loncapa studip.pm
Log:
User generation and enrollment
Index: modules/gerd/loncapa_lernmodule/loncapa/studip.pm
diff -u modules/gerd/loncapa_lernmodule/loncapa/studip.pm:1.4 modules/gerd/loncapa_lernmodule/loncapa/studip.pm:1.5
--- modules/gerd/loncapa_lernmodule/loncapa/studip.pm:1.4 Thu Aug 30 11:57:03 2012
+++ modules/gerd/loncapa_lernmodule/loncapa/studip.pm Thu Aug 30 14:25:53 2012
@@ -7,7 +7,7 @@
#
# Landing point for incoming StudIP requests
#
-# $Id: studip.pm,v 1.4 2012/08/30 11:57:03 www Exp $
+# $Id: studip.pm,v 1.5 2012/08/30 14:25:53 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -59,6 +59,7 @@
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
+use LONCAPA::Enrollment;
use LONCAPA;
use LWP::UserAgent;
use RPC::XML::ParserFactory;
@@ -83,8 +84,8 @@
# url patterns of valid routes
my %routes = (
'^courses$' => 'courses',
- '^course\/' => 'course',
- '^enter\/' => 'enter'
+ '^course\/(.+)$' => 'course',
+ '^enter\/(.+)$' => 'enter'
);
# registry of route callbacks
@@ -183,6 +184,12 @@
my $user = &LONCAPA::clean_username($rawuser);
+ unless ($user eq $rawuser) {
+ &Apache::lonauth::failed($r, 'Couldn\'t handle username '.$rawuser, undef);
+ return OK;
+ }
+
+
my %form = (
'uname' => $user,
'udom' => $domain
@@ -191,16 +198,58 @@
# only check against own domain
my $uhome = &Apache::lonnet::homeserver($user, $domain);
- if($uhome eq 'no_host'){
- &Apache::lonauth::failed($r, "The user $user doesn\'t exist in this domain.", \%form);
- return OK;
- #return &error_msg($r, HTTP_UNAUTHORIZED);
- }
+ my $crs=$$params{'course_id'};
+ my ($cdom, $cid) = split(/_/, $crs);
+
+ &Apache::lonnet::logthis("Getting course $crs $cdom $cid");
+# Make a new user in the course if course is in own domain
+ if (($uhome eq 'no_host') && ($cdom eq $domain)) {
+ my ($first,$last)=&get_userinfo($user);
+ &Apache::lonnet::logthis("Getting names $first $last");
+ if ($last) {
+ &Apache::lonnet::logthis("About to create $user in $domain");
+# We don't have this user, we need to generate the user
+ my $password=&LONCAPA::Enrollment::create_password();
+ &Apache::lonnet::modifyuser($domain,$user,undef,'internal',$password,$first,undef,$last);
+ }
+ }
+# Still no user? Well, goodbye then.
+ $uhome = &Apache::lonnet::homeserver($user, $domain);
+ if ($uhome eq 'no_host') {
+ &Apache::lonauth::failed($r, "The user $user doesn\'t exist in this domain.", \%form);
+ return OK;
+ }
+
+# user is existing and authenticated from here on
+# Now check if the user is in the course
+
+
+ if($cdom eq $domain){
+ my %roles = &Apache::lonnet::get_my_roles($user, $domain, 'userroles');
+ my $matched_role = undef;
+ for my $key (keys %roles){
+ my($rcid, $rcdom, $role) = split(':', $key);
+ if($rcid eq $cid && $rcdom eq $cdom){
+ $matched_role = $role.'./'.$rcdom.'/'.$rcid;
+ last;
+ }
+ }
+ unless ($matched_role) {
+# The user is not in the course, so add him or her
+ my $start=time-60;
+ my $end=$start+365*24*60*60;
+ $env{'user.name'}=$user;
+ $env{'user.domain'}=$domain;
+ &Apache::lonnet::logthis("About to enroll $user:$domain into $crs from $start to $end");
+ &Apache::lonnet::modify_student_enrollment($domain,$user,
+ undef,undef,undef,undef,undef,undef,
+ $end,$start,'auto',0,$crs,1);
+ }
+ }
-# user is authenticated from here on
+# Okay, the user is now either in the course or hopeless (because course in other domain)
- my ($cdom, $cid) = split(/_/, $$params{'course_id'});
if($cdom eq $domain){
my %roles = &Apache::lonnet::get_my_roles($user, $domain, 'userroles');
@@ -331,8 +380,8 @@
for my $pattern(keys %routes){
my $endpoint = $routes{$pattern};
if(($path_info =~ /$pattern/) && ($request_handlers{$endpoint})){
+ $params{'course_id'}=$1;
$handler = $request_handlers{$endpoint};
- %params = %+;
last;
}
}
More information about the LON-CAPA-cvs
mailing list