--- loncom/interface/createaccount.pm 2008/07/17 12:10:05 1.22
+++ loncom/interface/createaccount.pm 2009/03/12 14:13:34 1.31
@@ -3,7 +3,7 @@
# institutional log-in ID (institutional authentication required - localauth
# or kerberos) or an e-mail address.
#
-# $Id: createaccount.pm,v 1.22 2008/07/17 12:10:05 raeburn Exp $
+# $Id: createaccount.pm,v 1.31 2009/03/12 14:13:34 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -58,10 +58,21 @@ sub handler {
my $sso_username = $r->subprocess_env->get('REDIRECT_SSOUserUnknown');
my $sso_domain = $r->subprocess_env->get('REDIRECT_SSOUserDomain');
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token','courseid']);
+ &Apache::lonacc::get_posted_cgi($r);
+ &Apache::lonlocal::get_language_handle($r);
+
if ($sso_username ne '' && $sso_domain ne '') {
$domain = $sso_domain;
- } else {
+ } else {
$domain = &Apache::lonnet::default_login_domain();
+ if (defined($env{'form.courseid'})) {
+ if (&validate_course($env{'form.courseid'})) {
+ if ($env{'form.courseid'} =~ /^($match_domain)_($match_courseid)$/) {
+ $domain = $1;
+ }
+ }
+ }
}
my $domdesc = &Apache::lonnet::domain($domain,'description');
my $contact_name = &mt('LON-CAPA helpdesk');
@@ -74,12 +85,8 @@ sub handler {
my $include = $r->dir_config('lonIncludes');
my $start_page;
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token','courseid']);
- &Apache::lonacc::get_posted_cgi($r);
- &Apache::lonlocal::get_language_handle($r);
-
my $handle = &Apache::lonnet::check_for_valid_session($r);
- if ($handle ne '') {
+ if (($handle ne '') && ($handle !~ /^publicuser_\d+$/)) {
$start_page =
&Apache::loncommon::start_page('Already logged in');
my $end_page =
@@ -263,7 +270,7 @@ sub print_footer {
&Apache::lonhtmlcommon::echo_form_input(['backto','logtoken',
'token','serverid','uname','upass','phase','create_with_email',
'code','useremail','crypt','cfirstname','clastname',
- 'cmiddlename','cgeneration','cpermanentemail','cid]).
+ 'cmiddlename','cgeneration','cpermanentemail','cid']).
'');
}
$r->print(&Apache::loncommon::end_page());
@@ -381,7 +388,7 @@ sub print_username_form {
my %lt = &Apache::lonlocal::texthash(
unam => 'username',
udom => 'domain',
- uemail => 'Email address in LON-CAPA',
+ uemail => 'E-mail address in LON-CAPA',
proc => 'Proceed');
my $output;
if (ref($cancreate) eq 'ARRAY') {
@@ -397,34 +404,43 @@ sub print_username_form {
}
if (grep(/^email$/,@{$cancreate})) {
$output .= '
'.&mt('Create account with an e-mail address as your username').'
';
- if (grep(/^login$/,@{$cancreate})) {
- $output .= &mt('Provide your e-mail address to request a LON-CAPA account,[_1] if you do not have a log-in ID at your institution.',' ').'
';
- } else {
- $output .= ' ';
- }
- my $emailform = '';
my $captchaform = &create_captcha();
- my $submit_text = &mt('Request LON-CAPA account');
- $output .= '';
+ } else {
+ 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 .= '
';
+ $output .= '';
}
}
if ($output eq '') {
@@ -451,27 +467,32 @@ sub login_box {
my $upassform = '';
$output .= '';
return $output;
@@ -517,17 +538,13 @@ sub process_email_request {
$contact_email,$captcha_hash{$captcha_chk});
return $output;
}
- my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts);
my $uhome=&Apache::lonnet::homeserver($useremail,$domain);
if ($uhome eq 'no_host') {
- my $checkhash;
- my $checks = { 'username' => 1 };
- $checkhash->{$useremail.':'.$domain} = { 'newuser' => 1, };
- &Apache::loncommon::user_rule_check($checkhash,$checks,
- \%alerts,\%rulematch,\%inst_results,\%curr_rules,
- \%got_rules);
- if (ref($alerts{'useremail'}) eq 'HASH') {
- if (ref($alerts{'useremail'}{$domain}) eq 'HASH') {
+ my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts);
+ &call_rulecheck($useremail,$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}) {
$output = &invalid_state('userrules',$domdesc,
$contact_name,$contact_email);
@@ -552,6 +569,20 @@ sub process_email_request {
return $output;
}
+sub call_rulecheck {
+ my ($uname,$udom,$alerts,$rulematch,$inst_results,$curr_rules,
+ $got_rules,$tocheck) = @_;
+ my ($checkhash,$checks);
+ $checkhash->{$uname.':'.$udom} = { 'newuser' => 1, };
+ if ($tocheck eq 'username') {
+ $checks = { 'username' => 1 };
+ }
+ &Apache::loncommon::user_rule_check($checkhash,$checks,
+ $alerts,$rulematch,$inst_results,$curr_rules,
+ $got_rules);
+ return;
+}
+
sub send_token {
my ($domain,$email,$server,$domdesc,$contact_name,$contact_email,$courseid) = @_;
my $msg = '
'.&mt('Account creation status').'
'.
@@ -566,10 +597,10 @@ sub send_token {
my $token = &Apache::lonnet::tmpput(\%info,$server);
if ($token !~ /^error/ && $token ne 'no_such_host') {
my $esc_token = &escape($token);
- my $mailmsg = &mt('A request was submitted on [_1] for creation of a LON-CAPA account at the following institution: [_2].',localtime(time),$domdesc).' '.
- &mt('To complete this process please open a web browser and enter the following'
- .' URL in the address/location box: [_1]'
- ,&Apache::lonnet::absolute_url().'/adm/createaccount?token='.$esc_token);
+ my $showtime = localtime(time);
+ my $mailmsg = &mt('A request was submitted on [_1] for creation of a LON-CAPA account at the following institution: [_2].',$showtime,$domdesc).' '.
+ &mt('To complete this process please open a web browser and enter the following URL in the address/location box: [_1]',
+ &Apache::lonnet::absolute_url().'/adm/createaccount?token='.$esc_token);
my $result = &Apache::resetpw::send_mail($domdesc,$email,$mailmsg,$contact_name,
$contact_email);
if ($result eq 'ok') {
@@ -698,7 +729,7 @@ sub print_dataentry_form {
'lastname' => "Last Name",
'generation' => "Generation",
'permanentemail' => "Permanent e-mail address",
- 'id' => "ID/Student Number",
+ 'id' => "Student/Employee ID",
'lg' => "Login Data"
);
my %textboxsize = (
@@ -866,14 +897,10 @@ sub login_failure_msg {
sub username_check {
my ($username,$domain,$domdesc,$courseid,$lonhost,$contact_email,$contact_name,
$sso_logout) = @_;
- my (%rulematch,%inst_results,$newuser,$checkfail,$rowcount,$editable,$output,$msg,
+ my (%rulematch,%inst_results,$checkfail,$rowcount,$editable,$output,$msg,
%alerts,%curr_rules,%got_rules);
- $newuser = 1;
- my $checkhash;
- my $checks = { 'username' => 1 };
- $checkhash->{$username.':'.$domain} = { 'newuser' => $newuser };
- &Apache::loncommon::user_rule_check($checkhash,$checks,\%alerts,\%rulematch,
- \%inst_results,\%curr_rules,\%got_rules);
+ &call_rulecheck($username,$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}{$username}) {
@@ -999,13 +1026,32 @@ sub username_activation {
}
}
# Call modifyuser
+ my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts,%info);
+ &call_rulecheck($username,$domain,\%alerts,\%rulematch,
+ \%inst_results,\%curr_rules,%got_rules);
+ my @userinfo = ('firstname','middlename','lastname','generation',
+ 'permanentemail','id');
+ my %canmodify =
+ &Apache::loncreateuser::selfcreate_canmodify('selfcreate',$domain,
+ \@userinfo,\%inst_results);
+ foreach my $item (@userinfo) {
+ if ($canmodify{$item}) {
+ $info{$item} = $env{'form.c'.$item};
+ } else {
+ $info{$item} = $inst_results{$username.':'.$domain}{$item};
+ }
+ }
+ if (ref($inst_results{$username.':'.$domain}{'inststatus'}) eq 'ARRAY') {
+ my @inststatuses = @{$inst_results{$username.':'.$domain}{'inststatus'}};
+ $info{'inststatus'} = join(':',map { &escape($_); } @inststatuses);
+ }
my $result =
- &Apache::lonnet::modifyuser($domain,$username,$env{'form.courseid'},
+ &Apache::lonnet::modifyuser($domain,$username,$env{'form.cid'},
$domdefaults{'auth_def'},
- $domdefaults{'auth_arg_def'},$env{'form.cfirstname'},
- $env{'form.cmiddlename'},$env{'form.clastname'},
- $env{'form.cgeneration'},undef,undef,
- $env{'form.cpermanentemail'});
+ $domdefaults{'auth_arg_def'},$info{'firstname'},
+ $info{'middlename'},$info{'lastname'},
+ $info{'generation'},undef,undef,
+ $info{'permanentemail'},$info{'inststatus'});
if ($result eq 'ok') {
my $delete = &Apache::lonnet::tmpdel($env{'form.authtoken'});
$output = &mt('A LON-CAPA account has been created for username: [_1] in domain: [_2].',$username,$domain);
@@ -1059,7 +1105,7 @@ sub invalid_state {
} elsif ($error eq 'existinguser') {
$msg = &mt('The e-mail address you provided is already in use as a username in LON-CAPA at this institution.');
} elsif ($error eq 'userrules') {
- $msg = &mt('Username rules for this LON-CAPA at this institution do not allow the e-mail address you provided to be used as a username.');
+ $msg = &mt('Username rules at this institution do not allow the e-mail address you provided to be used as a username.');
} elsif ($error eq 'userformat') {
$msg = &mt('The e-mail address you provided may not be used as a username at this LON-CAPA institution.');
} elsif ($error eq 'captcha') {
@@ -1090,15 +1136,23 @@ sub linkto_email_help {
sub create_captcha {
my ($output_dir,$db_dir) = @_;
my %captcha_params = &captcha_settings();
- my $captcha = Authen::Captcha->new(
- output_folder => $captcha_params{'output_dir'},
- data_folder => $captcha_params{'db_dir'},
- );
- my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
- my $output = ''."\n".
- &mt('Type in the letters/numbers shown below').' '.
- ' '.
- '';
+ my ($output,$maxtries,$tries) = ('',10,0);
+ while ($tries < $maxtries) {
+ $tries ++;
+ my $captcha = Authen::Captcha->new (
+ output_folder => $captcha_params{'output_dir'},
+ data_folder => $captcha_params{'db_dir'},
+ );
+ my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
+
+ if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
+ $output = ''."\n".
+ &mt('Type in the letters/numbers shown below').' '.
+ ' '.
+ '';
+ last;
+ }
+ }
return $output;
}