--- loncom/interface/createaccount.pm 2008/03/24 05:15:14 1.4 +++ loncom/interface/createaccount.pm 2008/07/08 17:52:16 1.13 @@ -3,7 +3,7 @@ # institutional log-in ID (institutional authentication required - localauth # or kerberos) or an e-mail address. # -# $Id: createaccount.pm,v 1.4 2008/03/24 05:15:14 raeburn Exp $ +# $Id: createaccount.pm,v 1.13 2008/07/08 17:52:16 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,6 +35,7 @@ use Apache::Constants qw(:common); use Apache::lonacc; use Apache::lonnet; use Apache::loncommon; +use Apache::lonhtmlcommon; use Apache::lonlocal; use Apache::lonauth; use Apache::resetpw; @@ -42,6 +43,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,8 +52,17 @@ 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'); @@ -71,7 +82,7 @@ sub handler { &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; } $start_page = @@ -82,24 +93,55 @@ sub handler { $domain = $env{'form.udom'}; } } - my $cancreate; + 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'}); } } } - 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 $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('