--- loncom/interface/createaccount.pm 2016/02/17 19:15:48 1.71 +++ loncom/interface/createaccount.pm 2017/08/03 20:06:21 1.75 @@ -4,7 +4,7 @@ # 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.71 2016/02/17 19:15:48 raeburn Exp $ +# $Id: createaccount.pm,v 1.75 2017/08/03 20:06:21 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -124,7 +124,7 @@ sub handler { my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain); - my ($cancreate,$statustocreate,$emailusername) = + my ($cancreate,$statustocreate) = &get_creation_controls($domain,$domconfig{'usercreation'}); my ($result,$output) = @@ -146,17 +146,37 @@ sub handler { return OK; } } - $start_page = &Apache::loncommon::start_page($title,$js); - my %domconfig = + my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain); - my ($cancreate,$statustocreate,$emailusername) = + 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('Account creation unavailable').'

'. ''. - &mt('Creation of a new user account using an e-mail address or an institutional log-in ID as username is not permitted at this institution ([_1]).',$domdesc). + &mt('Creation of a new user account using an institutional log-in ID or e-mail verification is not permitted for: [_1].',$domdesc). '

'; $r->print($output); &print_footer($r); @@ -178,7 +198,6 @@ sub handler { if (ref($domconfig{'usercreation'}{'cancreate'}{'shibenv'}) eq 'HASH') { my @possfields = ('firstname','middlename','lastname','generation', 'permanentemail','id'); - my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($domain); $shibenv= {}; foreach my $key (keys(%{$domconfig{'usercreation'}{'cancreate'}{'shibenv'}})) { if ($key eq 'inststatus') { @@ -215,11 +234,10 @@ sub handler { my ($output,$nostart,$noend,$redirect); my $token = $env{'form.token'}; if ($token) { - my $usertype = &get_usertype($domain); ($output,$nostart,$noend,$redirect) = &process_mailtoken($r,$token,$contact_name,$contact_email,$domain, $domdesc,$lonhost,$include,$start_page,$cancreate, - $domconfig{'usercreation'},$usertype); + $domconfig{'usercreation'},$types); if ($redirect) { $r->internal_redirect('/adm/switchserver'); return OK; @@ -238,7 +256,35 @@ sub handler { return OK; } } - + my ($usernameset,$condition,$excluded,$hascustom); + if ((grep(/^email$/,@{$cancreate})) && (($env{'form.create_with_email'}) || + ((!$token) && ($env{'form.phase'} eq '')))) { + my $usertype = &get_usertype($domain); + if ($usertype eq '') { + $usertype = 'default'; + } + if (ref($verification) eq 'HASH') { + if ($verification->{$usertype} =~ /^(free|first)$/) { + $usernameset = $verification->{$usertype}; + } + } + if (ref($emailoptions) eq 'HASH') { + if ($emailoptions->{$usertype} =~ /^(inst|noninst)$/) { + my $chosen = $1; + if (ref($emaildomain) eq 'HASH') { + if (ref($emaildomain->{$usertype}) eq 'HASH') { + if ($chosen eq 'inst') { + $condition = $emaildomain->{$usertype}->{$chosen}; + } else { + $excluded = $emaildomain->{$usertype}->{$chosen}; + } + } + } + } elsif ($emailoptions->{$usertype} eq 'custom') { + $hascustom = 1; + } + } + } if ($env{'form.phase'} eq 'username_activation') { (my $result,$output,$nostart) = &username_activation($r,$env{'form.uname'},$domain,$domdesc, @@ -270,12 +316,16 @@ sub handler { } elsif ($env{'form.create_with_email'}) { &print_header($r,$start_page,$courseid); my $usertype = &get_usertype($domain); + if ($usertype eq '') { + $usertype = 'default'; + } $output = &process_email_request($env{'form.uname'},$domain,$domdesc, $contact_name,$contact_email,$cancreate, $lonhost,$domconfig{'usercreation'}, - $emailusername,$courseid,$usertype); + $emailusername,$courseid,$usertype, + $usernameset,$condition,$excluded,$hascustom); } elsif (!$token) { - &print_header($r,$start_page,$courseid); + &print_header($r,$start_page,$courseid,$pagetitle); my $now=time; if ((grep(/^login$/,@{$cancreate})) && (!grep(/^email$/,@{$cancreate}))) { if (open(my $jsh,"<$include/londes.js")) { @@ -287,11 +337,13 @@ sub handler { } } if (grep(/^email$/,@{$cancreate})) { - $r->print(&javascript_validmail()); + $r->print(&javascript_validmail($condition)); } my $usertype = &get_usertype($domain); $output = &print_username_form($r,$domain,$domdesc,$cancreate,$now,$lonhost, - $include,$courseid,$emailusername,$usertype); + $include,$courseid,$emailusername, + $statusforemail,$usernameset,$condition, + $excluded,$usertype,$types,$usertypes,$othertitle); } $r->print($output); &print_footer($r); @@ -299,16 +351,25 @@ sub handler { } sub print_header { - my ($r,$start_page,$courseid) = @_; + my ($r,$start_page,$courseid,$pagetitle) = @_; $r->print($start_page); &Apache::lonhtmlcommon::clear_breadcrumbs(); + my $url = '/adm/createaccount'; + if ($pagetitle eq '') { + $pagetitle = 'New username'; + } if ($courseid ne '') { my %coursehash = &Apache::lonnet::coursedescription($courseid); &selfenroll_crumbs($r,$courseid,$coursehash{'description'}); } + if ($env{'form.reportedtype'}) { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>$url, + text=>"Select affiliation"}); + } &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"/adm/createuser", - text=>"New username"}); + ({href=>$url, + text=>$pagetitle}); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Create account')); return; } @@ -319,7 +380,7 @@ sub print_footer { $r->print('
'. &Apache::lonhtmlcommon::echo_form_input(['backto','logtoken', 'token','serverid','uname','upass','phase','create_with_email', - 'code','crypt','cfirstname','clastname', + 'code','crypt','cfirstname','clastname','g-recaptcha-response', 'recaptcha_challenge_field','recaptcha_response_field', 'cmiddlename','cgeneration','cpermanentemail','cid']). '
'); @@ -329,7 +390,7 @@ sub print_footer { sub get_usertype { my ($domain) = @_; - my $usertype = 'default'; + my $usertype; my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($domain); if (ref($types) eq 'ARRAY') { push(@{$types},'default'); @@ -366,7 +427,7 @@ sub selfenroll_crumbs { } sub javascript_setforms { - my ($now,$emailusername,$captcha,$usertype) = @_; + my ($now,$emailusername,$captcha,$usertype,$recaptchaversion,$usernameset,$condition,$excluded) = @_; my ($setuserinfo,@required,$requiredchk); if (ref($emailusername) eq 'HASH') { if (ref($emailusername->{$usertype}) eq 'HASH') { @@ -382,9 +443,15 @@ sub javascript_setforms { $setuserinfo .= ' server.elements.code.value=client.elements.code.value;'."\n". ' server.elements.crypt.value=client.elements.crypt.value;'."\n"; } elsif ($captcha eq 'recaptcha') { - $setuserinfo .= + if ($recaptchaversion ne '2') { + $setuserinfo .= ' server.elements.recaptcha_challenge_field.value=client.elements.recaptcha_challenge_field.value;'."\n". ' server.elements.recaptcha_response_field.value=client.elements.recaptcha_response_field.value;'."\n"; + } + } + if ($usernameset eq 'free') { + $setuserinfo .= + ' server.elements.username.value=client.elements.username.value;'."\n"; } } if (@required) { @@ -429,10 +496,8 @@ $requiredchk uextkey=client.elements.uextkey.value; lextkey=client.elements.lextkey.value; initkeys(); - server.elements.upass.value = getCrypted(client.elements.upass$now.value); - client.elements.uname.value=''; client.elements.upass$now.value=''; if (context == 'email') { @@ -448,6 +513,9 @@ $setuserinfo // ]]> ENDSCRIPT + if (($captcha eq 'recaptcha') && ($recaptchaversion eq '2')) { + $js .= "\n".''."\n"; + } return $js; } @@ -491,9 +559,12 @@ ENDSCRIPT } sub javascript_validmail { + my ($condition) = @_; my %js_lt = &Apache::lonlocal::texthash ( email => 'The e-mail address you entered', notv => 'is not a valid e-mail address', + avae => 'A valid e-mail address is not formed when the value you entered', + isco => 'is combined with the required domain', ); my $output = "\n".' +ENDSCRIPT + +} + +sub setelements_js { + my ($statusforemail,$types,$usertypes,$othertitle) = @_; + my ($posstypes,$posstypesnames,$availabletypes); + if ((ref($statusforemail) eq 'ARRAY') && (ref($types) eq 'ARRAY') && + (ref($usertypes) eq 'HASH')) { + $posstypes = join("','",@{$types},'default'); + $posstypesnames = join("','",(map {$usertypes->{$_};} @{$types}),$othertitle); + $availabletypes = join("','", @{$statusforemail}); + } + return <<"ENDSCRIPT"; + +ENDSCRIPT + +} + +sub username_js { + return <<"ENDSCRIPT"; + ENDSCRIPT } 500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.