--- loncom/interface/createaccount.pm 2018/09/11 18:55:57 1.72.4.1
+++ loncom/interface/createaccount.pm 2017/07/26 19:45:45 1.73
@@ -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.4.1 2018/09/11 18:55:57 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 @@ 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,36 @@ 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,
+ $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 = '
'.&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 +197,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 +233,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 +255,21 @@ sub handler {
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,12 +304,13 @@ sub handler {
$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")) {
+ if (open(my $jsh,"<$include/londes.js")) {
while(my $line = <$jsh>) {
$r->print($line);
}
@@ -291,7 +323,9 @@ sub handler {
}
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 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;
}
@@ -329,7 +372,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 +409,7 @@ sub selfenroll_crumbs {
}
sub javascript_setforms {
- my ($now,$emailusername,$captcha,$usertype,$recaptchaversion) = @_;
+ my ($now,$emailusername,$captcha,$usertype,$recaptchaversion,$usernameset,$condition) = @_;
my ($setuserinfo,@required,$requiredchk);
if (ref($emailusername) eq 'HASH') {
if (ref($emailusername->{$usertype}) eq 'HASH') {
@@ -388,6 +431,10 @@ sub javascript_setforms {
' 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 @@ ENDSCRIPT
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 @@ sub print_username_form {
}
}
if (grep(/^email$/,@{$cancreate})) {
- $output .= '
'.&mt('Create account with an e-mail address as your username').'
';
- 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 .= ''.
- &mt('An error occurred generating the validation code[_1] required for an e-mail address to be used as username.',' ').
- '
'.
- &mt('[_1]Contact the helpdesk[_2] or [_3]reload[_2] the page and try again.',
- '','','');
+ $output .= '