--- loncom/interface/createaccount.pm 2008/02/29 21:01:36 1.2 +++ loncom/interface/createaccount.pm 2008/07/08 03:00:43 1.10 @@ -3,7 +3,7 @@ # institutional log-in ID (institutional authentication required - localauth # or kerberos) or an e-mail address. # -# $Id: createaccount.pm,v 1.2 2008/02/29 21:01:36 raeburn Exp $ +# $Id: createaccount.pm,v 1.10 2008/07/08 03:00:43 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,11 +36,13 @@ use Apache::lonacc; use Apache::lonnet; use Apache::loncommon; use Apache::lonlocal; +use Apache::lonauth; use Apache::resetpw; use Authen::Captcha; use DynaLoader; # for Crypt::DES version use Crypt::DES; -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); +use HTML::Entities; sub handler { my $r = shift; @@ -49,65 +51,180 @@ sub handler { if ($r->header_only) { return OK; } - my $domain = &Apache::lonnet::default_login_domain(); + + my $domain; + + my $sso_username = $r->subprocess_env->get('REDIRECT_SSOUserUnknown'); + my $sso_domain = $r->subprocess_env->get('REDIRECT_SSOUserDomain'); + + if ($sso_username ne '' && $sso_domain ne '') { + $domain = $sso_domain; + } else { + $domain = &Apache::lonnet::default_login_domain(); + } my $domdesc = &Apache::lonnet::domain($domain,'description'); - my $start_page = - &Apache::loncommon::start_page('Create a user account in LON-CAPA','', - { - 'no_inline_link' => 1,}); - $r->print($start_page); - &Apache::lonhtmlcommon::clear_breadcrumbs(); - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"/adm/createuser", - text=>"New username"}); my $contact_name = &mt('LON-CAPA helpdesk'); my $contact_email = $r->dir_config('lonSupportEMail'); my $lonhost = $r->dir_config('lonHostID'); my $include = $r->dir_config('lonIncludes'); + my $start_page; + + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token','courseid']); &Apache::lonacc::get_posted_cgi($r); &Apache::lonlocal::get_language_handle($r); - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token']); - my $token = $env{'form.token'}; - my $output; - my $cancreate; + + my $handle = &Apache::lonnet::check_for_valid_session($r); + if ($handle ne '') { + $start_page = + &Apache::loncommon::start_page('Already logged in'); + my $end_page = + &Apache::loncommon::end_page(); + $r->print($start_page."\n".'
'.&mt('Please either [_1]continue the current session[_2] or [_3]logout[_4].','','','',''). + '
'.$end_page); + return OK; + } + $start_page = + &Apache::loncommon::start_page('Create a user account in LON-CAPA','', + {'no_inline_link' => 1,}); + if ($env{'form.phase'} eq 'username_activation') { + if ($env{'form.udom'} ne '') { + $domain = $env{'form.udom'}; + } + } + 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 ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') { - $cancreate = $domconfig{'usercreation'}{'cancreate'}{'selfcreate'}; + 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'}); } } } - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Create account')); - if (!$cancreate) { - $output = &mt('Creation of a new user account using an e-mail address as username or a loginID from your institution is not permitted in the domain: [_1] ([_2])',$domain,$domdesc); - } elsif ($token) { - $output = &process_mailtoken($r,$token,$contact_name,$contact_email,$domain, - $domdesc,$lonhost,$include); - } elsif ($env{'form.create_with_email'}) { + + if (@cancreate == 0) { + &print_header($r,$start_page); + my $output = &mt('Creation of a new user account using an e-mail address or an institutional log-in ID as username is not permitted in the domain: [_1] ([_2]).',$domain,$domdesc); + $r->print($output); + $r->print(&Apache::loncommon::end_page()); + return OK; + } + + my $courseid; + if (defined($env{'form.courseid'})) { + $courseid = &validate_course($env{'form.courseid'}); + } + + if ($sso_username ne '') { + &print_header($r,$start_page); + my ($output,$msg); + if (grep(/^sso$/,@cancreate)) { + $msg = &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 in this domain."); + ($output, my $checkfail) = &username_check($sso_username,$domain, + $domdesc,$courseid, + $lonhost,$contact_email); + if ($checkfail eq 'username') { + $msg .= &mt('A LON-CAPA account may not be created with the username you use.'); + } elsif ($checkfail eq 'authtoken') { + $msg .= &mt('Error creating token.'); + } else { + $msg .= &mt('To create one, use the table below to provide information about yourself (if appropriate), then click the "Create LON-CAPA account" button.'); + } + } else { + $msg = &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 in this domain, and you are not permitted to create one."); + } + $r->print('