--- loncom/interface/createaccount.pm 2008/12/05 19:22:58 1.26
+++ loncom/interface/createaccount.pm 2009/02/07 00:59:17 1.28
@@ -3,7 +3,7 @@
# institutional log-in ID (institutional authentication required - localauth
# or kerberos) or an e-mail address.
#
-# $Id: createaccount.pm,v 1.26 2008/12/05 19:22:58 schafran Exp $
+# $Id: createaccount.pm,v 1.28 2009/02/07 00:59:17 raeburn 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,10 +85,6 @@ 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 '') {
$start_page =
@@ -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 '') {
@@ -576,10 +592,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') {
@@ -1115,15 +1131,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;
}