--- loncom/interface/createaccount.pm 2014/05/05 22:01:15 1.66
+++ loncom/interface/createaccount.pm 2020/09/08 19:38:59 1.81
@@ -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.66 2014/05/05 22:01:15 raeburn Exp $
+# $Id: createaccount.pm,v 1.81 2020/09/08 19:38:59 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,6 +37,7 @@ use Apache::lonacc;
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonhtmlcommon;
+use Apache::lonuserutils;
use Apache::lonlocal;
use Apache::lonauth;
use Apache::resetpw;
@@ -124,7 +125,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 +147,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 +199,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 +235,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 +257,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,31 +317,34 @@ 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;
- my $gotlondes;
- if (grep(/^login$/,@{$cancreate})) {
- if (open(my $jsh,"<$include/londes.js")) {
+ 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$/,@{$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,$gotlondes,$emailusername,
- $usertype);
+ $include,$courseid,$emailusername,
+ $statusforemail,$usernameset,$condition,
+ $excluded,$usertype,$types,$usertypes,$othertitle);
}
$r->print($output);
&print_footer($r);
@@ -302,16 +352,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;
}
@@ -322,7 +381,7 @@ sub print_footer {
$r->print('');
@@ -332,7 +391,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');
@@ -369,7 +428,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') {
@@ -385,13 +444,20 @@ 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) {
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');
@@ -431,10 +497,8 @@ $requiredchk
uextkey=client.elements.uextkey.value;
lextkey=client.elements.lextkey.value;
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='';
if (context == 'email') {
@@ -446,17 +510,25 @@ $setuserinfo
}
return false;
}
+
// ]]>
ENDSCRIPT
+ if (($captcha eq 'recaptcha') && ($recaptchaversion eq '2')) {
+ $js .= "\n".''."\n";
+ }
return $js;
}
sub javascript_checkpass {
- my ($now,$context) = @_;
+ my ($now,$context,$domain) = @_;
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.');
+ my ($numrules,$intargjs) =
+ &Apache::lonuserutils::passwd_validation_js('upass',$domain);
+ &js_escape(\$nopass);
+ &js_escape(\$mismatchpass);
my $js = <<"ENDSCRIPT";
+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
}