--- loncom/interface/createaccount.pm 2014/03/03 17:11:41 1.61 +++ loncom/interface/createaccount.pm 2016/02/19 20:28:46 1.72 @@ -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.61 2014/03/03 17:11:41 raeburn Exp $ +# $Id: createaccount.pm,v 1.72 2016/02/19 20:28:46 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -170,10 +170,38 @@ sub handler { if (grep(/^sso$/,@{$cancreate})) { $msg = '

'.&mt('Account creation').'

'. &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 at this institution.").'
'; - + my $shibenv; + if (($r->dir_config('lonOtherAuthen') eq 'yes') && + ($r->dir_config('lonOtherAuthenType') eq 'Shibboleth')) { + if (ref($domconfig{'usercreation'}) eq 'HASH') { + if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') { + 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') { + if (ref($usertypes) eq 'HASH') { + if ($domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key} ne '') { + if (exists($usertypes->{$domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key}})) { + $shibenv->{$key} = $domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key}; + } + } + } + } elsif (grep(/^\Q$key\E/,@possfields)) { + if ($domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key} ne '') { + $shibenv->{$key} = $domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key}; + } + } + } + } + } + } + } $msg .= &username_check($sso_username,$domain,$domdesc,$courseid, $lonhost,$contact_email,$contact_name, - $sso_logout,$statustocreate); + $sso_logout,$statustocreate,$shibenv); } else { $msg = '

'.&mt('Account creation unavailable').'

'. ''.&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 at this institution, and you are not permitted to create one.").'

'.&mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email).'
'. @@ -187,10 +215,11 @@ 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'}); + $domconfig{'usercreation'},$usertype); if ($redirect) { $r->internal_redirect('/adm/switchserver'); return OK; @@ -248,24 +277,21 @@ sub handler { } elsif (!$token) { &print_header($r,$start_page,$courseid); my $now=time; - my $gotlondes; - if (grep(/^login$/,@{$cancreate})) { + if ((grep(/^login$/,@{$cancreate})) && (!grep(/^email$/,@{$cancreate}))) { if (open(my $jsh,"<$include/londes.js")) { while(my $line = <$jsh>) { $r->print($line); } close($jsh); $r->print(&javascript_setforms($now)); - $gotlondes = 1; } } - if (grep(/^email(|approval)$/,@{$cancreate})) { + if (grep(/^email$/,@{$cancreate})) { $r->print(&javascript_validmail()); } my $usertype = &get_usertype($domain); $output = &print_username_form($r,$domain,$domdesc,$cancreate,$now,$lonhost, - $include,$courseid,$gotlondes,$emailusername, - $usertype); + $include,$courseid,$emailusername,$usertype); } $r->print($output); &print_footer($r); @@ -293,7 +319,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']). '
'); @@ -328,7 +354,7 @@ sub selfenroll_crumbs { } my $last_crumb; if ($desc ne '') { - $last_crumb = &mt('Self-enroll in [_1]',"$desc"); + $last_crumb = &mt("Self-enroll in [_1]","'$desc'"); } else { $last_crumb = &mt('Self-enroll'); } @@ -340,7 +366,7 @@ sub selfenroll_crumbs { } sub javascript_setforms { - my ($now,$emailusername,$captcha,$usertype) = @_; + my ($now,$emailusername,$captcha,$usertype,$recaptchaversion) = @_; my ($setuserinfo,@required,$requiredchk); if (ref($emailusername) eq 'HASH') { if (ref($emailusername->{$usertype}) eq 'HASH') { @@ -356,13 +382,16 @@ 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 (@required) { my $missprompt = &mt('One or more required fields are currently blank.'); + &js_escape(\$missprompt); my $reqstr = join("','",@required); $requiredchk = <<"ENDCHK"; var requiredfields = new Array('$reqstr'); @@ -404,7 +433,7 @@ $requiredchk initkeys(); server.elements.upass.value - = crypted(client.elements.upass$now.value); + = getCrypted(client.elements.upass$now.value); client.elements.uname.value=''; client.elements.upass$now.value=''; @@ -417,17 +446,23 @@ $setuserinfo } return false; } + // ]]> ENDSCRIPT + if (($captcha eq 'recaptcha') && ($recaptchaversion eq '2')) { + $js .= "\n".''."\n"; + } return $js; } sub javascript_checkpass { my ($now,$context) = @_; my $nopass = &mt('You must enter a password.'); - my $mismatchpass = &mt('The passwords you entered did not match.').'\\n'. + my $mismatchpass = &mt('The passwords you entered did not match.')."\n". &mt('Please try again.'); + &js_escape(\$nopass); + &js_escape(\$mismatchpass); my $js = <<"ENDSCRIPT"; ENDSCRIPT