--- loncom/interface/createaccount.pm 2008/03/08 04:17:11 1.3 +++ 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.3 2008/03/08 04:17:11 raeburn Exp $ +# $Id: createaccount.pm,v 1.10 2008/07/08 03:00:43 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,6 +42,7 @@ use Authen::Captcha; use DynaLoader; # for Crypt::DES version use Crypt::DES; use LONCAPA qw(:DEFAULT :match); +use HTML::Entities; sub handler { my $r = shift; @@ -50,13 +51,23 @@ sub handler { if ($r->header_only) { return OK; } + + my $domain; - my $domain = &Apache::lonnet::default_login_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 $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); @@ -64,44 +75,78 @@ sub handler { my $handle = &Apache::lonnet::check_for_valid_session($r); if ($handle ne '') { - my $start_page = + $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); + ''.$end_page); return OK; } - - my $cancreate; + $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'}{'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'}); } } } - my $start_page = - &Apache::loncommon::start_page('Create a user account in LON-CAPA','', - { - 'no_inline_link' => 1,}); - if (!$cancreate) { + if (@cancreate == 0) { &print_header($r,$start_page); - my $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); + 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 $token = $env{'form.token'}; + 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('