From lon-capa-cvs-allow@mail.lon-capa.org Mon Feb 18 04:46:53 2008
From: lon-capa-cvs-allow@mail.lon-capa.org (lon-capa-cvs-allow@mail.lon-capa.org)
Date: Sun, 17 Feb 2008 23:46:53 -0500
Subject: [LON-CAPA-cvs] February 72% OFF
Message-ID: <20080217064652.8118.qmail@pool-138-88-1-106.res.east.verizon.net>
';
+ $rownum ++;
+ }
+ $$rowtotal += $rownum;
+ return $datatable;
+}
+
+sub defaults_titles {
+ my %titles = &Apache::lonlocal::texthash (
+ 'auth_def' => 'Default authentication type',
+ 'auth_arg_def' => 'Default authentication argument',
+ 'lang_def' => 'Default language',
+ );
+ return (\%titles);
+}
+
+
sub modifiable_userdata_row {
my ($context,$role,$settings,$numinrow,$rowcount) = @_;
my $rolename;
@@ -1908,12 +2000,13 @@
my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
my %title = ( coursecatalog => 'Display course catalog',
adminmail => 'Display administrator E-mail address',
+ newuser => 'Link for visitors to create a user account',
loginheader => 'Log-in box header');
my @offon = ('off','on');
my %loginhash;
($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
\%domconfig,\%loginhash);
- my @toggles = ('coursecatalog','adminmail');
+ my @toggles = ('coursecatalog','adminmail','newuser');
foreach my $item (@toggles) {
$loginhash{login}{$item} = $env{'form.'.$item};
}
@@ -1925,10 +2018,11 @@
my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
$dom);
if ($putresult eq 'ok') {
- my @toggles = ('coursecatalog','adminmail');
+ my @toggles = ('coursecatalog','adminmail','newuser');
my %defaultchecked = (
'coursecatalog' => 'on',
'adminmail' => 'off',
+ 'newuser' => 'off',
);
foreach my $item (@toggles) {
if ($defaultchecked{$item} eq 'on') {
@@ -3097,20 +3191,26 @@
sub modify_usercreation {
my ($dom,%domconfig) = @_;
my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
+ my $warningmsg;
if (ref($domconfig{'usercreation'}) eq 'HASH') {
foreach my $key (keys(%{$domconfig{'usercreation'}})) {
$curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
}
}
- my %title = &Apache::lonlocal::texthash (
- author => 'adding co-authors/assistant authors',
- course => 'adding users to a course',
- );
my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
- my @contexts = ('author','course');
+ my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
+ my @contexts = ('author','course','selfenroll');
foreach my $item(@contexts) {
$cancreate{$item} = $env{'form.can_createuser_'.$item};
+ if ($item eq 'selfenroll') {
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+ if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
+ if (($cancreate{$item} eq 'any') || ($cancreate{$item} eq 'login')) {
+ $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.&mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');
+ }
+ }
+ }
}
if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
foreach my $item (@contexts) {
@@ -3120,7 +3220,7 @@
}
} elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
foreach my $item (@contexts) {
- if (grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
+ if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
if ($cancreate{$item} ne 'any') {
push(@{$changes{'cancreate'}},$item);
}
@@ -3131,7 +3231,7 @@
}
}
} else {
- foreach my $item ('author','course') {
+ foreach my $item (@contexts) {
push(@{$changes{'cancreate'}},$item);
}
}
@@ -3166,10 +3266,25 @@
push(@{$changes{'id_rule'}},@id_rule);
}
- my @contexts = ('author','course','domain');
+ if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
+ foreach my $type (@{$curr_usercreation{'email_rule'}}) {
+ if (!grep(/^\Q$type\E$/,@email_rule)) {
+ push(@{$changes{'email_rule'}},$type);
+ }
+ }
+ foreach my $type (@email_rule) {
+ if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
+ push(@{$changes{'email_rule'}},$type);
+ }
+ }
+ } else {
+ push(@{$changes{'email_rule'}},@email_rule);
+ }
+
+ my @authen_contexts = ('author','course','domain');
my @authtypes = ('int','krb4','krb5','loc');
my %authhash;
- foreach my $item (@contexts) {
+ foreach my $item (@authen_contexts) {
my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
foreach my $auth (@authtypes) {
if (grep(/^\Q$auth\E$/,@authallowed)) {
@@ -3180,7 +3295,7 @@
}
}
if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
- foreach my $item (@contexts) {
+ foreach my $item (@authen_contexts) {
if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
foreach my $auth (@authtypes) {
if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
@@ -3191,7 +3306,7 @@
}
}
} else {
- foreach my $item (@contexts) {
+ foreach my $item (@authen_contexts) {
push(@{$changes{'authtypes'}},$item);
}
}
@@ -3201,6 +3316,7 @@
cancreate => \%cancreate,
username_rule => \@username_rule,
id_rule => \@id_rule,
+ email_rule => \@email_rule,
authtypes => \%authhash,
}
);
@@ -3213,15 +3329,29 @@
if (ref($changes{'cancreate'}) eq 'ARRAY') {
my %lt = &usercreation_types();
foreach my $type (@{$changes{'cancreate'}}) {
- my $chgtext;
- if ($cancreate{$type} eq 'none') {
- $chgtext = $lt{$type}.' '.&mt('creation of new users is not permitted, except by a Domain Coordinator.');
- } elsif ($cancreate{$type} eq 'any') {
- $chgtext = $lt{$type}.' '.&mt('creation of new users is permitted for both institutional and non-institutional usernames.');
- } elsif ($cancreate{$type} eq 'official') {
- $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for institutional usernames.',$lt{$type});
- } elsif ($cancreate{$type} eq 'unofficial') {
- $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for non-institutional usernames.',$lt{$type});
+ my $chgtext = $lt{$type}.', ';
+ if ($type eq 'selfenroll') {
+ if ($cancreate{$type} eq 'none') {
+ $chgtext .= &mt('creation of a new user account is not permitted.');
+ } elsif ($cancreate{$type} eq 'any') {
+ $chgtext .= &mt('creation of a new account is permitted for users authenticated by institutional log-in and SSO, and also for e-mail addresses used as usernames.');
+ } elsif ($cancreate{$type} eq 'login') {
+ $chgtext .= &mt('creation of a new account is only permitted for users authenticated by institutional log-in.');
+ } elsif ($cancreate{$type} eq 'sso') {
+ $chgtext .= &mt('creation of a new account is only permitted for users authenticated by institutional single sign on.');
+ } elsif ($cancreate{$type} eq 'email') {
+ $chgtext .= &mt('creation of a new account is only permitted for users who provide a valid e-mail address for use as the username.');
+ }
+ } else {
+ if ($cancreate{$type} eq 'none') {
+ $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
+ } elsif ($cancreate{$type} eq 'any') {
+ $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
+ } elsif ($cancreate{$type} eq 'official') {
+ $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
+ } elsif ($cancreate{$type} eq 'unofficial') {
+ $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
+ }
}
$resulttext .= '
'.$chgtext.'
';
}
@@ -3258,6 +3388,23 @@
$resulttext .= '
'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'
';
}
}
+ if (ref($changes{'email_rule'}) eq 'ARRAY') {
+ my ($emailrules,$emailruleorder) =
+ &Apache::lonnet::inst_userrules($dom,'email');
+ my $chgtext = '
';
+ foreach my $type (@email_rule) {
+ if (ref($emailrules->{$type}) eq 'HASH') {
+ $chgtext .= '
'.$emailrules->{$type}{'name'}.'
';
+ }
+ }
+ $chgtext .= '
';
+ if (@email_rule > 0) {
+ $resulttext .= '
'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'
';
+ } else {
+ $resulttext .= '
'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'
'.&mt('Authentication types available for assignment to new users').' '.$chgtext;
@@ -3284,6 +3435,9 @@
$resulttext = ''.
&mt('An error occurred: [_1]',$putresult).'';
}
+ if ($warningmsg ne '') {
+ $resulttext .= ' '.$warningmsg.' ';
+ }
return $resulttext;
}
@@ -3387,4 +3541,91 @@
return $resulttext;
}
+sub modify_defaults {
+ my ($dom,$r) = @_;
+ my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+ my @items = ('auth_def','auth_arg_def','lang_def');
+ my @authtypes = ('internal','krb4','krb5','localauth');
+ foreach my $item (@items) {
+ $newvalues{$item} = $env{'form.'.$item};
+ if ($item eq 'auth_def') {
+ if ($newvalues{$item} ne '') {
+ if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
+ push(@errors,$item);
+ }
+ }
+ } elsif ($item eq 'lang_def') {
+ if ($newvalues{$item} ne '') {
+ if ($newvalues{$item} =~ /^(\w+)/) {
+ my $langcode = $1;
+ if (code2language($langcode) eq '') {
+ push(@errors,$item);
+ }
+ } else {
+ push(@errors,$item);
+ }
+ }
+ }
+ if (grep(/^\Q$item\E$/,@errors)) {
+ $newvalues{$item} = $domdefaults{$item};
+ } elsif ($domdefaults{$item} ne $newvalues{$item}) {
+ $changes{$item} = 1;
+ }
+ }
+ my %defaults_hash = (
+ defaults => { auth_def => $newvalues{'auth_def'},
+ auth_arg_def => $newvalues{'auth_arg_def'},
+ lang_def => $newvalues{'lang_def'},
+ }
+ );
+ my $title = &defaults_titles();
+ my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
+ $dom);
+ if ($putresult eq 'ok') {
+ if (keys(%changes) > 0) {
+ $resulttext = &mt('Changes made:').'
';
+ my $version = $r->dir_config('lonVersion');
+ my $mailmsgtext = "Changes made to domain settings in a LON-CAPA installation - domain: $dom (running version: $version) - dns_domain.tab needs to be updated with the following changes, to support legacy 2.4, 2.5 and 2.6 versions of LON-CAPA.\n\n";
+ foreach my $item (sort(keys(%changes))) {
+ my $value = $env{'form.'.$item};
+ if ($value eq '') {
+ $value = &mt('none');
+ } elsif ($item eq 'auth_def') {
+ my %authnames = &authtype_names();
+ my %shortauth = (
+ internal => 'int',
+ krb4 => 'krb4',
+ krb5 => 'krb5',
+ localauth => 'loc',
+ );
+ $value = $authnames{$shortauth{$value}};
+ }
+ $resulttext .= '
'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'
';
+ $mailmsgtext .= "$title->{$item} set to $value\n";
+ }
+ $resulttext .= '
';
+ $mailmsgtext .= "\n";
+ my $cachetime = 24*60*60;
+ &Apache::lonnet::do_cache_new('domdefaults',$dom,
+ $defaults_hash{'defaults'},$cachetime);
+ my $sysmail = $r->dir_config('lonSysEMail');
+ &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
+ } else {
+ $resulttext = &mt('No changes made to default authentication/language settings');
+ }
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred: [_1]',$putresult).'';
+ }
+ if (@errors > 0) {
+ $resulttext .= ' '.&mt('The following were left unchanged because the values entered were invalid:');
+ foreach my $item (@errors) {
+ $resulttext .= ' "'.$title->{$item}.'",';
+ }
+ $resulttext =~ s/,$//;
+ }
+ return $resulttext;
+}
+
1;
--raeburn1203895120--
From lon-capa-cvs-allow@mail.lon-capa.org Sun Feb 24 23:23:40 2008
From: lon-capa-cvs-allow@mail.lon-capa.org (raeburn)
Date: Sun, 24 Feb 2008 23:23:40 -0000
Subject: [LON-CAPA-cvs] cvs: loncom /interface createaccount.pm
Message-ID:
This is a MIME encoded message
--raeburn1203895420
Content-Type: text/plain
raeburn Sun Feb 24 18:23:40 2008 EDT
Added files:
/loncom/interface createaccount.pm
Log:
Bug 5558. Visitors without a LON-CAPA account can create one, using an e-mail address (sends a URL to the address provided, which needs to be visited to complete the process), or an institutional login (authentication required).
Requires Authen::Captcha perl module to discourage robotic account requests.
Work in progress.
--raeburn1203895420
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080224182340.txt"
Index: loncom/interface/createaccount.pm
+++ loncom/interface/createaccount.pm
# The LearningOnline Network
# Allow visitors to create a user account with the username being either an
# institutional log-in ID (institutional authentication required - localauth
# or kerberos) or an e-mail address.
#
# $Id: createaccount.pm,v 1.1 2008/02/24 23:23:39 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
#
package Apache::createaccount;
use strict;
use Apache::Constants qw(:common);
use Apache::lonacc;
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
use Apache::resetpw;
use Authen::Captcha;
use DynaLoader; # for Crypt::DES version
use Crypt::DES;
use LONCAPA;
sub handler {
my $r = shift;
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
if ($r->header_only) {
return OK;
}
my $domain = &Apache::lonnet::default_login_domain();
my $domdesc = &Apache::lonnet::domain($domain,'description');
my $start_page =
&Apache::loncommon::start_page('Create a user account in LON-CAPA','',
{
'no_inline_link' => 1,});
$r->print($start_page);
&Apache::lonhtmlcommon::clear_breadcrumbs();
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"/adm/createuser",
text=>"New username"});
my $contact_name = &mt('LON-CAPA helpdesk');
my $contact_email = $r->dir_config('lonSupportEMail');
my $lonhost = $r->dir_config('lonHostID');
my $include = $r->dir_config('lonIncludes');
&Apache::lonacc::get_posted_cgi($r);
&Apache::lonlocal::get_language_handle($r);
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token']);
my $token = $env{'form.token'};
my $output;
my $cancreate;
my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
if (ref($domconfig{'usercreation'}) eq 'HASH') {
if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
if ($domconfig{'usercreation'}{'cancreate'}{'selfenroll'} ne 'none') {
$cancreate = $domconfig{'usercreation'}{'cancreate'}{'selfenroll'};
}
}
}
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Create account'));
if (!$cancreate) {
$output = &mt('Creation of a new user account using an e-mail address as username or a loginID from your institution is not permitted in the domain: [_1] ([_2])',$domain,$domdesc);
} elsif ($token) {
$output = &process_mailtoken($r,$token,$contact_name,$contact_email,$domain,
$domdesc,$lonhost,$include);
} elsif ($env{'form.create_with_email'}) {
$output = &process_email_request($env{'form.useremail'},$domain,$domdesc,
$contact_name,$contact_email,$cancreate,
$lonhost,$domconfig{'usercreation'});
} elsif ($env{'form.phase'} eq 'username_validation') {
$output = &username_validation($env{'form.uname'},$domain,$domdesc,
$contact_name,$contact_email);
} elsif ($env{'form.phase'} eq 'username_activation') {
(my $result,$output) = &username_activation($env{'form.uname'},
$domain,$domdesc);
} else {
my $now=time;
if ($cancreate eq 'any' || $cancreate eq 'login') {
my $jsh=Apache::File->new($include."/londes.js");
$r->print(<$jsh>);
$r->print(&javascript_setforms($now));
}
$output = &print_username_form($domain,$domdesc,$cancreate,$now,$lonhost);
}
$r->print($output);
$r->print(&Apache::loncommon::end_page());
return OK;
}
sub javascript_setforms {
my ($now) = @_;
my $js = <
function send() {
this.document.server.elements.uname.value = this.document.client.elements.uname.value;
uextkey=this.document.client.elements.uextkey.value;
lextkey=this.document.client.elements.lextkey.value;
initkeys();
this.document.server.elements.upass.value
= crypted(this.document.client.elements.upass$now.value);
this.document.client.elements.uname.value='';
this.document.client.elements.upass$now.value='';
this.document.server.submit();
return false;
}
ENDSCRIPT
return $js;
}
sub javascript_checkpass {
my ($now) = @_;
my $nopass = &mt('You must enter a password');
my $mismatchpass = &mt('The passwords you entered did not match.').'\\n'.
&mt('Please try again.');
my $js = <<"ENDSCRIPT";
ENDSCRIPT
return $js;
}
sub print_username_form {
my ($domain,$domdesc,$cancreate,$now,$lonhost) = @_;
my %lt = &Apache::lonlocal::texthash(
unam => 'username',
udom => 'domain',
uemail => 'Email address in LON-CAPA',
proc => 'Proceed');
my $output;
if ($cancreate eq 'any' || $cancreate eq 'login') {
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 your institution').'
';
$output .= &mt('If you already have a Log-in ID at your institution, you may be able to use it[_1] for LON-CAPA.',' ').' '.&mt('Type in your Log-in ID and password to find out.').'
';
my ($lkey,$ukey) = &Apache::lonpreferences::des_keys();
my ($lextkey,$uextkey) = &getkeys($lkey,$ukey);
my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount',
$lonhost);
$output .= &serverform($logtoken,$lonhost);
my $unameform = '';
my $upassform = '';
my $submit_text = &mt('Create LON-CAPA account');
$output .= ''."\n".
&Apache::lonhtmlcommon::start_pick_box()."\n".
&Apache::lonhtmlcommon::row_title(&mt('Log-in ID'),
'LC_pick_box_title')."\n".
$unameform."\n".
&Apache::lonhtmlcommon::row_closure(1)."\n".
&Apache::lonhtmlcommon::row_title(&mt('Password'),
'LC_pick_box_title')."\n".
$upassform."\n".'
'.&mt('Create account with an e-mail address as your username').'
';
if ($cancreate eq 'any') {
$output .= &mt('Provide your e-mail address to request a LON-CAPA account if you do not have [_1] a log-in ID at your institution.',' ').'
';
} elsif ($cancreate eq 'unofficial') {
$output .= ' ';
}
my $emailform = '';
my $captchaform = &create_captcha();
my $submit_text = &mt('Request LON-CAPA account');
$output .= ''.
'
';
}
if ($output eq '') {
$output = &mt('Creation of a new user account using either an e-mail address or institutional log-in ID as your username is not permitted in the domain: [_1] ([_2])',$domain,$domdesc);
} else {
$output .= '';
}
return $output;
}
sub process_email_request {
my ($useremail,$domain,$domdesc,$contact_name,$contact_email,$cancreate,
$server,$settings) = @_;
my $useremail = $env{'form.useremail'};
my $output;
if ($cancreate ne 'any' && $cancreate ne 'email') {
$output = &invalid_state('noemails',$domdesc,
$contact_name,$contact_email);
return $output;
} elsif ($useremail !~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/) {
$output = &invalid_state('baduseremail',$domdesc,
$contact_name,$contact_email);
return $output;
} else {
my $uhome = &Apache::lonnet::homeserver($useremail,$domain);
if ($uhome ne 'no_host') {
$output = &invalid_state('existinguser',$domdesc,
$contact_name,$contact_email);
return $output;
} else {
my $code = $env{'form.code'};
my $md5sum = $env{'form.crypt'};
my %captcha_params = &captcha_settings();
my $captcha = Authen::Captcha->new(
output_folder => $captcha_params{'output_dir'},
data_folder => $captcha_params{'db_dir'},
);
my $captcha_chk = $captcha->check_code($code,$md5sum);
my %captcha_hash = (
0 => 'Code not checked (file error)',
-1 => 'Failed: code expired',
-2 => 'Failed: invalid code (not in database)',
-3 => 'Failed: invalid code (code does not match crypt)',
);
if ($captcha_chk != 1) {
$output = &invalid_state('captcha',$domdesc,$contact_name,
$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') {
if ($alerts{'username'}{$domain}{$useremail}) {
$output = &invalid_state('userrules',$domdesc,
$contact_name,$contact_email);
return $output;
}
}
}
my $format_msg =
&guest_format_check($useremail,$domain,$cancreate,
$settings);
if ($format_msg) {
$output = &invalid_state('userformat',$domdesc,$contact_name,
$contact_email,$format_msg);
return $output;
}
}
}
}
$output = &send_token($domain,$useremail,$server,$domdesc,$contact_name,
$contact_email);
return $output;
}
sub send_token {
my ($domain,$email,$server,$domdesc,$contact_name,$contact_email) = @_;
my $msg = &mt('Thank you for your request to create a new LON-CAPA account.').'
';
my $now = time;
my %info = ('ip' => $ENV{'REMOTE_ADDR'},
'time' => $now,
'domain' => $domain,
'username' => $email);
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 in the [_2] domain.',localtime(time),$domdesc).' '.
&mt('To complete this process please open a web browser and enter the following ".
"URL in the address/location box: ').&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') {
$msg .= &mt('A message has been sent to the e-mail address you provided.').' '.&mt('The message includes the web address for the link you will use to complete the account creation process.').' '.&mt("The link included in the message will be valid for the next [_1]two[_2] hours.",'','');
} else {
$msg .= &mt('An error occurred when sending a message to the e-mail address you provided. Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email);
}
} else {
$msg .= &mt('An error occurred creating a token required for the account creation process. Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email);
}
return $msg;
}
sub process_mailtoken {
my ($r,$token,$contact_name,$contact_email,$domain,$domdesc,$lonhost,$include) = @_;
my $msg;
my %data = &Apache::lonnet::tmpget($token);
my $now = time;
if (keys(%data) == 0) {
$msg = &mt('Sorry, the URL you provided to complete creation of a new LON-CAPA account was invalid. Either the token included in the URL has been deleted or the URL you provided was invalid. Please submit a new request for account creation and follow the link to the new URL included in the e-mail that will be sent to you.');
return $msg;
}
if (($data{'time'} =~ /^\d+$/) &&
($data{'domain'} ne '') &&
($data{'username'} =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/)) {
my $reqtime = localtime($data{'time'});
if ($now - $data{'time'} < 7200) {
if ($env{'form.phase'} eq 'createaccount') {
my ($result,$output) = &create_account($r,$domain,$lonhost,$token,
$data{'username'},$domdesc);
if ($result eq 'ok') {
$msg = $output;
my $delete = &Apache::lonnet::tmpdel($token);
my $now = localtime(time);
my $mailmsg = &mt('A LON-CAPA account in the [_1] domain has been created [_2] from IP address: [_3]. If you did not perform this action or authorize it, please contact the [_4] ([_5]).',$domdesc,$now,$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'});
}
$msg .= '
'.&mt('Go to the login page.');
} else {
$msg .= &mt('A problem occurred when attempting to create your new LON-CAPA account').' '.$output.&mt('Please contact the [_1] - ([_2]) for assistance.',$contact_name,$contact_email);
}
} else {
$r->print(&mt('Please provide user information and a password for your new account.').' '.&mt('Your password, which must contain at least seven characters, will be sent to the LON-CAPA server in an encrypted form.').' ');
&print_dataentry_form($r,$domain,$lonhost,$include,$token,$now,$data{'username'});
}
} else {
$msg = &mt('Sorry, the token generated when you requested creation of an account has expired. Please submit a new request, and follow the link to the web page included in the new e-mail that will be sent to you, to allow you to create the account.');
}
} else {
$msg .= &mt('Sorry, the URL generated when you requested creation of an accountcontained incomplete information. Please submit a new request for creation of an account, and use the new URL that will be sent to your e-mail address to complete the process.');
}
return $msg;
}
sub print_dataentry_form {
my ($r,$domain,$lonhost,$include,$mailtoken,$now,$username) = @_;
my ($error,$output);
if (open(my $jsh,"<$include/londes.js")) {
while(my $line = <$jsh>) {
$r->print($line);
}
close($jsh);
$r->print(&javascript_setforms($now)."\n".&javascript_checkpass($now));
my ($lkey,$ukey) = &Apache::lonpreferences::des_keys();
my ($lextkey,$uextkey) = &getkeys($lkey,$ukey);
my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount',
$lonhost);
my @userinfo = ('firstname','middlename','lastname','generation','id',
'permanentemail');
my %lt=&Apache::lonlocal::texthash(
'pd' => "Personal Data",
'firstname' => "First Name",
'middlename' => "Middle Name",
'lastname' => "Last Name",
'generation' => "Generation",
'permanentemail' => "Permanent e-mail address",
'id' => "ID/Student Number",
'lg' => "Login Data"
);
my %textboxsize = (
firstname => '15',
middlename => '15',
lastname => '15',
generation => '5',
id => '15',
);
my $genhelp=&Apache::loncommon::help_open_topic('Generation');
$output = '
'.$lt{'pd'}.'
'.
'
ENDSERVERFORM
my $upassone = '';
my $upasstwo = '';
my $submit_text = &mt('Create LON-CAPA account');
$output .= '
'."\n".
'';
$r->print($output);
} else {
$error = &mt('Could not load javascript file [_1]','londes.js');
$r->print($error);
}
return;
}
sub create_account {
my ($r,$domain,$lonhost,$logtoken,$username,$domdesc) = @_;
my ($retrieved,$output,$upass) = &process_credentials($env{'form.logtoken'},
$env{'form.serverid'});
# Error messages
my $error = ''.&mt('Error').': ';
my $end = '
';
my $rtnlink = ''.
&mt('Return to previous page').''.
&Apache::loncommon::end_page();
if ($retrieved eq 'ok') {
if ($env{'form.cid'} ne '') {
my ($result,$userchkmsg) = &check_id($username,$domain,$domdesc);
if ($result eq 'fail') {
$output = $error.&mt('Invalid ID format').$end.
$userchkmsg.$rtnlink;
return ('fail',$output);
}
}
} else {
return ('fail',$error.$output.$end.$rtnlink);
}
# Call modifyuser
my $result =
&Apache::lonnet::modifyuser($domain,$username,$env{'form.cid'},
'internal',$upass,$env{'form.cfirstname'},
$env{'form.cmiddlename'},$env{'form.clastname'},
$env{'form.cgeneration'},undef,undef,$username);
$output = &mt('Generating user').': '.$result;
my $uhome = &Apache::lonnet::homeserver($username,$domain);
$output .= ' '.&mt('Home server').': '.$uhome.' '.
&Apache::lonnet::hostname($uhome).'
';
return ('ok',$output);
}
sub username_validation {
my ($username,$domain,$domdesc,$contact_name,$contact_email) = @_;
my ($retrieved,$output,$upass);
$username= &LONCAPA::clean_username($username);
$domain = &LONCAPA::clean_domain($domain);
my $uhome = &Apache::lonnet::homeserver($username,$domain);
if ($uhome ne 'no_host') {
$output = &invalid_state('existinguser',$domdesc,
$contact_name,$contact_email);
return $output;
}
($retrieved,$output,$upass) = &process_credentials($env{'form.logtoken'},
$env{'form.serverid'});
if ($retrieved eq 'ok') {
my $primlibserv = &Apache::lonnet::domain($domain,'primary');
my $authok;
my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
if ((($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth')) {
my $checkdefauth = 1;
$authok =
&Apache::lonnet::reply("encrypt:auth:$domain:$username:$upass:$checkdefauth",$primlibserv);
} else {
$authok = 'non_authorized';
}
if ($authok eq 'authorized') {
my (%rulematch,%inst_results,$newuser,%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);
if (ref($alerts{'username'}) eq 'HASH') {
if (ref($alerts{'username'}{$domain}) eq 'HASH') {
if ($alerts{'username'}{$domain}{$username}) {
my $userchkmsg;
if (ref($curr_rules{$domain}) eq 'HASH') {
$userchkmsg =
&Apache::loncommon::instrule_disallow_msg('username',
$domdesc,1).
&Apache::loncommon::user_rule_formats($domain,
$domdesc,$curr_rules{$domain}{'username'},
'username');
}
return $userchkmsg;
}
}
}
my $submit_text = &mt('Create LON-CAPA account');
$output =
'';
} else {
$output = &mt('Not authenticated').' '.&mt('Please check the username and password');
}
}
return $output;
}
sub username_activation {
my ($username,$domain,$domdesc) = @_;
my $output;
my $error = ''.&mt('Error').': ';
my $end = '
';
my $rtnlink = ''.
&mt('Return to previous page').''.
&Apache::loncommon::end_page();
my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
if ((($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth')) {
if ($env{'form.cid'} ne '') {
my ($result,$userchkmsg) = &check_id($username,$domain,$domdesc);
if ($result eq 'fail') {
$output = $error.&mt('Invalid ID format').$end.
$userchkmsg.$rtnlink;
return ('fail',$output);
}
}
# Call modifyuser
my $result =
&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'});
$output = &mt('Generating user').': '.$result;
my $uhome = &Apache::lonnet::homeserver($username,$domain);
$output .= ' '.&mt('Home server').': '.$uhome.' '.
&Apache::lonnet::hostname($uhome).'
';
return ('ok',$output);
} else {
$output = &mt("User account creation is not available for the current default authentication type.\n");
return('fail',$output);
}
}
sub check_id {
my ($username,$domain,$domdesc) = @_;
# Check ID format
my (%alerts,%rulematch,%inst_results,%curr_rules,%checkhash);
my %checks = ('id' => 1);
%{$checkhash{$username.':'.$domain}} = (
'newuser' => 1,
'id' => $env{'form.cid'},
);
&Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
\%rulematch,\%inst_results,\%curr_rules);
if (ref($alerts{'id'}) eq 'HASH') {
if (ref($alerts{'id'}{$domain}) eq 'HASH') {
if ($alerts{'id'}{$domain}{$env{'form.cid'}}) {
my $userchkmsg;
if (ref($curr_rules{$domain}) eq 'HASH') {
$userchkmsg =
&Apache::loncommon::instrule_disallow_msg('id',
$domdesc,1).
&Apache::loncommon::user_rule_formats($domain,
$domdesc,$curr_rules{$domain}{'id'},'id');
}
return ('fail',$userchkmsg);
}
}
}
return;
}
sub invalid_state {
my ($error,$domdesc,$contact_name,$contact_email,$msgtext) = @_;
my $msg;
if ($error eq 'baduseremail') {
$msg = &mt('The e-mail address you provided does not appear to be a valid address.');
} elsif ($error eq 'existinguser') {
$msg = &mt('The e-mail address you provided is already in use as a username in this LON-CAPA domain.');
} elsif ($error eq 'userrules') {
$msg = &mt('Username rules for this LON-CAPA domain 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 in this LON-CAPA domain.');
} elsif ($error eq 'captcha') {
$msg = &mt('Validation of the code your entered failed.');
} elsif ($error eq 'noemails') {
$msg = &mt('Creation of a new user account using an e-mail address as username is not permitted in this LON-CAPA domain.');
}
if ($msgtext) {
$msg .= ' '.$msgtext;
}
if ($contact_email ne '') {
my $escuri = &HTML::Entities::encode('/adm/createaccount','&<>"');
$msg .= ' '.&mt(' You may wish to contact the LON-CAPA helpdesk for the [_2] domain.',$escuri,$domdesc);
} else {
$msg .= ' '.&mt(' You may wish to send an e-mail to the server administrator: [_1] for the [_2] domain.',$Apache::lonnet::perlvar{'AdminEmail'},$domdesc);
}
return $msg;
}
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').' '.
' '.
'';
return $output;
}
sub captcha_settings {
my %captcha_params = (
output_dir => "/home/httpd/html/captcha",
www_output_dir => "/captcha",
db_dir => "/home/www/captchadb",
numchars => '5',
);
return %captcha_params;
}
sub getkeys {
my ($lkey,$ukey) = @_;
my $lextkey=hex($lkey);
if ($lextkey>2147483647) { $lextkey-=4294967296; }
my $uextkey=hex($ukey);
if ($uextkey>2147483647) { $uextkey-=4294967296; }
return ($lextkey,$uextkey);
}
sub serverform {
my ($logtoken,$lonhost,$mailtoken) = @_;
my $output .= <
ENDSERVERFORM
return $output;
}
sub process_credentials {
my ($logtoken,$lonhost) = @_;
my $tmpinfo=Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
my ($retrieved,$output,$upass);
if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
$output = &mt('Information needed to retrieve your log-in information is missing, inaccessible or expired.').' '.&mt('You may need to reload the previous page to obtain a new token.');
return ($retrieved,$output,$upass);
} else {
my $reply = &Apache::lonnet::reply('tmpdel:'.$logtoken,$lonhost);
if ($reply eq 'ok') {
$retrieved = 'ok';
} else {
$output = &mt('Session could not be opened.');
}
}
my ($key,$caller)=split(/&/,$tmpinfo);
if ($caller eq 'createaccount') {
$upass = &Apache::lonpreferences::des_decrypt($key,$env{'form.upass'});
} else {
$output = &mt('Unable to retrieve your log-in information - unexpected context');
}
return ($retrieved,$output,$upass);
}
sub guest_format_check {
my ($useremail,$domain,$cancreate,$settings) = @_;
my ($login,$format_match,$format_msg,@user_rules);
if (ref($settings) eq 'HASH') {
if (ref($settings->{'email_rule'}) eq 'ARRAY') {
push(@user_rules,@{$settings->{'email_rule'}});
}
}
if (@user_rules > 0) {
my %rule_check =
&Apache::lonnet::inst_rulecheck($domain,$useremail,undef,
'selfenroll',\@user_rules);
if (keys(%rule_check) > 0) {
foreach my $item (keys(%rule_check)) {
if ($rule_check{$item}) {
$format_match = 1;
last;
}
}
}
}
if ($format_match) {
($login) = ($useremail =~ /^([^\@]+)\@/);
$format_msg = ' '.&mt("Your e-mail address uses the same internet domain as your institution's LON-CAPA service.").' '.&mt('Creation of a LON-CAPA account with this type of e-mail address as username is not permitted.').' ';
if ($cancreate eq 'any' || $cancreate eq 'login') {
$format_msg .= &mt('You should request creation of a LON-CAPA account for a Log-in ID of "[_1]" at your institution instead.',$login).' ';
}
}
return $format_msg;
}
1;
--raeburn1203895420--
From lon-capa-cvs-allow@mail.lon-capa.org Sun Feb 24 23:41:00 2008
From: lon-capa-cvs-allow@mail.lon-capa.org (raeburn)
Date: Sun, 24 Feb 2008 23:41:00 -0000
Subject: [LON-CAPA-cvs] cvs: loncom / loncapa_apache.conf
Message-ID:
raeburn Sun Feb 24 18:41:00 2008 EDT
Modified files:
/loncom loncapa_apache.conf
Log:
Make createaccount.pm available - used for self-service account creation.
Index: loncom/loncapa_apache.conf
diff -u loncom/loncapa_apache.conf:1.170 loncom/loncapa_apache.conf:1.171
--- loncom/loncapa_apache.conf:1.170 Fri Oct 5 17:28:27 2007
+++ loncom/loncapa_apache.conf Sun Feb 24 18:41:00 2008
@@ -1,7 +1,7 @@
##
## loncapa_apache.conf -- Apache HTTP LON-CAPA configuration file
##
-## $Id: loncapa_apache.conf,v 1.170 2007/10/05 21:28:27 albertel Exp $
+## $Id: loncapa_apache.conf,v 1.171 2008/02/24 23:41:00 raeburn Exp $
##
#
@@ -1203,6 +1203,12 @@
ErrorDocument 500 /adm/errorhandler
+
+SetHandler perl-script
+PerlHandler Apache::createaccount
+ErrorDocument 500 /adm/errorhandler
+
+
SetHandler perl-script
PerlHandler Apache::londns
From lon-capa-cvs-allow@mail.lon-capa.org Sun Feb 24 23:43:29 2008
From: lon-capa-cvs-allow@mail.lon-capa.org (raeburn)
Date: Sun, 24 Feb 2008 23:43:29 -0000
Subject: [LON-CAPA-cvs] cvs: doc /loncapafiles loncapafiles.lpml
Message-ID:
raeburn Sun Feb 24 18:43:29 2008 EDT
Modified files:
/doc/loncapafiles loncapafiles.lpml
Log:
Make createaccount.pm available - used for self-service account creation.
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.569 doc/loncapafiles/loncapafiles.lpml:1.570
--- doc/loncapafiles/loncapafiles.lpml:1.569 Mon Jan 21 02:42:35 2008
+++ doc/loncapafiles/loncapafiles.lpml Sun Feb 24 18:43:29 2008
@@ -2,7 +2,7 @@
"http://lpml.sourceforge.net/DTD/lpml.dtd">
-
+