From ff51417c4ae2f799d66748bafc591273ec37fb82 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 6 Aug 2013 10:17:29 -0400 Subject: [PATCH] LP1207396 Patron self-registration web form Signed-off-by: Bill Erickson --- .../lib/OpenILS/WWW/EGCatLoader/Register.pm | 33 ++++++++++++++++++++++ .../perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm | 17 +++++++++++ Open-ILS/src/templates/opac/register.tt2 | 20 +++++++++---- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Register.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Register.pm index 55674ab0d6..661b5758d4 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Register.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Register.pm @@ -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; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index b8dd4f6e4c..e00d674ead 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -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; +} diff --git a/Open-ILS/src/templates/opac/register.tt2 b/Open-ILS/src/templates/opac/register.tt2 index 7522ec9e0f..46c353e0a6 100644 --- a/Open-ILS/src/templates/opac/register.tt2 +++ b/Open-ILS/src/templates/opac/register.tt2 @@ -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 %] + [% IF ctx.register.username_taken %] +

+ [% |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 %] +

+ [% END %] + [% ELSIF ctx.register.error %]

[% |l %] An registration error has occurred. Please see library staff. @@ -49,16 +60,15 @@ register_fields = [
- @@ -103,7 +113,7 @@ FOR field_def IN register_fields; [% ELSIF invalid_regex %] - [% l('The provided value does not have the correct format') %] + [% l('The value entered does not have the correct format') %] [% END %] [% IF example %] @@ -114,8 +124,8 @@ FOR field_def IN register_fields; -[% END; -# ====> shifting the code back to the right for context %] +[% END %] +
[% 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 %]