--- loncom/interface/createaccount.pm 2010/08/20 04:01:47 1.37.6.1 +++ loncom/interface/createaccount.pm 2019/05/05 04:00:42 1.77 @@ -1,9 +1,10 @@ # The LearningOnline Network # Allow visitors to create a user account with the username being either an -# institutional log-in ID (institutional authentication required - localauth -# or kerberos) or an e-mail address. +# institutional log-in ID (institutional authentication required - localauth, +# kerberos, or SSO) or an e-mail address. Requests to use an e-mail address as +# username may be processed automatically, or may be queued for approval. # -# $Id: createaccount.pm,v 1.37.6.1 2010/08/20 04:01:47 raeburn Exp $ +# $Id: createaccount.pm,v 1.77 2019/05/05 04:00:42 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,10 +37,10 @@ use Apache::lonacc; use Apache::lonnet; use Apache::loncommon; use Apache::lonhtmlcommon; +use Apache::lonuserutils; use Apache::lonlocal; use Apache::lonauth; use Apache::resetpw; -use Authen::Captcha; use DynaLoader; # for Crypt::DES version use Crypt::DES; use LONCAPA qw(:DEFAULT :match); @@ -55,22 +56,32 @@ sub handler { my $domain; - my $sso_username = $r->subprocess_env->get('REDIRECT_SSOUserUnknown'); - my $sso_domain = $r->subprocess_env->get('REDIRECT_SSOUserDomain'); + my $sso_username = $r->subprocess_env->get('SSOUserUnknown'); + my $sso_domain = $r->subprocess_env->get('SSOUserDomain'); - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token','courseid']); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['token','courseid','domain','type']); &Apache::lonacc::get_posted_cgi($r); &Apache::lonlocal::get_language_handle($r); if ($sso_username ne '' && $sso_domain ne '') { $domain = $sso_domain; } else { - $domain = &Apache::lonnet::default_login_domain(); - if (defined($env{'form.courseid'})) { - if (&validate_course($env{'form.courseid'})) { - if ($env{'form.courseid'} =~ /^($match_domain)_($match_courseid)$/) { - $domain = $1; + ($domain, undef) = Apache::lonnet::is_course($env{'form.courseid'}); + unless ($domain) { + if ($env{'form.phase'} =~ /^username_(activation|validation)$/) { + if (($env{'form.udom'} =~ /^$match_domain$/) && + (&Apache::lonnet::domain($env{'form.udom'}) ne '')) { + $domain = $env{'form.udom'}; + } else { + $domain = &Apache::lonnet::default_login_domain(); } + } elsif (($env{'form.phase'} eq '') && + ($env{'form.domain'} =~ /^$match_domain$/) && + (&Apache::lonnet::domain($env{'form.domain'}) ne '')) { + $domain = $env{'form.domain'}; + } else { + $domain = &Apache::lonnet::default_login_domain(); } } } @@ -92,15 +103,14 @@ sub handler { my $end_page = &Apache::loncommon::end_page(); $r->print($start_page."\n".'
'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].','','','',''). + '
'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].', + '','','',''). '
'.$end_page); return OK; } my ($js,$courseid,$title); - if (defined($env{'form.courseid'})) { - $courseid = &validate_course($env{'form.courseid'}); - } + $courseid = Apache::lonnet::is_course($env{'form.courseid'}); if ($courseid ne '') { $js = &catreturn_js(); $title = 'Self-enroll in a LON-CAPA course'; @@ -122,32 +132,53 @@ sub handler { &username_validation($r,$env{'form.uname'},$domain,$domdesc, $contact_name,$contact_email,$courseid, $lonhost,$statustocreate); - if ($result eq 'existingaccount') { + if ($result eq 'redirect') { + $r->internal_redirect('/adm/switchserver'); + return OK; + } elsif ($result eq 'existingaccount') { $r->print($output); &print_footer($r); return OK; } else { - $start_page = - &Apache::loncommon::start_page($title,$js, - {'no_inline_link' => 1,}); + $start_page = &Apache::loncommon::start_page($title,$js); &print_header($r,$start_page,$courseid); $r->print($output); &print_footer($r); return OK; } } - $start_page = - &Apache::loncommon::start_page($title,$js, - {'no_inline_link' => 1,}); - my %domconfig = + my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain); - my ($cancreate,$statustocreate) = &get_creation_controls($domain,$domconfig{'usercreation'}); + my ($cancreate,$statustocreate,$statusforemail,$emailusername, + $emailoptions,$verification,$emaildomain,$types,$usertypes,$othertitle) = + &get_creation_controls($domain,$domconfig{'usercreation'}); + my ($additems,$pagetitle); + if (ref($cancreate) eq 'ARRAY') { + unless (($env{'form.token'}) || ($sso_username ne '') || ($env{'form.phase'}) || + ($env{'form.create_with_email'})) { + if ((grep(/^email$/,@{$cancreate})) && (ref($statusforemail) eq 'ARRAY')) { + my $usertype = &get_usertype($domain); + if ((($usertype eq '') || (!grep(/^\Q$usertype\E$/,@{$statusforemail}))) && + (@{$statusforemail} > 0)) { + $js .= &setelements_js($statusforemail,$types,$usertypes,$othertitle); + $additems = {'add_entries' => { 'onload' => "setElements();"} }; + if ((@{$cancreate} == 1) && (@{$statusforemail} > 0)) { + $pagetitle = 'Select affiliation'; + } + } else { + $js .= &username_js(); + } + } + } + } + $start_page = &Apache::loncommon::start_page($title,$js,$additems); if (@{$cancreate} == 0) { - &print_header($r,$start_page,$courseid); + &print_header($r,$start_page,$courseid,$pagetitle); my $output = ''.&mt('Choose your affiliation at [_1]',$domdesc).'
'."\n". + ''; + $output .= ''."\n".''; } else { - my $helpdesk = '/adm/helpdesk?origurl=%2fadm%2fcreateaccount'; - if ($courseid ne '') { - $helpdesk .= '&courseid='.$courseid; + my ($captchaform,$error,$captcha,$recaptchaversion) = + &Apache::loncommon::captcha_display('usercreation',$lonhost); + if ($error) { + my $helpdesk = '/adm/helpdesk?origurl=%2fadm%2fcreateaccount'; + if ($courseid ne '') { + $helpdesk .= '&courseid='.$courseid; + } + $output .= ''. + &mt('An error occurred generating the validation code[_1] required for use of an e-mail address to request a LON-CAPA account.','