--- loncom/interface/createaccount.pm 2017/07/26 19:45:45 1.73 +++ loncom/interface/createaccount.pm 2017/08/03 16:22:08 1.74 @@ -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.73 2017/07/26 19:45:45 raeburn Exp $ +# $Id: createaccount.pm,v 1.74 2017/08/03 16:22:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -150,7 +150,7 @@ sub handler { my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain); my ($cancreate,$statustocreate,$statusforemail,$emailusername, - $verification,$emaildomain,$types,$usertypes,$othertitle) = + $emailoptions,$verification,$emaildomain,$types,$usertypes,$othertitle) = &get_creation_controls($domain,$domconfig{'usercreation'}); my ($additems,$pagetitle); if (ref($cancreate) eq 'ARRAY') { @@ -158,14 +158,15 @@ sub handler { ($env{'form.create_with_email'})) { if ((grep(/^email$/,@{$cancreate})) && (ref($statusforemail) eq 'ARRAY')) { my $usertype = &get_usertype($domain); - if (($usertype ne '') && (grep(/^\Q$usertype\E$/,@{$statusforemail}))) { - $js .= &username_js(); - } elsif (($usertype eq '') || (!grep(/^\Q$usertype\E$/,@{$statusforemail}))) { + 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) { + if ((@{$cancreate} == 1) && (@{$statusforemail} > 0)) { $pagetitle = 'Select affiliation'; } + } else { + $js .= &username_js(); } } } @@ -255,18 +256,32 @@ sub handler { return OK; } } - my ($usernameset,$condition); + 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} eq 'other') { - $usernameset = 1; + 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 ($emaildomain->{$usertype} ne '') { - $condition = $emaildomain->{$usertype}; + 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; } } } @@ -301,11 +316,14 @@ 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, - $usernameset,$condition); + $usernameset,$condition,$excluded,$hascustom); } elsif (!$token) { &print_header($r,$start_page,$courseid,$pagetitle); my $now=time; @@ -319,13 +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, $statusforemail,$usernameset,$condition, - $usertype,$types,$usertypes,$othertitle); + $excluded,$usertype,$types,$usertypes,$othertitle); } $r->print($output); &print_footer($r); @@ -409,7 +427,7 @@ sub selfenroll_crumbs { } sub javascript_setforms { - my ($now,$emailusername,$captcha,$usertype,$recaptchaversion,$usernameset,$condition) = @_; + my ($now,$emailusername,$captcha,$usertype,$recaptchaversion,$usernameset,$condition,$excluded) = @_; my ($setuserinfo,@required,$requiredchk); if (ref($emailusername) eq 'HASH') { if (ref($emailusername->{$usertype}) eq 'HASH') { @@ -431,7 +449,7 @@ sub javascript_setforms { ' server.elements.recaptcha_response_field.value=client.elements.recaptcha_response_field.value;'."\n"; } } - if ($usernameset) { + if ($usernameset eq 'free') { $setuserinfo .= ' server.elements.username.value=client.elements.username.value;'."\n"; } @@ -478,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') { @@ -543,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".'