LP1207396 Patron self-registration web form
authorBill Erickson <berick@esilibrary.com>
Tue, 6 Aug 2013 14:17:29 +0000 (10:17 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 6 Aug 2013 14:17:47 +0000 (10:17 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Register.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/templates/opac/register.tt2

index 55674ab..661b575 100644 (file)
@@ -17,6 +17,12 @@ sub load_patron_reg {
     $ctx->{register} = {};
     $self->collect_register_validation_settings;
 
+    # in the home org unit selector, we only want to present 
+    # org units to the patron which support self-registration.
+    # all other org units will be disabled
+    $ctx->{register}{valid_orgs} = 
+        $self->setting_is_true_for_orgs('opac.allow_pending_user');
+
     # just loading the form
     return Apache2::Const::OK
         unless $cgi->request_method eq 'POST';
@@ -43,6 +49,8 @@ sub load_patron_reg {
     # At least one value was invalid. Exit early and re-render.
     return Apache2::Const::OK if $ctx->{register}{invalid};
 
+    $self->test_requested_username($user);
+
     # user.stage.create will generate a temporary usrname and 
     # link the user and address objects via this username in the DB.
     my $resp = $U->simplereq(
@@ -65,6 +73,29 @@ sub load_patron_reg {
     return Apache2::Const::OK;
 }
 
+# if the username is in use by an actor.usr OR a 
+# pending user treat it as taken and warn the user.
+sub test_requested_username {
+    my ($self, $user) = @_;
+    my $uname = $user->usrname || return;
+    my $e = $self->editor;
+
+    my $taken = $e->search_actor_user(
+        {usrname => $uname, deleted => 'f'}, 
+        {idlist => 1}
+    )->[0];
+
+    $taken = $e->search_staging_actor_stage(
+        {usrname => $uname}, 
+        {idlist => 1}
+    )->[0] unless $taken;
+
+    if ($taken) {
+        $self->ctx->{register}{username_taken} = 1;
+        $user->clear_usrname;
+    }
+}
+
 sub collect_register_validation_settings {
     my $self = shift;
     my $ctx = $self->ctx;
@@ -129,6 +160,8 @@ sub collect_register_validation_settings {
         unless defined $shash->{stgma}{city}{require};
     $shash->{stgma}{post_code}{require} = 1
         unless defined $shash->{stgma}{post_code}{require};
+    $shash->{stgu}{usrname}{show} = 1
+        unless defined $shash->{stgu}{usrname}{show};
 
     $ctx->{register}{settings} = $shash;
 }
index b8dd4f6..e00d674 100644 (file)
@@ -737,7 +737,24 @@ sub load_org_util_funcs {
 
 }
 
+# returns the list of org unit IDs for which the 
+# selected org unit setting returned a true value
+sub setting_is_true_for_orgs {
+    my ($self, $setting) = @_;
+    my $ctx = $self->ctx;
+    my @valid_orgs;
+
+    my $test_org;
+    $test_org = sub {
+        my $org = shift;
+        push (@valid_orgs, $org->id) if
+            $ctx->{get_org_setting}->($org->id, $setting);
+        $test_org->($_) for @{$org->children};
+    };
 
+    $test_org->($ctx->{aou_tree}->());
+    return \@valid_orgs;
+}
     
 
 
index 7522ec9..46c353e 100644 (file)
@@ -25,6 +25,7 @@ register_fields = [
     {class => 'stgu',  name = 'dob', label => l('Date of Birth')},
     {class => 'stgu',  name = 'day_phone', label => l('Phone Number')},
     {class => 'stgu',  name = 'email', label => l('Email Address')}
+    {class => 'stgu',  name = 'usrname', label => l('Requested Username')}
 ];
 %]
 
@@ -40,6 +41,16 @@ register_fields = [
             Please see library staff to complete your registration.
             [% END %]</h3>
 
+            [% IF ctx.register.username_taken %]
+            <p>
+                [% |l %]
+                Note: The selected username may be in use by another
+                patron.  You may select another username when finalizing
+                your registration or in the online catalog.
+                [% END %]
+            </p>
+            [% END %]
+
         [% ELSIF ctx.register.error %]
             <h3>[% |l %]
             An registration error has occurred. Please see library staff.
@@ -49,16 +60,15 @@ register_fields = [
 
         <form method='POST'>
             <table>
-                <!-- TODO <label>s -->
                 <tr>
                     <td>
                         <label for='stgu.home_ou'>[% l('Home Library') %]</label>
                     </td>
                     <td>[% INCLUDE build_org_selector 
-                            # TODO: limit to orgs where pending-allowed
                             name='stgu.home_ou' 
                             value=ctx_org
                             can_have_users_only=1
+                            valid_org_list=ctx.register.valid_orgs
                         %]
                     </td>
                 </tr>
@@ -103,7 +113,7 @@ FOR field_def IN register_fields;
         </span>
     [% ELSIF invalid_regex %]
         <span class='patron-reg-invalid'>
-            [% l('The provided value does not have the correct format') %]
+            [% l('The value entered does not have the correct format') %]
         </span>
     [% END %]
     [% IF example %]
@@ -114,8 +124,8 @@ FOR field_def IN register_fields;
 
     </td>
 </tr>
-[% END;
-# ====> shifting the code back to the right for context %]
+[% END %]
+<!-- ====> shifting the code back to the right for context -->
                     <tr>
                         <td>
                             <a href="[% ctx.opac_root %]/home"