[LON-CAPA-cvs] cvs: loncom /interface createaccount.pm domainprefs.pm lonconfigsettings.pm loncreateuser.pm
raeburn
raeburn at source.lon-capa.org
Wed Jul 26 15:45:46 EDT 2017
raeburn Wed Jul 26 19:45:46 2017 EDT
Modified files:
/loncom/interface createaccount.pm domainprefs.pm
lonconfigsettings.pm loncreateuser.pm
Log:
- Self-creation of user accounts using e-mail verification.
- User can be prompted to choose affiliation (e.g., instructor, student,
other etc.).
- User can be given option to choose a username, while e-mail address
still used for verification. A required e-mail domain can be set.
- Domain Coordinator can display user-selected status and user's e-mail
address when choosing to approve queued account requests.
-------------- next part --------------
Index: loncom/interface/createaccount.pm
diff -u loncom/interface/createaccount.pm:1.72 loncom/interface/createaccount.pm:1.73
--- loncom/interface/createaccount.pm:1.72 Fri Feb 19 20:28:46 2016
+++ loncom/interface/createaccount.pm Wed Jul 26 19:45:45 2017
@@ -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.72 2016/02/19 20:28:46 raeburn Exp $
+# $Id: createaccount.pm,v 1.73 2017/07/26 19:45:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -124,7 +124,7 @@
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,36 @@
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,
+ $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 ne '') && (grep(/^\Q$usertype\E$/,@{$statusforemail}))) {
+ $js .= &username_js();
+ } elsif (($usertype eq '') || (!grep(/^\Q$usertype\E$/,@{$statusforemail}))) {
+ $js .= &setelements_js($statusforemail,$types,$usertypes,$othertitle);
+ $additems = {'add_entries' => { 'onload' => "setElements();"} };
+ if (@{$cancreate} == 1) {
+ $pagetitle = 'Select affiliation';
+ }
+ }
+ }
+ }
+ }
+ $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 = '<h3>'.&mt('Account creation unavailable').'</h3>'.
'<span class="LC_warning">'.
- &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).
'</span><br /><br />';
$r->print($output);
&print_footer($r);
@@ -178,7 +197,6 @@
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 +233,10 @@
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 +255,21 @@
return OK;
}
}
-
+ my ($usernameset,$condition);
+ if ((grep(/^email$/,@{$cancreate})) && (($env{'form.create_with_email'}) ||
+ ((!$token) && ($env{'form.phase'} eq '')))) {
+ my $usertype = &get_usertype($domain);
+ if (ref($verification) eq 'HASH') {
+ if ($verification->{$usertype} eq 'other') {
+ $usernameset = 1;
+ if (ref($emaildomain) eq 'HASH') {
+ if ($emaildomain->{$usertype} ne '') {
+ $condition = $emaildomain->{$usertype};
+ }
+ }
+ }
+ }
+ }
if ($env{'form.phase'} eq 'username_activation') {
(my $result,$output,$nostart) =
&username_activation($r,$env{'form.uname'},$domain,$domdesc,
@@ -273,9 +304,10 @@
$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);
} 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")) {
@@ -291,7 +323,9 @@
}
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,
+ $usertype,$types,$usertypes,$othertitle);
}
$r->print($output);
&print_footer($r);
@@ -299,16 +333,25 @@
}
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;
}
@@ -329,7 +372,7 @@
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 +409,7 @@
}
sub javascript_setforms {
- my ($now,$emailusername,$captcha,$usertype,$recaptchaversion) = @_;
+ my ($now,$emailusername,$captcha,$usertype,$recaptchaversion,$usernameset,$condition) = @_;
my ($setuserinfo, at required,$requiredchk);
if (ref($emailusername) eq 'HASH') {
if (ref($emailusername->{$usertype}) eq 'HASH') {
@@ -388,6 +431,10 @@
' server.elements.recaptcha_response_field.value=client.elements.recaptcha_response_field.value;'."\n";
}
}
+ if ($usernameset) {
+ $setuserinfo .=
+ ' server.elements.username.value=client.elements.username.value;'."\n";
+ }
}
if (@required) {
my $missprompt = &mt('One or more required fields are currently blank.');
@@ -520,18 +567,16 @@
sub print_username_form {
my ($r,$domain,$domdesc,$cancreate,$now,$lonhost,$include,$courseid,$emailusername,
- $usertype) = @_;
+ $statusforemail,$usernameset,$condition,$usertype,$types,$usertypes,
+ $othertitle) = @_;
my %lt = &Apache::lonlocal::texthash (
- unam => 'username',
- udom => 'domain',
- uemail => 'E-mail address in LON-CAPA',
- proc => 'Proceed',
crac => 'Create account with a username provided by this institution',
clca => 'Create LON-CAPA account',
type => 'Type in your log-in ID and password to find out.',
plse => 'Please provide a password for your new account.',
info => 'Please provide user information and a password for your new account.',
yopw => 'Your password will be encrypted when sent (and stored).',
+ crae => 'Create account using e-mail address verification',
);
my $output;
if (ref($cancreate) eq 'ARRAY') {
@@ -548,45 +593,82 @@
}
}
if (grep(/^email$/,@{$cancreate})) {
- $output .= '<div class="LC_left_float"><h3>'.&mt('Create account with an e-mail address as your username').'</h3>';
- 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 .= '<span class="LC_error">'.
- &mt('An error occurred generating the validation code[_1] required for an e-mail address to be used as username.','<br />').
- '</span><br /><br />'.
- &mt('[_1]Contact the helpdesk[_2] or [_3]reload[_2] the page and try again.',
- '<a href="'.$helpdesk.'">','</a>','<a href="javascript:window.location.reload()">');
+ $output .= '<div class="LC_left_float"><h3>'.$lt{'crae'}.'</h3>';
+ if ($usertype ne '') {
+ if (ref($statusforemail) eq 'ARRAY') {
+ unless (grep(/^\Q$usertype\E$/,@{$statusforemail})) {
+ undef($usertype);
+ }
+ }
+ }
+ if (($usertype eq '') && (ref($statusforemail) eq 'ARRAY') &&
+ (@{$statusforemail}) && (ref($types) eq 'ARRAY')) {
+ my @posstypes = @{$types};
+ unless (grep(/^default$/, at posstypes)) {
+ push(@posstypes,'default');
+ }
+ $output .= '<p>'.&mt('Choose your affiliation at [_1]',$domdesc).'</p>'."\n".
+ '<form name="reportstatus" id="LC_reportstatus" action="" method="post" '.
+ 'onsubmit="return checkVerification();"><p>';
+ foreach my $type (@posstypes) {
+ my $name;
+ if ($type eq 'default') {
+ $name = $othertitle;
+ } else {
+ $name = $type;
+ if (ref($usertypes) eq 'HASH') {
+ if (exists($usertypes->{$type})) {
+ $name = $usertypes->{$type};
+ }
+ }
+ }
+ $output .= '<label><input type="radio" name="type" value="'.$type.'" />'.
+ $name.'</label>'.(' 'x2);
+ }
+ if ($env{'form.courseid'} =~ /^$match_domain\_$match_courseid$/) {
+ $output .= "\n".'<input type="hidden" name="courseid" value="'.$env{'form.courseid'}.'" />';
+ }
+ $output .= '</p>'."\n".'<p><input type="submit" name="reportedtype" value="'.&mt('Submit').'" /></p></form>';
} else {
- if (grep(/^login$/,@{$cancreate})) {
- $output .= &mt('If you do not have a log-in ID at your institution, [_1]provide your e-mail address to request a LON-CAPA account.','<br />').'<br /><br />'.
- $lt{'plse'}.'<br />'.
- $lt{'yopw'}.'<br />';
+ 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 .= '<span class="LC_error">'.
+ &mt('An error occurred generating the validation code[_1] required for use of an e-mail address to request a LON-CAPA account.','<br />').
+ '</span><br /><br />'.
+ &mt('[_1]Contact the helpdesk[_2] or [_3]reload[_2] the page and try again.',
+ '<a href="'.$helpdesk.'">','</a>','<a href="javascript:window.location.reload()">');
} else {
- my $prompt = $lt{'plse'};
- if (ref($emailusername) eq 'HASH') {
- if (ref($emailusername->{$usertype}) eq 'HASH') {
- if (keys(%{$emailusername->{$usertype}}) > 0) {
- $prompt = $lt{'info'};
+ if (grep(/^login$/,@{$cancreate})) {
+ $output .= &mt('If you do not have a log-in ID at your institution, [_1]provide your e-mail address to request a LON-CAPA account.','<br />').'<br /><br />'.
+ $lt{'plse'}.'<br />'.
+ $lt{'yopw'}.'<br />';
+ } else {
+ my $prompt = $lt{'plse'};
+ if (ref($emailusername) eq 'HASH') {
+ if (ref($emailusername->{$usertype}) eq 'HASH') {
+ if (keys(%{$emailusername->{$usertype}}) > 0) {
+ $prompt = $lt{'info'};
+ }
}
}
+ $output .= $prompt.'<br />'.
+ $lt{'yopw'}.'<br />';
}
- $output .= $prompt.'<br />'.
- $lt{'yopw'}.'<br />';
+ $output .= &print_dataentry_form($r,$domain,$lonhost,$include,$now,$captchaform,
+ $courseid,$emailusername,$captcha,$usertype,
+ $recaptchaversion,$usernameset,$condition);
}
- $output .= &print_dataentry_form($r,$domain,$lonhost,$include,$now,$captchaform,
- $courseid,$emailusername,$captcha,$usertype,
- $recaptchaversion);
}
$output .= '</div>';
}
}
if ($output eq '') {
- $output = &mt('Creation of a new LON-CAPA user account using an e-mail address or an institutional log-in ID as your username is not permitted at [_1].',$domdesc);
+ $output = &mt('Creation of a new LON-CAPA user account using an institutional log-in ID or verification by e-mail is not permitted at [_1].',$domdesc);
} else {
$output .= '<div class="LC_clear_float_footer"></div>';
}
@@ -646,8 +728,9 @@
sub process_email_request {
my ($useremail,$domain,$domdesc,$contact_name,$contact_email,$cancreate,
- $server,$settings,$emailusername,$courseid,$usertype) = @_;
- my $output;
+ $server,$settings,$emailusername,$courseid,$usertype,$usernameset,
+ $condition) = @_;
+ my ($output,$uname);
if (ref($cancreate) eq 'ARRAY') {
if (!grep(/^email$/,@{$cancreate})) {
$output = &invalid_state('noemails',$domdesc,
@@ -659,13 +742,37 @@
return $output;
} else {
$useremail =~ s/^\s+|\s+$//g;
- my $uname=&LONCAPA::clean_username($useremail);
- if ($useremail ne $uname) {
- $output = &invalid_state('badusername',$domdesc,
- $contact_name,$contact_email);
- return $output;
+ my $possuname;
+ if ($env{'form.username'}) {
+ $possuname = $env{'form.username'};
+ $possuname =~ s/^\s+|\s+$//g;
+ }
+ if (($usernameset) && ($possuname ne '')) {
+ if ($condition ne '') {
+ if ($useremail =~ /\Q$condition\E/) {
+ $uname = &LONCAPA::clean_username($possuname);
+ } else {
+ $output = &invalid_state('emailfail',$domdesc,
+ $contact_name,$contact_email);
+ return $output;
+ }
+ } else {
+ $uname=&LONCAPA::clean_username($possuname);
+ }
+ if ($uname ne $possuname) {
+ $output = &invalid_state('badusername',$domdesc,
+ $contact_name,$contact_email);
+ return $output;
+ }
+ } else {
+ $uname=&LONCAPA::clean_username($useremail);
+ if ($useremail ne $uname) {
+ $output = &invalid_state('badusername',$domdesc,
+ $contact_name,$contact_email);
+ return $output;
+ }
}
- my $uhome = &Apache::lonnet::homeserver($useremail,$domain);
+ my $uhome = &Apache::lonnet::homeserver($uname,$domain);
if ($uhome ne 'no_host') {
$output = &invalid_state('existinguser',$domdesc,
$contact_name,$contact_email);
@@ -678,29 +785,32 @@
return $output;
}
my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts);
- &call_rulecheck($useremail,$domain,\%alerts,\%rulematch,
+ &call_rulecheck($uname,$domain,\%alerts,\%rulematch,
\%inst_results,\%curr_rules,\%got_rules,'username');
if (ref($alerts{'username'}) eq 'HASH') {
if (ref($alerts{'username'}{$domain}) eq 'HASH') {
- if ($alerts{'username'}{$domain}{$useremail}) {
+ if ($alerts{'username'}{$domain}{$uname}) {
$output = &invalid_state('userrules',$domdesc,
$contact_name,$contact_email);
return $output;
}
}
}
- my $format_msg =
- &guest_format_check($useremail,$domain,$cancreate,
- $settings);
- if ($format_msg) {
- $output = &invalid_state('userformat',$domdesc,$contact_name,
- $contact_email,$format_msg);
- return $output;
+ if (($usernameset) && ($possuname ne '')) {
+ my $format_msg =
+ &guest_format_check($useremail,$domain,$cancreate,
+ $settings);
+ if ($format_msg) {
+ $output = &invalid_state('userformat',$domdesc,$contact_name,
+ $contact_email,$format_msg);
+ return $output;
+ }
}
}
}
$output = &send_token($domain,$useremail,$server,$domdesc,$contact_name,
- $contact_email,$courseid,$emailusername,$usertype);
+ $contact_email,$courseid,$emailusername,$usertype,
+ $uname);
}
return $output;
}
@@ -721,7 +831,7 @@
sub send_token {
my ($domain,$email,$server,$domdesc,$contact_name,$contact_email,$courseid,$emailusername,
- $usertype) = @_;
+ $usertype,$uname) = @_;
my $msg = '<h3>'.&mt('Account creation status').'</h3>'.
&mt('Thank you for your request to create a new LON-CAPA account.').
'<br /><br />';
@@ -747,18 +857,21 @@
'upass' => $env{'form.upass'},
'serverid' => $env{'form.serverid'},
'tmpinfo' => $tmpinfo);
-
+ if ($uname ne '') {
+ $info{'username'} = $uname;
+ $info{'email'} = $email;
+ }
if (ref($emailusername) eq 'HASH') {
if (ref($emailusername->{$usertype}) eq 'HASH') {
foreach my $item (keys(%{$emailusername->{$usertype}})) {
$info{$item} = $env{'form.'.$item};
$info{$item} =~ s/(`)//g;
}
- unless ($usertype eq 'default') {
- $info{'inststatus'} = $usertype;
- }
}
}
+ if ($usertype ne '') {
+ $info{'usertype'} = $usertype;
+ }
my $token = &Apache::lonnet::tmpput(\%info,$server,'createaccount');
if ($token !~ /^error/ && $token ne 'no_such_host') {
my $esc_token = &escape($token);
@@ -792,7 +905,7 @@
sub process_mailtoken {
my ($r,$token,$contact_name,$contact_email,$domain,$domdesc,$lonhost,
- $include,$start_page,$cancreate,$settings,$usertype) = @_;
+ $include,$start_page,$cancreate,$settings,$types) = @_;
my ($msg,$nostart,$noend,$redirect);
my %data = &Apache::lonnet::tmpget($token);
my $now = time;
@@ -805,12 +918,33 @@
}
if (($data{'time'} =~ /^\d+$/) &&
($data{'domain'} ne '') &&
- ($data{'username'} =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/)) {
+ ((($data{'email'} =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/) && ($data{'username'} =~ /^$match_username$/)) ||
+ ($data{'username'} =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/))) {
if ($now - $data{'time'} < 7200) {
# Check if request should be queued.
if (ref($cancreate) eq 'ARRAY') {
- my $disposition;
+ my ($disposition,$usertype);
if (grep(/^email$/,@{$cancreate})) {
+ if (exists($data{'usertype'})) {
+ $usertype = $data{'usertype'};
+ my @posstypes;
+ if (ref($types) eq 'ARRAY') {
+ @posstypes = @{$types};
+ if (@posstypes) {
+ unless (grep(/^default$/, at posstypes)) {
+ push(@posstypes,'default');
+ }
+ }
+ if (grep(/\Q$usertype\E/, at posstypes)) {
+ unless ($usertype eq 'default') {
+ $data{'inststatus'} = $usertype;
+ }
+ } else {
+ undef($usertype);
+ }
+ }
+ delete($data{'usertype'});
+ }
if (ref($settings) eq 'HASH') {
if (ref($settings->{'cancreate'}) eq 'HASH') {
if (ref($settings->{'cancreate'}{'selfcreateprocessing'}) eq 'HASH') {
@@ -893,14 +1027,15 @@
#
sub print_dataentry_form {
my ($r,$domain,$lonhost,$include,$now,$captchaform,$courseid,$emailusername,$captcha,
- $usertype,$recaptchaversion) = @_;
+ $usertype,$recaptchaversion,$usernameset,$condition) = @_;
my ($error,$output);
if (open(my $jsh,"<$include/londes.js")) {
while(my $line = <$jsh>) {
$r->print($line);
}
close($jsh);
- $output = &javascript_setforms($now,$emailusername,$captcha,$usertype,$recaptchaversion).
+ $output = &javascript_setforms($now,$emailusername,$captcha,$usertype,$recaptchaversion,
+ $usernameset,$condition).
"\n".&javascript_checkpass($now,'email');
my ($lkey,$ukey) = &Apache::loncommon::des_keys();
my ($lextkey,$uextkey) = &getkeys($lkey,$ukey);
@@ -916,7 +1051,6 @@
foreach my $field (sort(keys(%{$emailusername->{$usertype}}))) {
$output .= '<input type="hidden" name="'.$field.'" value="" />'."\n";
}
- $output .= '<input type="hidden" name="type" value="" />'."\n";
}
}
if ($captcha eq 'original') {
@@ -935,6 +1069,13 @@
';
}
}
+ if ($usertype ne '') {
+ $output .= '<input type="hidden" name="type" value="'.
+ &HTML::Entities::encode($usertype,'\'<>"&').'" />'."\n";
+ }
+ if ($usernameset) {
+ $output .= '<input type="hidden" name="username" value="" />'."\n";
+ }
$output .= <<"ENDSERVERFORM";
<input type="hidden" name="logtoken" value="$logtoken" />
<input type="hidden" name="serverid" value="$lonhost" />
@@ -955,7 +1096,8 @@
my ($datatable,$rowcount) =
&Apache::loncreateuser::personal_data_display('',$domain,'email','selfcreate',
'','',$now,$captchaform,
- $emailusername,$usertype);
+ $emailusername,$usertype,
+ $usernameset,$condition);
if ($rowcount) {
$output .= '<div class="LC_left_float">'.$beginclientform.$datatable.$endclientform;
} else {
@@ -977,14 +1119,15 @@
sub get_creation_controls {
my ($domain,$usercreation) = @_;
- my (@cancreate, at statustocreate,$emailusername);
+ my (@cancreate, at statustocreate, at statusforemail,$emailusername,$processing,
+ $verification,$emaildomain,$othertitle,$usertypes,$types);
if (ref($usercreation) eq 'HASH') {
if (ref($usercreation->{'cancreate'}) eq 'HASH') {
+ ($othertitle,$usertypes,$types) =
+ &Apache::loncommon::sorted_inst_types($domain);
if (ref($usercreation->{'cancreate'}{'statustocreate'}) eq 'ARRAY') {
@statustocreate = @{$usercreation->{'cancreate'}{'statustocreate'}};
if (@statustocreate == 0) {
- my ($othertitle,$usertypes,$types) =
- &Apache::loncommon::sorted_inst_types($domain);
if (ref($types) eq 'ARRAY') {
if (@{$types} == 0) {
@statustocreate = ('default');
@@ -995,8 +1138,6 @@
}
} else {
@statustocreate = ('default');
- my ($othertitle,$usertypes,$types) =
- &Apache::loncommon::sorted_inst_types($domain);
if (ref($types) eq 'ARRAY') {
push(@statustocreate,@{$types});
}
@@ -1007,6 +1148,45 @@
($usercreation->{'cancreate'}{'selfcreate'} ne '')) {
@cancreate = ($usercreation->{'cancreate'}{'selfcreate'});
}
+ if (grep(/^email$/, at cancreate)) {
+ if (ref($usercreation->{'cancreate'}{'selfcreateprocessing'}) eq 'HASH') {
+ $processing = $usercreation->{'cancreate'}{'selfcreateprocessing'};
+ }
+ if (ref($usercreation->{'cancreate'}{'emailverified'}) eq 'HASH') {
+ $verification = $usercreation->{'cancreate'}{'emailverified'};
+ }
+ if (ref($usercreation->{'cancreate'}{'emaildomain'}) eq 'HASH') {
+ $emaildomain = $usercreation->{'cancreate'}{'emaildomain'};
+ }
+ if (ref($processing)) {
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
+ my @emailtypes;
+ if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
+ @emailtypes = @{$domdefaults{'inststatusguest'}};
+ if (@emailtypes) {
+ unless (grep(/^default$/, at emailtypes)) {
+ push(@emailtypes,'default');
+ }
+ foreach my $type (@emailtypes) {
+ if ($processing->{$type} ne 'notinuse') {
+ unless (grep(/^$type$/, at statusforemail)) {
+ push(@statusforemail,$type);
+ }
+ }
+ }
+ unless (@statusforemail) {
+ my @okcreate;
+ foreach my $poss (@cancreate) {
+ unless ($poss eq 'email') {
+ push(@okcreate,$poss);
+ }
+ }
+ @cancreate = @okcreate;
+ }
+ }
+ }
+ }
+ }
if (ref($usercreation->{'cancreate'}{'emailusername'}) eq 'HASH') {
$emailusername = $usercreation->{'cancreate'}{'emailusername'};
} else {
@@ -1019,7 +1199,8 @@
}
}
}
- return (\@cancreate,\@statustocreate,$emailusername);
+ return (\@cancreate,\@statustocreate,\@statusforemail,$emailusername,
+ $verification,$emaildomain,$types,$usertypes,$othertitle);
}
sub create_account {
@@ -1032,7 +1213,7 @@
my $output;
if (ref($dataref) eq 'HASH') {
my ($username,$encpass,$serverid,$courseid,$id,$firstname,$middlename,$lastname,
- $generation,$inststatus);
+ $generation,$inststatus,$permanentemail);
$username = $dataref->{'username'};
$encpass = $dataref->{'upass'};
$serverid = $dataref->{'serverid'};
@@ -1044,6 +1225,11 @@
$generation = $dataref->{'generation'};
$inststatus = $dataref->{'inststatus'};
+ if ($dataref->{'email'} ne '') {
+ $permanentemail = $dataref->{'email'};
+ } else {
+ $permanentemail = $dataref->{'username'};
+ }
my $currhome = &Apache::lonnet::homeserver($username,$domain);
unless ($currhome eq 'no_host') {
$output = &mt('User account requested for username: [_1] in domain: [_2] already exists.',$username,$domain);
@@ -1075,7 +1261,7 @@
my $result =
&Apache::lonnet::modifyuser($domain,$username,$id,
'internal',$upass,$firstname,$middlename,
- $lastname,$generation,undef,undef,$username);
+ $lastname,$generation,undef,undef,$permanentemail);
$output = &mt('Generating user: [_1]',$result);
# Now that the user account exists, retrieve the homeserver, and include it in the output.
@@ -1465,6 +1651,8 @@
$msg .= &mt('Validation of the code you entered failed.');
} elsif ($error eq 'noemails') {
$msg .= &mt('Creation of a new user account using an e-mail address as username is not permitted at this LON-CAPA institution.');
+ } elsif ($error eq 'emailfail') {
+ $msg .= &mt('Creation of a new user account with verification by e-mail is not permitted with the e-mail address you provided');
}
$msg .= '</span>';
if ($msgtext) {
@@ -1709,4 +1897,98 @@
}
+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";
+<script type="text/javascript">
+// <![CDATA[
+
+function setElements() {
+ if (document.getElementById('LC_reportstatus')) {
+ var reportnum = document.reportstatus.type.length;
+ if ((reportnum != 'undefined') && (typeof(document.reportstatus.type) != 'undefined')) {
+ for (var i=0; i<reportnum; i++) {
+ document.reportstatus.type[i].checked = false;
+ }
+ }
+ }
+}
+
+function checkVerification() {
+ var curr;
+ var cancreate = false;
+ var reportnum = document.reportstatus.type.length;
+ if ((reportnum == 'undefined') && (typeof(document.reportstatus.type) != 'undefined')) {
+ curr = document.reportstatus.type.value;
+ } else if (document.reportstatus.type.length) {
+ for (var i=0; i<document.reportstatus.type.length; i++) {
+ if (document.reportstatus.type[i].checked) {
+ curr = document.reportstatus.type[i].value;
+ break;
+ }
+ }
+ }
+ var types = Array('$posstypes');
+ var names = Array('$posstypesnames');
+ var available = Array('$availabletypes');
+ if (available.length) {
+ for (var i=0; i<available.length; i++) {
+ if (curr == available[i]) {
+ cancreate = true;
+ break;
+ }
+ }
+ }
+ if (types.length > 0) {
+ for (var j=0; j<types.length; j++) {
+ if (curr == types[j]) {
+ if (!cancreate) {
+ alert('Creation of an account via verification by e-mail unavailable for user type: "'+names[j]+'"');
+ }
+ break;
+ }
+ }
+ }
+ if (cancreate) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+// ]]>
+</script>
+ENDSCRIPT
+
+}
+
+sub username_js {
+ return <<"ENDSCRIPT";
+<script type="text/javascript">
+// <![CDATA[
+
+function toggleDisplay(caller,divid) {
+ if (document.getElementById(divid)) {
+ if (caller.checked) {
+ if (caller.value == '1') {
+ document.getElementById(divid).style.display = 'none';
+ } else {
+ document.getElementById(divid).style.display = 'inline';
+ }
+ }
+ }
+}
+// ]]>
+</script>
+ENDSCRIPT
+
+}
+
1;
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.302 loncom/interface/domainprefs.pm:1.303
--- loncom/interface/domainprefs.pm:1.302 Tue Jul 18 16:03:08 2017
+++ loncom/interface/domainprefs.pm Wed Jul 26 19:45:45 2017
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.302 2017/07/18 16:03:08 raeburn Exp $
+# $Id: domainprefs.pm,v 1.303 2017/07/26 19:45:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -281,7 +281,7 @@
{col1 => 'Internal Authentication',
col2 => 'Value'},
{col1 => 'Institutional user types',
- col2 => 'Assignable to e-mail usernames'}],
+ col2 => 'Assignable to non-institutional users'}],
print => \&print_defaults,
modify => \&modify_defaults,
},
@@ -363,7 +363,7 @@
col2 => 'Enabled?'},
{col1 => 'Institutional user type (login/SSO self-creation)',
col2 => 'Information user can enter'},
- {col1 => 'Self-creation with e-mail as username',
+ {col1 => 'Self-creation with e-mail verification',
col2 => 'Settings'}],
print => \&print_selfcreation,
modify => \&modify_selfcreation,
@@ -5752,7 +5752,7 @@
sub print_selfcreation {
my ($position,$dom,$settings,$rowtotal) = @_;
- my (@selfcreate,$createsettings,$processing,$datatable);
+ my (@selfcreate,$createsettings,$processing,$emailverified,$emaildomain,$datatable);
if (ref($settings) eq 'HASH') {
if (ref($settings->{'cancreate'}) eq 'HASH') {
$createsettings = $settings->{'cancreate'};
@@ -5769,6 +5769,12 @@
if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
$processing = $createsettings->{'selfcreateprocessing'};
}
+ if (ref($createsettings->{'emailverified'}) eq 'HASH') {
+ $emailverified = $createsettings->{'emailverified'};
+ }
+ if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
+ $emaildomain = $createsettings->{'emaildomain'};
+ }
}
}
}
@@ -5859,7 +5865,7 @@
}
} else {
my %choices = &Apache::lonlocal::texthash (
- cancreate_email => 'E-mail address as username',
+ cancreate_email => 'Non-institutional username (e-mail verification)',
);
my @toggles = sort(keys(%choices));
my %defaultchecked = (
@@ -5891,16 +5897,27 @@
$usertypeshash{'default'} = $othertitle;
$additional .= '<table><tr>';
foreach my $status (@ordered) {
- $additional .= '<th>'.$usertypeshash{$status}.'</th>';
+ $additional .= '<th align="center">'.$usertypeshash{$status}.'</th>';
+ }
+ $additional .= '</tr><tr>';
+ foreach my $status (@ordered) {
+ $additional .= '<td align="left" valign="top">'.&validate_by_email($rowtotal,$processing,$status).'</td>';
+ }
+ $additional .= '</tr></table><br />'.
+ '<table><tr>';
+ foreach my $status (@ordered) {
+ $additional .= '<th align="center">'.$usertypeshash{$status}.'</th>';
}
$additional .= '</tr><tr>';
foreach my $status (@ordered) {
- $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
+ $additional .= '<td align="left" valign="top">'.&email_as_username($rowtotal,$emailverified,$emaildomain,$status).'</td>';
}
$additional .= '</tr></table>';
+
} else {
$usertypeshash{'default'} = $othertitle;
- $additional .= &email_as_username($rowtotal,$processing);
+ $additional .= &mt('Approval:').' '.&validate_by_email($rowtotal,$processing).'<br />'.
+ &mt('Username:').' '.&email_as_username($rowtotal,$emailverified,$emaildomain);
}
$additional .= '</div>'."\n";
@@ -5930,15 +5947,20 @@
return $datatable;
}
-sub email_as_username {
+sub validate_by_email {
my ($rowtotal,$processing,$type) = @_;
my %choices =
&Apache::lonlocal::texthash (
automatic => 'Automatic approval',
approval => 'Queued for approval',
+ notinuse => 'Unavailable',
);
my $output;
- foreach my $option ('automatic','approval') {
+ my @options = ('automatic','approval');
+ unless ($type eq '') {
+ push(@options,'notinuse');
+ }
+ foreach my $option (@options) {
my $checked;
if (ref($processing) eq 'HASH') {
if ($type eq '') {
@@ -5983,6 +6005,83 @@
return $output;
}
+sub email_as_username {
+ my ($rowtotal,$emailverified,$emaildomain,$type) = @_;
+ my %choices =
+ &Apache::lonlocal::texthash (
+ email => 'Username is e-mail',
+ other => 'Username is chosen',
+ );
+ my $name = 'cancreate_emailverified';
+ my $condition = 'cancreate_emaildomain';
+ if (($type ne '') && ($type ne 'default')) {
+ $name .= '_'.$type;
+ $condition .= '_'.$type;
+ }
+ my $display = 'none';
+ my $onclick = "toggleDisplay(this.form,'$name');";
+
+ my $output;
+ foreach my $option ('email','other') {
+ my ($checked,$domain);
+ if (ref($emailverified) eq 'HASH') {
+ if ($type eq '') {
+ if (!exists($emailverified->{'default'})) {
+ if ($option eq 'email') {
+ $checked = ' checked="checked"';
+ }
+ } else {
+ if ($emailverified->{'default'} eq $option) {
+ $checked = ' checked="checked"';
+ }
+ }
+ } else {
+ if (!exists($emailverified->{$type})) {
+ if ($option eq 'email') {
+ $checked = ' checked="checked"';
+ }
+ } else {
+ if ($emailverified->{$type} eq $option) {
+ $checked = ' checked="checked"';
+ if ($option eq 'other') {
+ $display = 'inline';
+ }
+ }
+ }
+ }
+ } elsif ($option eq 'email') {
+ $checked = ' checked="checked"';
+ }
+ $output .= '<span class="LC_nobreak"><label>'.
+ '<input type="radio" name="'.$name.'"'.
+ $checked.' value="'.$option.'" onclick="'.$onclick.'" />'.
+ $choices{$option}.'</label></span>';
+ if ($type eq '') {
+ $output .= ' ';
+ } else {
+ $output .= '<br />';
+ }
+ }
+ my $domain;
+ if (ref($emaildomain) eq 'HASH') {
+ if ($type eq '') {
+ if (exists($emaildomain->{'default'})) {
+ $domain = $emaildomain->{'default'};
+ }
+ } else {
+ if (exists($emaildomain->{$type})) {
+ $domain = $emaildomain->{$type};
+ }
+ }
+ }
+ $output .= '<div id="'.$name.'" style="display: '.$display.';">'.
+ '<span class="LC_domprefs_email">'.&mt('E-mail domain').'</span> '.
+ '<input type="text" name="'.$condition.'" value="'.$domain.'" size="10" />'.
+ '</div>';
+ $$rowtotal ++;
+ return $output;
+}
+
sub captcha_choice {
my ($context,$settings,$itemcount) = @_;
my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
@@ -10959,12 +11058,10 @@
if ($key eq 'cancreate') {
if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
- if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
- ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
- ($item eq 'recaptchaversion')) {
- $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
- } else {
+ if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
$curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
+ } else {
+ $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
}
}
}
@@ -11169,12 +11266,18 @@
sub modify_selfcreation {
my ($dom,%domconfig) = @_;
my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
- my (%save_usercreate,%save_usermodify);
- my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
- if (ref($types) eq 'ARRAY') {
- $usertypes->{'default'} = $othertitle;
- push(@{$types},'default');
+ my (%save_usercreate,%save_usermodify, at types,%usertypes);
+ my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
+ if (ref($typesref) eq 'ARRAY') {
+ @types = @{$typesref};
+ }
+ unless (grep(/^default$/, at types)) {
+ push(@types,'default');
}
+ if (ref($usertypesref) eq 'HASH') {
+ %usertypes = %{$usertypesref};
+ }
+ $usertypes{'default'} = $othertitle;
#
# Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
#
@@ -11184,10 +11287,11 @@
if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
- ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
- ($item eq 'recaptchaversion') ||
- ($item eq 'emailusername') || ($item eq 'notify') ||
- ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
+ ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
+ ($item eq 'recaptchaversion') || ($item eq 'notify') ||
+ ($item eq 'emailusername') || ($item eq 'shibenv') ||
+ ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
+ ($item eq 'emaildomain')) {
$curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
} else {
$save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
@@ -11220,10 +11324,12 @@
@{$cancreate{'statustocreate'}} = ();
%{$cancreate{'selfcreateprocessing'}} = ();
%{$cancreate{'shibenv'}} = ();
+ %{$cancreate{'emailverified'}} = ();
+ %{$cancreate{'emaildomain'}} = ();
my %selfcreatetypes = (
sso => 'users authenticated by institutional single sign on',
login => 'users authenticated by institutional log-in',
- email => 'users who provide a valid e-mail address for use as username',
+ email => 'users verified by e-mail',
);
#
# Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
@@ -11242,12 +11348,22 @@
if ($item eq 'email') {
if ($env{'form.cancreate_email'}) {
push(@{$cancreate{'selfcreate'}},'email');
- push(@contexts,'selfcreateprocessing');
+ push(@contexts,('selfcreateprocessing','emailverified','emaildomain'));
foreach my $type (@statuses) {
if ($type eq 'default') {
$cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
+ unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {
+ $cancreate{'emailverified'}{$type} = $env{'form.cancreate_emailverified'};
+ if ($cancreate{'emailverified'}{$type} eq 'other') {
+ $cancreate{'emaildomain'}{$type} =$env{'form.cancreate_emaildomain'};
+ }
+ }
} else {
$cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
+ $cancreate{'emailverified'}{$type} = $env{'form.cancreate_emailverified_'.$type};
+ if ($cancreate{'emailverified'}{$type} eq 'other') {
+ $cancreate{'emaildomain'}{$type} =$env{'form.cancreate_emaildomain_'.$type};
+ }
}
}
}
@@ -11266,8 +11382,8 @@
if ($env{'form.cancreate_email'}) {
push(@contexts,'emailusername');
- if (ref($types) eq 'ARRAY') {
- foreach my $type (@{$types}) {
+ if (@types) {
+ foreach my $type (@types) {
if (ref($infofields) eq 'ARRAY') {
foreach my $field (@{$infofields}) {
if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
@@ -11279,7 +11395,7 @@
}
#
# Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
-# queued requests for self-creation of account using e-mail address as username
+# queued requests for self-creation of account verified by e-mail.
#
my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
@@ -11300,7 +11416,7 @@
}
#
-# Retrieve rules (if any) governing types of e-mail address which may be used as a username
+# Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
#
@email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
&process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
@@ -11347,14 +11463,14 @@
# which the user may supply, if institutional data is unavailable.
#
if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
- if (ref($types) eq 'ARRAY') {
- if (@{$types} > 1) {
+ if (@types) {
+ if (@types > 1) {
@{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
push(@contexts,'statustocreate');
} else {
undef($cancreate{'statustocreate'});
}
- foreach my $type (@{$types}) {
+ foreach my $type (@types) {
my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
foreach my $field (@fields) {
if (grep(/^\Q$field\E$/, at modifiable)) {
@@ -11365,7 +11481,7 @@
}
}
if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
- foreach my $type (@{$types}) {
+ foreach my $type (@types) {
if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
foreach my $field (@fields) {
if ($save_usermodify{'selfcreate'}{$type}{$field} ne
@@ -11377,7 +11493,7 @@
}
}
} else {
- foreach my $type (@{$types}) {
+ foreach my $type (@types) {
push(@{$changes{'selfcreate'}},$type);
}
}
@@ -11435,7 +11551,7 @@
}
}
}
- } elsif ($item eq 'selfcreateprocessing') {
+ } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emaildomain')) {
if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
push(@{$changes{'cancreate'}},$item);
@@ -11523,6 +11639,12 @@
if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
$save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
}
+ if (ref($cancreate{'emailverified'}) eq 'HASH') {
+ $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
+ }
+ if (ref($cancreate{'emaildomain'}) eq 'HASH') {
+ $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
+ }
if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
$save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
}
@@ -11547,7 +11669,7 @@
if (ref($changes{'cancreate'}) eq 'ARRAY') {
my %lt = &selfcreation_types();
foreach my $type (@{$changes{'cancreate'}}) {
- my $chgtext;
+ my $chgtext = '';
if ($type eq 'selfcreate') {
if (@{$cancreate{$type}} == 0) {
$chgtext .= &mt('Self creation of a new user account is not permitted.');
@@ -11562,10 +11684,25 @@
if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
if (@{$cancreate{'statustocreate'}} == 0) {
- $chgtext .= '<br />'.
- '<span class="LC_warning">'.
- &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
- '</span>';
+ $chgtext .= '<span class="LC_warning">'.
+ &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
+ '</span><br />';
+ }
+ }
+ }
+ if (grep(/^email$/,@{$cancreate{$type}})) {
+ if (@statuses > 1) {
+ my $numtypes = 0;
+ foreach my $type (@statuses) {
+ unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {
+ $numtypes ++;
+ }
+ }
+ if (!$numtypes) {
+ $chgtext .= '<span class="LC_warning">'.
+ &mt("However, e-mail verification is currently set to 'unavailable' for all user types (including 'other'), so self-creation of accounts is not possible for non-institutional log-in.").
+ '</span><br />';
+
}
}
}
@@ -11573,7 +11710,7 @@
}
} elsif ($type eq 'shibenv') {
if (keys(%{$cancreate{$type}}) == 0) {
- $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
+ $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
} else {
$chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
'<ul>';
@@ -11586,7 +11723,7 @@
}
}
$chgtext .= '</ul>';
- }
+ }
} elsif ($type eq 'statustocreate') {
if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
(ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
@@ -11599,7 +11736,7 @@
&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
'</span>';
}
- } elsif (ref($usertypes) eq 'HASH') {
+ } elsif (keys(%usertypes) > 0) {
if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
$chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
} else {
@@ -11610,12 +11747,12 @@
if ($case eq 'default') {
$chgtext .= '<li>'.$othertitle.'</li>';
} else {
- $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
+ $chgtext .= '<li>'.$usertypes{$case}.'</li>';
}
}
$chgtext .= '</ul>';
if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
- $chgtext .= '<br /><span class="LC_warning">'.
+ $chgtext .= '<span class="LC_warning">'.
&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
'</span>';
}
@@ -11627,26 +11764,109 @@
$chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
}
}
+ $chgtext .= '<br />';
}
} elsif ($type eq 'selfcreateprocessing') {
my %choices = &Apache::lonlocal::texthash (
automatic => 'Automatic approval',
approval => 'Queued for approval',
+ notinuse => 'Unavailable',
);
if (@statuses > 1) {
- $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
- '<ul>';
- foreach my $type (@statuses) {
- if ($type eq 'default') {
- $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
- } else {
- $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
- }
- }
- $chgtext .= '</ul>';
+ my $numtypes = 0;
+ foreach my $type (@statuses) {
+ unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {
+ $numtypes ++;
+ }
+ }
+ if ($numtypes) {
+ $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
+ '<ul>';
+ foreach my $type (@statuses) {
+ if ($type eq 'default') {
+ $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
+ } else {
+ $chgtext .= '<li>'.$usertypes{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
+ }
+ }
+ $chgtext .= '</ul>';
+ }
} else {
- $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
- $choices{$cancreate{'selfcreateprocessing'}{'default'}});
+ $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
+ $choices{$cancreate{'selfcreateprocessing'}{'default'}});
+ }
+ } elsif ($type eq 'emailverified') {
+ my %options = &Apache::lonlocal::texthash (
+ email => 'Username is e-mail',
+ other => 'Username is chosen',
+ );
+ if (@statuses > 1) {
+ my $numtypes = 0;
+ foreach my $type (@statuses) {
+ unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {
+ $numtypes ++;
+ }
+ }
+ if ($numtypes) {
+ $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
+ '<ul>';
+ foreach my $type (@statuses) {
+ next if ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse');
+ if ($type eq 'default') {
+ $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$type}}.'</li>';
+ } else {
+ $chgtext .= '<li>'.$usertypes{$type}.' -- '.$options{$cancreate{'emailverified'}{$type}}.'</li>';
+ }
+ }
+ $chgtext .= '</ul>';
+ }
+ } else {
+ $chgtext .= &mt('For self-created accounts verified by e-mail address: "[_1]"',
+ $choices{$cancreate{'emailverified'}{'default'}});
+ }
+ } elsif ($type eq 'emaildomain') {
+ if (@statuses > 1) {
+ my $numtypes = 0;
+ foreach my $type (@statuses) {
+ unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {
+ if ($cancreate{'emailverified'}{$type} eq 'other') {
+ $numtypes ++;
+ }
+ }
+ }
+ if ($numtypes) {
+ $chgtext .= &mt('For self-created accounts verified by e-mail address, with username chosen by user ...').
+ '<ul>';
+ foreach my $type (@statuses) {
+ next if (($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') ||
+ ($cancreate{'emailverified'}{$type} eq 'email'));
+ if ($type eq 'default') {
+ if ($cancreate{'emaildomain'}{$type} eq '') {
+ $chgtext .= '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
+ } else {
+ $chgtext .= '<li>'.$othertitle.' -- '.&mt("User's e-mail domain needs to be: [_1]",
+ $cancreate{'emaildomain'}{$type}).'</li>';
+ }
+ } else {
+ if ($cancreate{'emaildomain'}{$type} eq '') {
+ $chgtext .= '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
+ } else {
+ $chgtext .= '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail domain needs to be: [_1]",
+ $cancreate{'emaildomain'}{$type}).'</li>';
+ }
+ }
+ }
+ $chgtext .= '</ul>';
+ }
+ } else {
+ if ($cancreate{'emailverified'}{'default'} eq 'other') {
+ if ($cancreate{'emaildomain'}{'default'} eq '') {
+ $chgtext .= &mt('No restriction on e-mail domain for self-created accounts verified by e-mail address, where username is chosen by user.');
+ } else {
+ $chgtext .= &mt('For self-created accounts verified by e-mail address, where username is chosen by user, e-mail domain needs to be: [_1],
+ $cancreate{'selfcreateprocessing'}{'default'});
+ }
+ }
}
} elsif ($type eq 'captcha') {
if ($savecaptcha{$type} eq 'notused') {
@@ -11683,11 +11903,11 @@
}
} elsif ($type eq 'emailusername') {
if (ref($cancreate{'emailusername'}) eq 'HASH') {
- if (ref($types) eq 'ARRAY') {
- foreach my $type (@{$types}) {
+ if (@types) {
+ foreach my $type (@types) {
if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
- $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
+ $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
'<ul>';
foreach my $field (@{$infofields}) {
if ($cancreate{'emailusername'}{$type}{$field}) {
@@ -11696,23 +11916,27 @@
}
$chgtext .= '</ul>';
} else {
- $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
+ $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
}
} else {
- $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
+ $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
}
}
}
}
} elsif ($type eq 'notify') {
- $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
+ my $numapprove = 0;
if (ref($changes{'cancreate'}) eq 'ARRAY') {
if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
if ($cancreate{'notify'}{'approval'}) {
- $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
+ $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
+ $numapprove ++;
}
}
}
+ unless ($numapprove) {
+ $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
+ }
}
if ($chgtext) {
$resulttext .= '<li>'.$chgtext.'</li>';
@@ -11731,12 +11955,12 @@
$chgtext .= '</ul>';
if (@email_rule > 0) {
$resulttext .= '<li>'.
- &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
+ &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ').
$chgtext.
'</li>';
} else {
$resulttext .= '<li>'.
- &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
+ &mt('There are now no restrictions on e-mail addresses which may be used for verification when self-enrolling.').
'</li>';
}
}
@@ -11745,9 +11969,9 @@
my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
foreach my $type (@{$changes{'selfcreate'}}) {
my $typename = $type;
- if (ref($usertypes) eq 'HASH') {
- if ($usertypes->{$type} ne '') {
- $typename = $usertypes->{$type};
+ if (keys(%usertypes) > 0) {
+ if ($usertypes{$type} ne '') {
+ $typename = $usertypes{$type};
}
}
my @modifiable;
@@ -15248,6 +15472,7 @@
var optionsElement = domForm.coursecredits;
var checkval = 1;
var dispval = 'block';
+ var selfcreateRegExp = /^cancreate_emailverified/;
if (caller == 'emailoptions') {
optionsElement = domForm.cancreate_email;
}
@@ -15258,6 +15483,11 @@
optionsElement = domForm.canclone;
checkval = 'instcode';
}
+ if (selfcreateRegExp.test(caller)) {
+ optionsElement = domForm.elements[caller];
+ checkval = 'other';
+ dispval = 'inline'
+ }
if (optionsElement.length) {
var currval;
for (var i=0; i<optionsElement.length; i++) {
Index: loncom/interface/lonconfigsettings.pm
diff -u loncom/interface/lonconfigsettings.pm:1.33 loncom/interface/lonconfigsettings.pm:1.34
--- loncom/interface/lonconfigsettings.pm:1.33 Tue Oct 11 22:58:55 2016
+++ loncom/interface/lonconfigsettings.pm Wed Jul 26 19:45:45 2017
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: lonconfigsettings.pm,v 1.33 2016/10/11 22:58:55 raeburn Exp $
+# $Id: lonconfigsettings.pm,v 1.34 2017/07/26 19:45:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -40,7 +40,7 @@
use LONCAPA qw(:DEFAULT :match);
sub print_header {
- my ($r,$phase,$context,$jscript,$container) = @_;
+ my ($r,$phase,$context,$jscript,$container,$instcode,$dom) = @_;
my ($pagetitle,$brcrumtitle,$action,$call_category_check,$instcode_check,
$crstype, at actions, at code_order);
if ($phase eq 'display') {
@@ -177,11 +177,32 @@
$additem = {'add_entries' => \%loaditems,};
} elsif ($phase eq 'display') {
if ($context eq 'domain') {
+ my $onload;
if (grep(/^coursedefaults$/, at actions)) {
+ $onload = "toggleDisplay(document.display,'cloneinstcode');".
+ "toggleDisplay(document.display,'credits');".
+ "toggleDisplay(document.display,'studentsubmission');";
+ }
+ if (grep(/^selfcreation$/, at actions)) {
+ my $prefix = 'cancreate_emailverified';
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+ if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
+ my $order = $domdefaults{'inststatusguest'};
+ if (ref($order) eq 'ARRAY') {
+ foreach my $type (@{$order}) {
+ if (($type ne '') && ($type ne 'default')) {
+ my $name = $prefix.'_'.$type;
+ $onload .= "toggleDisplay(document.display,'$name');";
+ }
+ }
+ }
+ }
+ $onload .= "toggleDisplay(document.display,'$prefix');".
+ "toggleDisplay(document.display,'emailoptions');".
+ }
+ if ($onload) {
my %loaditems = (
- ' onload' => "toggleDisplay(document.display,'cloneinstcode');".
- "toggleDisplay(document.display,'credits');".
- "toggleDisplay(document.display,'studentsubmission');",
+ 'onload' => $onload;
);
$additem = {'add_entries' => \%loaditems,};
}
@@ -342,7 +363,7 @@
if (ref($values) eq 'HASH') {
$instcode = $values->{'internal.coursecode'};
}
- &print_header($r,$phase,$context,$jscript,$container,$instcode);
+ &print_header($r,$phase,$context,$jscript,$container,$instcode,$dom);
my $divwidth = 900;
if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) {
if (@actions > 0) {
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.441 loncom/interface/loncreateuser.pm:1.442
--- loncom/interface/loncreateuser.pm:1.441 Wed Jul 26 19:42:22 2017
+++ loncom/interface/loncreateuser.pm Wed Jul 26 19:45:45 2017
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.441 2017/07/26 19:42:22 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.442 2017/07/26 19:45:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2352,7 +2352,7 @@
sub personal_data_display {
my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
- $now,$captchaform,$emailusername,$usertype) = @_;
+ $now,$captchaform,$emailusername,$usertype,$usernameset,$condition) = @_;
my ($output,%userenv,%canmodify,%canmodify_status);
my @userinfo = ('firstname','middlename','lastname','generation',
'permanentemail','id');
@@ -2379,6 +2379,7 @@
'inststatus' => "Affiliation",
'email' => 'E-mail address',
'valid' => 'Validation',
+ 'username' => 'Username',
);
%canmodify_status =
@@ -2397,7 +2398,7 @@
if (ref($emailusername) eq 'HASH') {
if (ref($emailusername->{$usertype}) eq 'HASH') {
my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
- @userinfo = ();
+ @userinfo = ();
if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
foreach my $field (@{$infofields}) {
if ($emailusername->{$usertype}->{$field}) {
@@ -2427,9 +2428,16 @@
$output = '<h3>'.$lt{'pd'}.'</h3>'.
&Apache::lonhtmlcommon::start_pick_box();
if (($context eq 'selfcreate') && ($newuser eq 'email')) {
+ if ($condition) {
+ if ($condition =~ /[-\w]+\.[-\w]+$/) {
+ $condition = '@'.$condition;
+ } else {
+ undef($condition);
+ }
+ }
$output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
'LC_oddrow_value')."\n".
- '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
+ '<input type="text" name="uname" size="25" value="'.$condition.'" autocomplete="off" />';
$rowcount ++;
$output .= &Apache::lonhtmlcommon::row_closure(1);
my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
@@ -2444,6 +2452,19 @@
'LC_oddrow_value')."\n".
$upasstwo.
&Apache::lonhtmlcommon::row_closure()."\n";
+ if ($usernameset) {
+ my $onclick = "toggleDisplay(this,'selfcreateusername');";
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
+ &mt('Use e-mail address: ').
+ '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".
+ (' 'x2).
+ '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.&mt('No').'</label>'."\n".
+ '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
+ '<br /><span class="LC_nobreak">'.&mt('Preferred username').
+ ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
+ '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
+ $rowcount ++;
+ }
}
foreach my $item (@userinfo) {
my $rowtitle = $lt{$item};
@@ -4919,47 +4940,73 @@
unless ($usertype) {
$usertype = 'default';
}
+ my ($showstatus,$showemail,$pickstart);
+ my $numextras = 0;
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
+ if (ref($usertypes) eq 'HASH') {
+ if ($usertypes->{$usertype}) {
+ $showstatus = $usertypes->{$usertype};
+ } else {
+ $showstatus = $othertitle;
+ }
+ $numextras ++;
+ }
+ if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
+ $showemail = $info{$uname}{'email'};
+ $numextras ++;
+ }
if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
+ $pickstart = 1;
$r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
- my ($num,$count,$showstatus);
+ my ($num,$count);
$count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
- unless ($usertype eq 'default') {
- my ($othertitle,$usertypes,$types) =
- &Apache::loncommon::sorted_inst_types($dom);
- if (ref($usertypes) eq 'HASH') {
- if ($usertypes->{$usertype}) {
- $showstatus = $usertypes->{$usertype};
- $count ++;
- }
- }
- }
+ $count += $numextras;
foreach my $field (@{$infofields}) {
next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
next unless ($infotitles->{$field});
$r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
$info{$uname}{$field});
$num ++;
- if ($count == $num) {
- $r->print(&Apache::lonhtmlcommon::row_closure(1));
- } else {
+ unless ($count == $num) {
$r->print(&Apache::lonhtmlcommon::row_closure());
}
}
- if ($showstatus) {
- $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
- $showstatus.
- &Apache::lonhtmlcommon::row_closure(1));
+ }
+ }
+ if ($numextras) {
+ unless ($pickstart) {
+ $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
+ $pickstart = 1;
+ }
+ if ($showemail) {
+ my $closure = '';
+ unless ($showstatus) {
+ $closure = 1;
}
- $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
+ $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
+ $showemail.
+ &Apache::lonhtmlcommon::row_closure($closure));
}
+ if ($showstatus) {
+ $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
+ $showstatus.
+ &Apache::lonhtmlcommon::row_closure(1));
+ }
+ }
+ if ($pickstart) {
+ $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
+ } else {
+ $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
}
+ } else {
+ $r->print('<div>'.&mt('No information available for this account request.').'</div>');
}
}
}
}
- $r->print(&close_popup_form());
}
+ $r->print(&close_popup_form());
} elsif (($env{'form.action'} eq 'listusers') &&
($permission->{'view'} || $permission->{'cusr'})) {
my $helpitem = 'Course_View_Class_List';
More information about the LON-CAPA-cvs
mailing list