[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Wed, 12 Sep 2007 23:32:59 -0000
raeburn Wed Sep 12 19:32:59 2007 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
Namespacing for usernames.
Add &username_rule_check(), which is called when preparing to add a new username, to see if any username format checks are enabled for the domain, and whether the new username matches them.
If the format matches, but the username does not exist in the institutional directory, warn the user, and ask for a different username.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.584 loncom/interface/loncommon.pm:1.585
--- loncom/interface/loncommon.pm:1.584 Tue Sep 11 19:36:46 2007
+++ loncom/interface/loncommon.pm Wed Sep 12 19:32:59 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.584 2007/09/11 23:36:46 albertel Exp $
+# $Id: loncommon.pm,v 1.585 2007/09/12 23:32:59 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -5908,6 +5908,59 @@
return $output;
}
+sub username_rule_check {
+ my ($srch,$caller) = @_;
+ my ($response,@curr_rules,%inst_results,$rulematch);
+ my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($srch->{'srchdomain'});
+ if (ref($srch) eq 'HASH') {
+ (my $inst_response,%inst_results) =
+ &Apache::lonnet::get_instuser($srch->{'srchdomain'},
+ $srch->{'srchterm'});
+ my %domconfig = &Apache::lonnet::get_dom('configuration',
+ ['usercreation'],$srch->{'srchdomain'});
+ if (ref($domconfig{'usercreation'}) eq 'HASH') {
+ if (ref($domconfig{'usercreation'}{'username_rule'}) eq 'ARRAY') {
+ @curr_rules = @{$domconfig{'usercreation'}{'username_rule'}};
+ }
+ }
+ if (@curr_rules > 0) {
+ my $domdesc = &Apache::lonnet::domain($srch->{'srchdomain'},'description');
+ my $instuser_reqd;
+ my %rule_check = &Apache::lonnet::inst_rulecheck($srch->{'srchdomain'},$srch->{'srchterm'},\@curr_rules);
+ foreach my $rule (@curr_rules) {
+ if ($rule_check{$rule}) {
+ $rulematch = $rule;
+ if ($inst_response eq 'ok') {
+ if (keys(%inst_results) == 0) {
+ if ($caller eq 'new') {
+ $response = &mt('The username you chose matches the format of usernames defined for <span class="LC_cusr_emph">[_1]</span>, but the user does not exist in the institutional directory.',$domdesc).'<br />'.&mt("You must choose a username with a different format -- one that will not conflict with 'official' institutional usernames.");
+ }
+ }
+ }
+ last;
+ }
+ }
+ if ($response) {
+ if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
+ if (@{$ruleorder} > 0) {
+ $response .= '<br />'.&mt('Usernames with the following format(s) may <span class="LC_cusr_emph">only</span> be used for verified users at [_1]:',$domdesc).' <ul>';
+ foreach my $rule (@{$ruleorder}) {
+ if (grep(/^\Q$rule\E$/,@curr_rules)) {
+ if (ref($rules->{$rule}) eq 'HASH') {
+ $response .= '<li>'.$rules->{$rule}{'name'}.': '.
+ $rules->{$rule}{'desc'}.'</li>';
+ }
+ }
+ }
+ }
+ $response .= '</ul>';
+ }
+ }
+ }
+ }
+ return ($response,$rulematch,$rules,%inst_results);
+}
+
=pod
=back