Diff for /loncom/interface/createaccount.pm between versions 1.34 and 1.35

version 1.34, 2009/04/04 21:47:40 version 1.35, 2009/04/22 13:43:48
Line 112  sub handler { Line 112  sub handler {
         if ($env{'form.udom'} ne '') {          if ($env{'form.udom'} ne '') {
             $domain = $env{'form.udom'};              $domain = $env{'form.udom'};
         }          }
   
           my %domconfig = 
               &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
           my ($cancreate,$statustocreate) = 
               &get_creation_controls($domain,$domconfig{'usercreation'});
   
         my ($result,$output) =          my ($result,$output) =
             &username_validation($r,$env{'form.uname'},$domain,$domdesc,              &username_validation($r,$env{'form.uname'},$domain,$domdesc,
                                  $contact_name,$contact_email,$courseid,                                   $contact_name,$contact_email,$courseid,
                                  $lonhost);                                   $lonhost,$statustocreate);
         if ($result eq 'existingaccount') {          if ($result eq 'existingaccount') {
             $r->print($output);              $r->print($output);
             &print_footer($r);              &print_footer($r);
Line 133  sub handler { Line 139  sub handler {
     $start_page =      $start_page =
         &Apache::loncommon::start_page($title,$js,          &Apache::loncommon::start_page($title,$js,
                                        {'no_inline_link'   => 1,});                                         {'no_inline_link'   => 1,});
     my @cancreate;  
     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);  
     if (ref($domconfig{'usercreation'}) eq 'HASH') {  
         if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {  
             if (ref($domconfig{'usercreation'}{'cancreate'}{'selfcreate'}) eq 'ARRAY') {  
                 @cancreate = @{$domconfig{'usercreation'}{'cancreate'}{'selfcreate'}};  
             } elsif (($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') &&  
                      ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne '')) {  
                 @cancreate = ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'});  
             }  
         }  
     }  
   
     if (@cancreate == 0) {      my %domconfig = 
           &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
       my ($cancreate,$statustocreate) = &get_creation_controls($domain,$domconfig{'usercreation'});
       if (@{$cancreate} == 0) {
         &print_header($r,$start_page,$courseid);          &print_header($r,$start_page,$courseid);
         my $output = '<h3>'.&mt('Account creation unavailable').'</h3>'.          my $output = '<h3>'.&mt('Account creation unavailable').'</h3>'.
                      '<span class="LC_warning">'.                       '<span class="LC_warning">'.
Line 160  sub handler { Line 157  sub handler {
         &print_header($r,$start_page,$courseid);          &print_header($r,$start_page,$courseid);
         my ($msg,$sso_logout);          my ($msg,$sso_logout);
         $sso_logout = &sso_logout_frag($r,$domain);          $sso_logout = &sso_logout_frag($r,$domain);
         if (grep(/^sso$/,@cancreate)) {          if (grep(/^sso$/,@{$cancreate})) {
             $msg = '<h3>'.&mt('Account creation').'</h3>'.              $msg = '<h3>'.&mt('Account creation').'</h3>'.
                    &mt("Although your username and password were authenticated by your institution's Single Sign On system, you do not currently have a LON-CAPA account at this institution.").'<br />';                     &mt("Although your username and password were authenticated by your institution's Single Sign On system, you do not currently have a LON-CAPA account at this institution.").'<br />';
   
             $msg .= &username_check($sso_username,$domain,$domdesc,$courseid,               $msg .= &username_check($sso_username,$domain,$domdesc,$courseid, 
                                     $lonhost,$contact_email,$contact_name,$sso_logout);                                      $lonhost,$contact_email,$contact_name,
                                       $sso_logout,$statustocreate);
         } else {          } else {
             $msg = '<h3>'.&mt('Account creation unavailable').'</h3>'.              $msg = '<h3>'.&mt('Account creation unavailable').'</h3>'.
                    '<span class="LC_warning">'.&mt("Although your username and password were authenticated by your institution's Single Sign On system, you do not currently have a LON-CAPA account at this institution, and you are not permitted to create one.").'</span><br /><br />'.&mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email).'<hr />'.                     '<span class="LC_warning">'.&mt("Although your username and password were authenticated by your institution's Single Sign On system, you do not currently have a LON-CAPA account at this institution, and you are not permitted to create one.").'</span><br /><br />'.&mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email).'<hr />'.
Line 215  sub handler { Line 213  sub handler {
         (my $result,$output) =           (my $result,$output) = 
             &username_validation($r,$env{'form.uname'},$domain,$domdesc,              &username_validation($r,$env{'form.uname'},$domain,$domdesc,
                                  $contact_name,$contact_email,$courseid,                                   $contact_name,$contact_email,$courseid,
                                  $lonhost);                                   $lonhost,$statustocreate);
         if ($result eq 'existingaccount') {          if ($result eq 'existingaccount') {
             $r->print($output);              $r->print($output);
             &print_footer($r);              &print_footer($r);
Line 226  sub handler { Line 224  sub handler {
     } elsif ($env{'form.create_with_email'}) {      } elsif ($env{'form.create_with_email'}) {
         &print_header($r,$start_page,$courseid);          &print_header($r,$start_page,$courseid);
         $output = &process_email_request($env{'form.useremail'},$domain,$domdesc,          $output = &process_email_request($env{'form.useremail'},$domain,$domdesc,
                                          $contact_name,$contact_email,\@cancreate,                                           $contact_name,$contact_email,$cancreate,
                                          $lonhost,$domconfig{'usercreation'},                                           $lonhost,$domconfig{'usercreation'},
                                          $courseid);                                           $courseid);
     } elsif (!$token) {      } elsif (!$token) {
         &print_header($r,$start_page,$courseid);          &print_header($r,$start_page,$courseid);
         my $now=time;          my $now=time;
         if (grep(/^login$/,@cancreate)) {          if (grep(/^login$/,@{$cancreate})) {
             my $jsh=Apache::File->new($include."/londes.js");              my $jsh=Apache::File->new($include."/londes.js");
             $r->print(<$jsh>);              $r->print(<$jsh>);
             $r->print(&javascript_setforms($now));              $r->print(&javascript_setforms($now));
         }          }
         if (grep(/^email$/,@cancreate)) {          if (grep(/^email$/,@{$cancreate})) {
             $r->print(&javascript_validmail());              $r->print(&javascript_validmail());
         }          }
         $output = &print_username_form($domain,$domdesc,\@cancreate,$now,$lonhost,          $output = &print_username_form($domain,$domdesc,$cancreate,$now,$lonhost,
                                        $courseid);                                         $courseid);
     }      }
     $r->print($output);      $r->print($output);
Line 792  ENDSERVERFORM Line 790  ENDSERVERFORM
     return $output;      return $output;
 }  }
   
   sub get_creation_controls {
       my ($domain,$usercreation) = @_;
       my (@cancreate,@statustocreate);
       if (ref($usercreation) eq 'HASH') {
           if (ref($usercreation->{'cancreate'}) eq 'HASH') {
               if (ref($usercreation->{'cancreate'}{'statustocreate'}) eq 'ARRAY') {
                   @statustocreate = @{$usercreation->{'cancreate'}{'statustocreate'}};
               } else {
                   @statustocreate = ('default');
                   my ($othertitle,$usertypes,$types) =
                       &Apache::loncommon::sorted_inst_types($domain);
                   if (ref($types) eq 'ARRAY') {
                       push(@statustocreate,@{$types});
                   }
               }
               if (ref($usercreation->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
                   @cancreate = @{$usercreation->{'cancreate'}{'selfcreate'}};
               } elsif (($usercreation->{'cancreate'}{'selfcreate'} ne 'none') &&
                        ($usercreation->{'cancreate'}{'selfcreate'} ne '')) {
                   @cancreate = ($usercreation->{'cancreate'}{'selfcreate'});
               }
           }
       }
       return (\@cancreate,\@statustocreate);
   }
   
 sub create_account {  sub create_account {
     my ($r,$domain,$lonhost,$username,$domdesc) = @_;      my ($r,$domain,$lonhost,$username,$domdesc) = @_;
     my ($retrieved,$output,$upass) = &process_credentials($env{'form.logtoken'},      my ($retrieved,$output,$upass) = &process_credentials($env{'form.logtoken'},
Line 829  sub create_account { Line 853  sub create_account {
   
 sub username_validation {  sub username_validation {
     my ($r,$username,$domain,$domdesc,$contact_name,$contact_email,$courseid,      my ($r,$username,$domain,$domdesc,$contact_name,$contact_email,$courseid,
         $lonhost) = @_;          $lonhost,$statustocreate) = @_;
     my ($retrieved,$output,$upass);      my ($retrieved,$output,$upass);
   
     $username= &LONCAPA::clean_username($username);      $username= &LONCAPA::clean_username($username);
Line 863  sub username_validation { Line 887  sub username_validation {
         }          }
         if ($authok eq 'authorized') {          if ($authok eq 'authorized') {
             $output = &username_check($username,$domain,$domdesc,$courseid,$lonhost,              $output = &username_check($username,$domain,$domdesc,$courseid,$lonhost,
                                       $contact_email,$contact_name);                                        $contact_email,$contact_name,undef,
                                         $statustocreate);
         } else {          } else {
             $output = &login_failure_msg($courseid);              $output = &login_failure_msg($courseid);
         }          }
Line 888  sub login_failure_msg { Line 913  sub login_failure_msg {
 }  }
   
 sub username_check {  sub username_check {
     my ($username,$domain,$domdesc,$courseid,$lonhost,$contact_email,$contact_name,      my ($username,$domain,$domdesc,$courseid,$lonhost,$contact_email,
         $sso_logout) = @_;          $contact_name,$sso_logout,$statustocreate) = @_;
     my (%rulematch,%inst_results,$checkfail,$rowcount,$editable,$output,$msg,      my (%rulematch,%inst_results,$checkfail,$rowcount,$editable,$output,$msg,
         %alerts,%curr_rules,%got_rules);          %alerts,%curr_rules,%got_rules);
     &call_rulecheck($username,$domain,\%alerts,\%rulematch,      &call_rulecheck($username,$domain,\%alerts,\%rulematch,
Line 909  sub username_check { Line 934  sub username_check {
         }          }
     }      }
     if (!$checkfail) {      if (!$checkfail) {
           if (ref($statustocreate) eq 'ARRAY') {
               $checkfail = 'inststatus';
               if (ref($inst_results{$username.':'.$domain}{inststatus}) eq 'ARRAY') {
                   foreach my $inststatus (@{$inst_results{$username.':'.$domain}{inststatus}}) {
                       if (grep(/^\Q$inststatus\E$/,@{$statustocreate})) {
                           undef($checkfail);
                           last;
                       }
                   }
               } elsif (grep(/^default$/,@{$statustocreate})) {
                   undef($checkfail);
               }
           }
       }
       if (!$checkfail) {
         $output = '<form method="post" action="/adm/createaccount">';          $output = '<form method="post" action="/adm/createaccount">';
         (my $datatable,$rowcount,$editable) =           (my $datatable,$rowcount,$editable) = 
             &Apache::loncreateuser::personal_data_display($username,$domain,1,'selfcreate',              &Apache::loncreateuser::personal_data_display($username,$domain,1,'selfcreate',
Line 943  sub username_check { Line 983  sub username_check {
         } elsif ($checkfail eq 'authtoken') {          } elsif ($checkfail eq 'authtoken') {
             $msg .= '<span class="LC_error">'.&mt('Error creating token.').'</span>'.              $msg .= '<span class="LC_error">'.&mt('Error creating token.').'</span>'.
                     '<br />'.$output;                      '<br />'.$output;
           } elsif ($checkfail eq 'inststatus') {
               $msg .= '<span class="LC_warning">'.
                        &mt('You are not permitted to create a LON-CAPA account.').
                        '</span><br /><br />'.$output;
         }          }
         $msg .= &mt('Please contact the [_1] ([_2]) for assistance.',          $msg .= &mt('Please contact the [_1] ([_2]) for assistance.',
                 $contact_name,$contact_email).'<br /><hr />'.                  $contact_name,$contact_email).'<br /><hr />'.

Removed from v.1.34  
changed lines
  Added in v.1.35


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>