Diff for /loncom/interface/createaccount.pm between versions 1.47 and 1.48

version 1.47, 2011/09/29 13:34:32 version 1.48, 2012/05/16 21:19:39
Line 45  use Crypt::DES; Line 45  use Crypt::DES;
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
 use HTML::Entities;  use HTML::Entities;
   
   #TODO this module needs documentation
   
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
Line 65  sub handler { Line 67  sub handler {
     if ($sso_username ne '' && $sso_domain ne '') {      if ($sso_username ne '' && $sso_domain ne '') {
         $domain = $sso_domain;           $domain = $sso_domain; 
     } else {      } else {
         $domain = &Apache::lonnet::default_login_domain();          ($domain, undef) = Apache::lonnet::is_course($env{'form.courseid'}); 
         if (defined($env{'form.courseid'})) {          $domain ||= &Apache::lonnet::default_login_domain();
             if (&validate_course($env{'form.courseid'})) {  
                 if ($env{'form.courseid'} =~ /^($match_domain)_($match_courseid)$/) {  
                     $domain = $1;   
                 }  
             }  
         }  
     }      }
     my $domdesc = &Apache::lonnet::domain($domain,'description');      my $domdesc = &Apache::lonnet::domain($domain,'description');
     my $contact_name = &mt('LON-CAPA helpdesk');      my $contact_name = &mt('LON-CAPA helpdesk');
Line 98  sub handler { Line 94  sub handler {
     }      }
   
     my ($js,$courseid,$title);      my ($js,$courseid,$title);
     if (defined($env{'form.courseid'})) {      $courseid = Apache::lonnet::is_course($env{'form.courseid'});
         $courseid = &validate_course($env{'form.courseid'});  
     }  
     if ($courseid ne '') {      if ($courseid ne '') {
         $js = &catreturn_js();          $js = &catreturn_js();
         $title = 'Self-enroll in a LON-CAPA course';          $title = 'Self-enroll in a LON-CAPA course';
Line 295  sub selfenroll_crumbs { Line 289  sub selfenroll_crumbs {
     return;      return;
 }  }
   
 sub validate_course {  
     my ($courseid) = @_;  
     my ($cdom,$cnum) = ($courseid =~ /^($match_domain)_($match_courseid)$/);  
     if (($cdom ne '') && ($cnum ne '')) {  
         if (&Apache::lonnet::is_course($cdom,$cnum)) {  
             return ($courseid);  
         }  
     }  
     return;  
 }  
   
 sub javascript_setforms {  sub javascript_setforms {
     my ($now) =  @_;      my ($now) =  @_;
     my $js = <<ENDSCRIPT;      my $js = <<ENDSCRIPT;
Line 652  sub process_mailtoken { Line 635  sub process_mailtoken {
                     } else {                      } else {
                         $msg .= &mt('An error occurred when sending e-mail to [_1] confirming creation of your LON-CAPA account.',$data{'username'});                          $msg .= &mt('An error occurred when sending e-mail to [_1] confirming creation of your LON-CAPA account.',$data{'username'});
                     }                      }
                     my %form = &start_session($r,$data{'username'},$domain,                       &start_session($r, $data{'username'}, $domain, $lonhost,
                                               $lonhost,$data{'courseid'},                          $data{'courseid'}, $token);
                                               $token);  
                     $nostart = 1;                      $nostart = 1;
                     $noend = 1;                      $noend = 1;
                 } else {                  } else {
Line 681  sub process_mailtoken { Line 663  sub process_mailtoken {
 }  }
   
 sub start_session {  sub start_session {
     my ($r,$username,$domain,$lonhost,$courseid,$token) = @_;      my ($r, $username, $domain, $lonhost, $courseid, $token) = @_;
     my %form = (  
                 uname => $username,  
                 udom  => $domain,  
                );  
     my $firsturl = '/adm/roles';  
     if (defined($courseid)) {  
         $courseid = &validate_course($courseid);  
         if ($courseid ne '') {  
             $form{'courseid'} = $courseid;  
             $firsturl = '/adm/selfenroll?courseid='.$courseid;  
         }  
     }  
     if ($r->dir_config('lonBalancer') eq 'yes') {      if ($r->dir_config('lonBalancer') eq 'yes') {
         &Apache::lonauth::success($r,$form{'uname'},$form{'udom'},          Apache::lonauth::success($r, $username, $domain, $lonhost,
                                   $lonhost,'noredirect',undef,\%form);              'noredirect', undef, {});
         if ($token ne '') {   
             my $delete = &Apache::lonnet::tmpdel($token);          Apache::lonnet::tmpdel($token) if $token;
         }  
         $r->internal_redirect('/adm/switchserver');          $r->internal_redirect('/adm/switchserver');
     } else {      } else {
         &Apache::lonauth::success($r,$form{'uname'},$form{'udom'},          $courseid = Apache::lonnet::is_course($courseid); 
                                   $lonhost,$firsturl,undef,\%form);  
           Apache::lonauth::success($r, $username, $domain, $lonhost,
               ($courseid ? "/adm/selfenroll?courseid=$courseid" : '/adm/roles'),
               undef, {}); 
     }      }
     return %form;  
       return;
 }  }
   
   
Line 877  sub username_validation { Line 852  sub username_validation {
     if ($uhome ne 'no_host') {      if ($uhome ne 'no_host') {
         my $result = &Apache::lonnet::authenticate($username,$upass,$domain);          my $result = &Apache::lonnet::authenticate($username,$upass,$domain);
         if ($result ne 'no_host') {           if ($result ne 'no_host') { 
             my %form = &start_session($r,$username,$domain,$lonhost,$courseid);              &start_session($r, $username, $domain, $lonhost, $courseid);
             $output = '<br /><br />'.&mt('A LON-CAPA account already exists for username [_1] at this institution ([_2]).','<tt>'.$username.'</tt>',$domdesc).'<br />'.&mt('The password entered was also correct so you have been logged in.');              $output = '<br /><br />'.&mt('A LON-CAPA account already exists for username [_1] at this institution ([_2]).','<tt>'.$username.'</tt>',$domdesc).'<br />'.&mt('The password entered was also correct so you have been logged in.');
             return ('existingaccount',$output);              return ('existingaccount',$output);
         } else {          } else {
Line 1101  sub username_activation { Line 1076  sub username_activation {
         if ($result eq 'ok') {          if ($result eq 'ok') {
             my $delete = &Apache::lonnet::tmpdel($env{'form.authtoken'});              my $delete = &Apache::lonnet::tmpdel($env{'form.authtoken'});
             $output = &mt('A LON-CAPA account has been created for username: [_1] in domain: [_2].',$username,$domain);              $output = &mt('A LON-CAPA account has been created for username: [_1] in domain: [_2].',$username,$domain);
             my %form = &start_session($r,$username,$domain,$lonhost,$courseid);              &start_session($r, $username, $domain, $lonhost, $courseid);
             my $nostart = 1;              my $nostart = 1;
             return ('ok',$output,$nostart);              return ('ok',$output,$nostart);
         } else {          } else {

Removed from v.1.47  
changed lines
  Added in v.1.48


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