[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm

raeburn raeburn at source.lon-capa.org
Wed Feb 12 16:29:03 EST 2014


raeburn		Wed Feb 12 21:29:03 2014 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
  Log:
  - Bug 6646
    - Self-creation of user accounts with e-mail address as username can
      be queued for approval.
    - Link in Domain Coordinator's User Management menu to approve/reject
      requests.
    - Support for pop-up window to display details of new account request. 
    - User information and password requested from prospective user in a single
      web form.
  
  
-------------- next part --------------
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.390 loncom/interface/loncreateuser.pm:1.391
--- loncom/interface/loncreateuser.pm:1.390	Tue Feb 11 17:34:41 2014
+++ loncom/interface/loncreateuser.pm	Wed Feb 12 21:29:03 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.390 2014/02/11 17:34:41 bisitz Exp $
+# $Id: loncreateuser.pm,v 1.391 2014/02/12 21:29:03 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2161,13 +2161,37 @@
 }
 
 sub personal_data_display {
-    my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
+    my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
+        $now,$captchaform,$emailusername) = @_;
     my ($output,%userenv,%canmodify,%canmodify_status);
     my @userinfo = ('firstname','middlename','lastname','generation',
                     'permanentemail','id');
     my $rowcount = 0;
     my $editable = 0;
-    %canmodify_status = 
+    my %textboxsize = (
+                       firstname      => '15',
+                       middlename     => '15',
+                       lastname       => '15',
+                       generation     => '5',
+                       permanentemail => '25',
+                       id             => '15',
+                      );
+
+    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'             => "Student/Employee ID",
+                'lg'             => "Login Data",
+                'inststatus'     => "Affiliation",
+                'email'          => 'E-mail address',
+                'valid'          => 'Validation',
+    );
+
+    %canmodify_status =
         &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
                                                    ['inststatus'],$rolesarray);
     if (!$newuser) {
@@ -2179,31 +2203,53 @@
             &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
                                                        \@userinfo,$rolesarray);
     } elsif ($context eq 'selfcreate') {
-        %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
-                                           $inst_results,$rolesarray);
+        if ($newuser eq 'email') {
+            if (ref($emailusername) eq 'HASH') { 
+                my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
+                @userinfo = ();          
+                if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
+                    foreach my $field (@{$infofields}) { 
+                        if ($emailusername->{$field}) {
+                            push(@userinfo,$field);
+                            $canmodify{$field} = 1;
+                            unless ($textboxsize{$field}) {
+                                $textboxsize{$field} = 25;
+                            }
+                            unless ($lt{$field}) {
+                                $lt{$field} = $infotitles->{$field};
+                            }
+                        }
+                    }
+                }
+            }
+        } else {
+            %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
+                                               $inst_results,$rolesarray);
+        }
     }
-    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'             => "Student/Employee ID",
-                'lg'             => "Login Data",
-                'inststatus'     => "Affiliation",
-    );
-    my %textboxsize = (
-                       firstname      => '15',
-                       middlename     => '15',
-                       lastname       => '15',
-                       generation     => '5',
-                       permanentemail => '25',
-                       id             => '15',
-                      );
+
     my $genhelp=&Apache::loncommon::help_open_topic('Generation');
     $output = '<h3>'.$lt{'pd'}.'</h3>'.
               &Apache::lonhtmlcommon::start_pick_box();
+    if (($context eq 'selfcreate') && ($newuser eq 'email')) {
+        $output .= &Apache::lonhtmlcommon::row_title($lt{'email'},undef,
+                                                     'LC_oddrow_value')."\n".
+                   '<input type="text" name="uname" size="25" value="" />';
+        $rowcount ++;
+        $output .= &Apache::lonhtmlcommon::row_closure(1);
+        my $upassone = '<input type="password" name="upass'.$now.'" size="10" />';
+        my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="10" />';
+        $output .= &Apache::lonhtmlcommon::row_title(&mt('Password'),
+                                                    'LC_pick_box_title',
+                                                    'LC_oddrow_value')."\n".
+                   $upassone."\n".
+                   &Apache::lonhtmlcommon::row_closure(1)."\n".
+                   &Apache::lonhtmlcommon::row_title(&mt('Confirm password'),
+                                                     'LC_pick_box_title',
+                                                     'LC_oddrow_value')."\n".
+                   $upasstwo.
+                   &Apache::lonhtmlcommon::row_closure()."\n";
+    }
     foreach my $item (@userinfo) {
         my $rowtitle = $lt{$item};
         my $hiderow = 0;
@@ -2217,7 +2263,7 @@
                     $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
                 } else {
                     if ($context eq 'selfcreate') {
-                        if ($canmodify{$item}) { 
+                        if ($canmodify{$item}) {
                             $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
                             $editable ++;
                         } else {
@@ -2233,7 +2279,11 @@
                         $row .= $ccuname;
                     } else {
                         if ($canmodify{$item}) {
-                            $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
+                            if ($newuser eq 'email') {
+                                $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
+                            } else {
+                                $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
+                            }
                             $editable ++;
                         } else {
                             $hiderow = 1;
@@ -2296,6 +2346,20 @@
             }
         }
     }
+    if (($context eq 'selfcreate') && ($newuser eq 'email')) {
+        if ($captchaform) {
+            $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'},
+                                                         'LC_pick_box_title')."\n".
+                       $captchaform."\n".'<br /><br />'.
+                       &Apache::lonhtmlcommon::row_closure(1); 
+            $rowcount ++;
+        }
+        my $submit_text = &mt('Create account');
+        $output .= &Apache::lonhtmlcommon::row_title()."\n".
+                   '<br /><input type="submit" name="createaccount" value="'.
+                   $submit_text.'" />'.
+                   &Apache::lonhtmlcommon::row_closure(1);
+    }
     $output .= &Apache::lonhtmlcommon::end_pick_box();
     if (wantarray) {
         if ($context eq 'selfcreate') {
@@ -4494,12 +4558,12 @@
 
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
         ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
-         'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
+         'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
     &Apache::lonhtmlcommon::clear_breadcrumbs();
     my $args;
     my $brcrum = [];
     my $bread_crumbs_component = 'User Management';
-    if ($env{'form.action'} ne 'dateselect') {
+    if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
         $brcrum = [{href=>"/adm/createuser",
                     text=>"User Management",
                     help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'}
@@ -4666,7 +4730,8 @@
         }
         $args = { bread_crumbs           => $brcrum,
                   bread_crumbs_component => $bread_crumbs_component};
-        $r->print(&header(undef,$args));
+        my $js = &usernamerequest_javascript();
+        $r->print(&header(&add_script($js),$args));
         if (!exists($env{'form.state'})) {
             $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
                                                                             $env{'request.role.domain'}));
@@ -4675,6 +4740,103 @@
             $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
                                                                          $env{'request.role.domain'}));
         }
+    } elsif (($env{'form.action'} eq 'processusernamereq') &&
+             ($permission->{'cusr'}) &&
+             (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
+        push(@{$brcrum},
+                 {href => '/adm/createuser?action=processusernamereq',
+                  text => 'LON-CAPA account requests',
+                  help => 'Domain_Username_Approvals'});
+        $bread_crumbs_component = 'Account requests';
+        if ($env{'form.state'} eq 'done') {
+            push(@{$brcrum},
+                     {href => '/adm/createuser?action=usernamereqqueue',
+                      text => 'Result',
+                      help => 'Domain_Username_Approvals'});
+            $bread_crumbs_component = 'LON-CAPA account request result';
+        }
+        $args = { bread_crumbs           => $brcrum,
+                  bread_crumbs_component => $bread_crumbs_component};
+        my $js = &usernamerequest_javascript();
+        $r->print(&header(&add_script($js),$args));
+        if (!exists($env{'form.state'})) {
+            $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
+                                                                            $env{'request.role.domain'}));
+        } elsif ($env{'form.state'} eq 'done') {
+            $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
+            $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
+                                                                         $env{'request.role.domain'}));
+        }
+    } elsif (($env{'form.action'} eq 'displayuserreq') &&
+             ($permission->{'cusr'})) {
+        my $dom = $env{'form.domain'};
+        my $uname = $env{'form.username'};
+        my $warning;
+        if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
+            if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
+                if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
+                    my $uhome = &Apache::lonnet::homeserver($uname,$dom);
+                    if ($uhome eq 'no_host') {
+                        my $queue = $env{'form.queue'};
+                        my $reqkey = &escape($uname).'_'.$queue; 
+                        my $namespace = 'usernamequeue';
+                        my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
+                        my %queued =
+                            &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
+                        unless ($queued{$reqkey}) {
+                            $warning = &mt('No information was found for this LON-CAPA account request.');
+                        }
+                    } else {
+                        $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
+                    }
+                } else {
+                    $warning = &mt('LON-CAPA account request status check is for an invalid username.');
+                }
+            } else {
+                $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
+            }
+        } else {
+            $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
+        }
+        my $args = { only_body => 1 };
+        $r->print(&header(undef,$args).
+                  '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
+        if ($warning ne '') {
+            $r->print('<div class="LC_warning">'.$warning.'</div>');
+        } else {
+            my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
+            my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
+            my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+            if (ref($domconfig{'usercreation'}) eq 'HASH') {
+                if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
+                    if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
+                        my $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}}));
+                        my %info =
+                            &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
+                        if (ref($info{$uname}) eq 'HASH') {
+                            if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
+                                $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
+                                my $num;
+                                foreach my $field (@{$infofields}) {
+                                    next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$field});
+                                    next unless ($infotitles->{$field});
+                                    $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
+                                              $info{$uname}{$field});
+                                    $num ++;
+                                    if ($count == $num) {
+                                        $r->print(&Apache::lonhtmlcommon::row_closure(1));
+                                    } else {
+                                        $r->print(&Apache::lonhtmlcommon::row_closure());
+                                    }
+                                }
+                                $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
+                            }
+                        }
+                    }
+                }
+            }
+            $r->print(&close_popup_form());
+        }
     } elsif (($env{'form.action'} eq 'listusers') && 
              ($permission->{'view'} || $permission->{'cusr'})) {
         if ($env{'form.phase'} eq 'bulkchange') {
@@ -4874,6 +5036,32 @@
           .'</script>'."\n";
 }
 
+sub usernamerequest_javascript {
+    my $js = <<ENDJS;
+
+function openusernamereqdisplay(dom,uname,queue) {
+    var url = '/adm/createuser?action=displayuserreq';
+    url += '&domain='+dom+'&username='+uname+'&queue='+queue;
+    var title = 'Account_Request_Browser';
+    var options = 'scrollbars=1,resizable=1,menubar=0';
+    options += ',width=700,height=600';
+    var stdeditbrowser = open(url,title,options,'1');
+    stdeditbrowser.focus();
+    return;
+}
+ 
+ENDJS
+}
+
+sub close_popup_form {
+    my $close= &mt('Close Window');
+    return << "END";
+<p><form name="displayreq" action="" method="post">
+<input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
+</form></p>
+END
+}
+
 sub verify_user_display {
     my ($context) = @_;
     my %lt = &Apache::lonlocal::texthash (
@@ -5127,6 +5315,14 @@
              linktitle => 'Approve or reject author role requests',
             },
             {
+             linktext => 'LON-CAPA Account Requests',
+             icon => 'list-add.png',
+             #help => 'Domain_Username_Approvals',
+             url => '/adm/createuser?action=processusernamereq',
+             permission => $permission->{'cusr'},
+             linktitle => 'Approve or reject LON-CAPA account requests',
+            },
+            {
              linktext => 'Change Log',
              icon => 'document-properties.png',
              #help => 'Course_User_Logs',


More information about the LON-CAPA-cvs mailing list