$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';
# 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(
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;
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;
}
}
+# 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;
+}
{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')}
];
%]
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.
<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>
</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 %]
</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"