[LON-CAPA-cvs] cvs: loncom /interface createaccount.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Thu, 17 Jul 2008 20:19:43 -0000
raeburn Thu Jul 17 16:19:43 2008 EDT
Modified files:
/loncom/interface createaccount.pm
Log:
- Fix typo (missing quote after cid in call to echo_form_output().
- Checking of username against institutional rules moved to &call_rulecheck() routine.
- Institutional ststus types including as final arg in call to Apache::lonnet::modifyuser().
- Sanity checking so unmodifiable fields use institutional data for the new user.
Index: loncom/interface/createaccount.pm
diff -u loncom/interface/createaccount.pm:1.22 loncom/interface/createaccount.pm:1.23
--- loncom/interface/createaccount.pm:1.22 Thu Jul 17 08:10:05 2008
+++ loncom/interface/createaccount.pm Thu Jul 17 16:19:43 2008
@@ -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.23 2008/07/17 20:19:43 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -263,7 +263,7 @@
&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']).
'</form>');
}
$r->print(&Apache::loncommon::end_page());
@@ -517,17 +517,13 @@
$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 +548,20 @@
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 = '<h3>'.&mt('Account creation status').'</h3>'.
@@ -866,14 +876,10 @@
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 +1005,32 @@
}
}
# 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);