--- loncom/interface/createaccount.pm 2014/04/19 20:48:43 1.63 +++ loncom/interface/createaccount.pm 2014/04/23 10:11:26 1.64 @@ -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.63 2014/04/19 20:48:43 raeburn Exp $ +# $Id: createaccount.pm,v 1.64 2014/04/23 10:11:26 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -187,10 +187,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; @@ -259,7 +260,7 @@ sub handler { $gotlondes = 1; } } - if (grep(/^email(|approval)$/,@{$cancreate})) { + if (grep(/^email$/,@{$cancreate})) { $r->print(&javascript_validmail()); } my $usertype = &get_usertype($domain); @@ -511,7 +512,7 @@ sub print_username_form { $domain,'createaccount').''; } } - if (grep(/^email(|approval)$/,@{$cancreate})) { + if (grep(/^email$/,@{$cancreate})) { $output .= '

'.&mt('Create account with an e-mail address as your username').'

'; my ($captchaform,$error,$captcha) = &Apache::loncommon::captcha_display('usercreation',$lonhost); if ($error) { @@ -612,7 +613,7 @@ sub process_email_request { $server,$settings,$emailusername,$courseid,$usertype) = @_; my $output; if (ref($cancreate) eq 'ARRAY') { - if (!grep(/^email(|approval)$/,@{$cancreate})) { + if (!grep(/^email$/,@{$cancreate})) { $output = &invalid_state('noemails',$domdesc, $contact_name,$contact_email); return $output; @@ -755,7 +756,7 @@ sub send_token { sub process_mailtoken { my ($r,$token,$contact_name,$contact_email,$domain,$domdesc,$lonhost, - $include,$start_page,$cancreate,$settings) = @_; + $include,$start_page,$cancreate,$settings,$usertype) = @_; my ($msg,$nostart,$noend,$redirect); my %data = &Apache::lonnet::tmpget($token); my $now = time; @@ -772,36 +773,46 @@ sub process_mailtoken { if ($now - $data{'time'} < 7200) { # Check if request should be queued. if (ref($cancreate) eq 'ARRAY') { + my $disposition; if (grep(/^email$/,@{$cancreate})) { - my ($result,$output,$uhome) = - &create_account($r,$domain,$domdesc,\%data); - if ($result eq 'ok') { - $msg = $output; - my $shownow = &Apache::lonlocal::locallocaltime($now); - my $mailmsg = &mt('A LON-CAPA account for the institution: [_1] has been created [_2] from IP address: [_3]. If you did not perform this action or authorize it, please contact the [_4] ([_5]).',$domdesc,$shownow,$ENV{'REMOTE_ADDR'},$contact_name,$contact_email)."\n"; - my $mailresult = &Apache::resetpw::send_mail($domdesc,$data{'email'}, - $mailmsg,$contact_name, - $contact_email); - if ($mailresult eq 'ok') { - $msg .= &mt('An e-mail confirming creation of your new LON-CAPA account has been sent to [_1].',$data{'username'}); - } else { - $msg .= &mt('An error occurred when sending e-mail to [_1] confirming creation of your LON-CAPA account.',$data{'username'}); + if (ref($settings) eq 'HASH') { + if (ref($settings->{'cancreate'}) eq 'HASH') { + if (ref($settings->{'cancreate'}{'selfcreateprocessing'}) eq 'HASH') { + $disposition = $settings->{'cancreate'}{'selfcreateprocessing'}{$usertype}; + } } - $redirect = &start_session($r,$data{'username'},$domain,$uhome, - $data{'courseid'},$token); - $nostart = 1; - $noend = 1; + } + if ($disposition eq 'approval') { + $msg = &store_request($domain,$data{'username'},'approval',\%data,$settings); + my $delete = &Apache::lonnet::tmpdel($token); } else { - $msg .= &mt('A problem occurred when attempting to create your new LON-CAPA account.') - .'
'.$output; - if (($contact_name ne '') && ($contact_email ne '')) { - $msg .= &mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email); + my ($result,$output,$uhome) = + &create_account($r,$domain,$domdesc,\%data); + if ($result eq 'ok') { + $msg = $output; + my $shownow = &Apache::lonlocal::locallocaltime($now); + my $mailmsg = &mt('A LON-CAPA account for the institution: [_1] has been created [_2] from IP address: [_3]. If you did not perform this action or authorize it, please contact the [_4] ([_5]).',$domdesc,$shownow,$ENV{'REMOTE_ADDR'},$contact_name,$contact_email)."\n"; + my $mailresult = &Apache::resetpw::send_mail($domdesc,$data{'email'}, + $mailmsg,$contact_name, + $contact_email); + if ($mailresult eq 'ok') { + $msg .= &mt('An e-mail confirming creation of your new LON-CAPA account has been sent to [_1].',$data{'username'}); + } else { + $msg .= &mt('An error occurred when sending e-mail to [_1] confirming creation of your LON-CAPA account.',$data{'username'}); + } + $redirect = &start_session($r,$data{'username'},$domain,$uhome, + $data{'courseid'},$token); + $nostart = 1; + $noend = 1; + } else { + $msg .= &mt('A problem occurred when attempting to create your new LON-CAPA account.') + .'
'.$output; + if (($contact_name ne '') && ($contact_email ne '')) { + $msg .= &mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email); + } } + my $delete = &Apache::lonnet::tmpdel($token); } - my $delete = &Apache::lonnet::tmpdel($token); - } elsif (grep(/^emailapproval$/,@{$cancreate})) { - $msg = &store_request($domain,$data{'username'},'approval',\%data,$settings); - my $delete = &Apache::lonnet::tmpdel($token); } else { $msg = &invalid_state('noemails',$domdesc,$contact_name,$contact_email); }