--- loncom/interface/createaccount.pm 2014/02/12 20:47:40 1.58
+++ loncom/interface/createaccount.pm 2014/05/05 21:28:10 1.65
@@ -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.58 2014/02/12 20:47:40 raeburn Exp $
+# $Id: createaccount.pm,v 1.65 2014/05/05 21:28:10 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -59,7 +59,7 @@ sub handler {
my $sso_domain = $r->subprocess_env->get('SSOUserDomain');
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['token','courseid','domain']);
+ ['token','courseid','domain','type']);
&Apache::lonacc::get_posted_cgi($r);
&Apache::lonlocal::get_language_handle($r);
@@ -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;
@@ -240,10 +269,11 @@ sub handler {
}
} elsif ($env{'form.create_with_email'}) {
&print_header($r,$start_page,$courseid);
+ my $usertype = &get_usertype($domain);
$output = &process_email_request($env{'form.uname'},$domain,$domdesc,
$contact_name,$contact_email,$cancreate,
$lonhost,$domconfig{'usercreation'},
- $emailusername,$courseid);
+ $emailusername,$courseid,$usertype);
} elsif (!$token) {
&print_header($r,$start_page,$courseid);
my $now=time;
@@ -258,11 +288,13 @@ sub handler {
$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);
+ $include,$courseid,$gotlondes,$emailusername,
+ $usertype);
}
$r->print($output);
&print_footer($r);
@@ -291,12 +323,28 @@ sub print_footer {
&Apache::lonhtmlcommon::echo_form_input(['backto','logtoken',
'token','serverid','uname','upass','phase','create_with_email',
'code','crypt','cfirstname','clastname',
+ 'recaptcha_challenge_field','recaptcha_response_field',
'cmiddlename','cgeneration','cpermanentemail','cid']).
'');
}
$r->print(&Apache::loncommon::end_page());
}
+sub get_usertype {
+ my ($domain) = @_;
+ my $usertype = 'default';
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($domain);
+ if (ref($types) eq 'ARRAY') {
+ push(@{$types},'default');
+ my $posstype = $env{'form.type'};
+ $posstype =~ s/^\s+|\s$//g;
+ if (grep(/^\Q$posstype\E$/,@{$types})) {
+ $usertype = $posstype;
+ }
+ }
+ return $usertype;
+}
+
sub selfenroll_crumbs {
my ($r,$courseid,$desc) = @_;
&Apache::lonhtmlcommon::add_breadcrumb
@@ -309,7 +357,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');
}
@@ -321,12 +369,50 @@ sub selfenroll_crumbs {
}
sub javascript_setforms {
- my ($now,$emailusername) = @_;
- my $setuserinfo;
+ my ($now,$emailusername,$captcha,$usertype) = @_;
+ my ($setuserinfo,@required,$requiredchk);
if (ref($emailusername) eq 'HASH') {
- foreach my $key (sort(keys(%{$emailusername}))) {
- $setuserinfo .= ' server.elements.'.$key.'.value=client.elements.'.$key.'.value;'."\n";
- }
+ if (ref($emailusername->{$usertype}) eq 'HASH') {
+ foreach my $key (sort(keys(%{$emailusername->{$usertype}}))) {
+ if ($emailusername->{$usertype}{$key} eq 'required') {
+ push(@required,$key);
+ }
+ $setuserinfo .= ' server.elements.'.$key.'.value=client.elements.'.$key.'.value;'."\n";
+ }
+ $setuserinfo .= ' server.elements.type.value=client.elements.type.value;'."\n";
+ }
+ if ($captcha eq 'original') {
+ $setuserinfo .= ' server.elements.code.value=client.elements.code.value;'."\n".
+ ' server.elements.crypt.value=client.elements.crypt.value;'."\n";
+ } elsif ($captcha eq 'recaptcha') {
+ $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.');
+ my $reqstr = join("','",@required);
+ $requiredchk = <<"ENDCHK";
+ var requiredfields = new Array('$reqstr');
+ missing = 0;
+ for (var i=0; i 0) {
+ alert("$missprompt");
+ return false;
+ }
+
+ENDCHK
}
my $js = <
@@ -338,13 +424,9 @@ sub javascript_setforms {
server = document.forms[one];
if (document.forms[two]) {
client = document.forms[two];
+$requiredchk
server.elements.uname.value = client.elements.uname.value;
server.elements.udom.value = client.elements.udom.value;
- if (context == 'email') {
- $setuserinfo
- }
- server.elements.code.value=client.elements.code.value;
- server.elements.crypt.value=client.elements.crypt.value;
uextkey=client.elements.uextkey.value;
lextkey=client.elements.lextkey.value;
@@ -355,7 +437,10 @@ sub javascript_setforms {
client.elements.uname.value='';
client.elements.upass$now.value='';
- client.elements.upasscheck$now.value='';
+ if (context == 'email') {
+$setuserinfo
+ client.elements.upasscheck$now.value='';
+ }
server.submit();
}
}
@@ -427,30 +512,37 @@ ENDSCRIPT
}
sub print_username_form {
- my ($r,$domain,$domdesc,$cancreate,$now,$lonhost,$include,$courseid,$gotlondes,$emailusername) = @_;
- my %lt = &Apache::lonlocal::texthash(
+ my ($r,$domain,$domdesc,$cancreate,$now,$lonhost,$include,$courseid,$gotlondes,$emailusername,
+ $usertype) = @_;
+ my %lt = &Apache::lonlocal::texthash (
unam => 'username',
udom => 'domain',
uemail => 'E-mail address in LON-CAPA',
- proc => 'Proceed');
+ 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).',
+ );
my $output;
if (ref($cancreate) eq 'ARRAY') {
if (grep(/^login$/,@{$cancreate})) {
my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
if ((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth')) {
- $output = '
'.&mt('Create account with a username provided by this institution').'
';
- my $submit_text = &mt('Create LON-CAPA account');
- $output .= &mt('If you already have a log-in ID at this institution,[_1] you may be able to use it for LON-CAPA.',' ').
+ $output = '
'.$lt{'crac'}.'
';
+ $output .= &mt('If you already have a log-in ID at this institution [_1]you may be able to use it for LON-CAPA.',' ').
'
'.
- &mt('Type in your log-in ID and password to find out.').
+ $lt{'type'}.
'