$ctx->{register}{valid_orgs} =
$self->setting_is_true_for_orgs('opac.allow_pending_user');
+ $self->collect_opt_in_settings;
+
# just loading the form
return Apache2::Const::OK
unless $cgi->request_method eq 'POST';
# attempt to create a pending address
$addr = undef unless $has_addr;
+ # opt-in settings
+ my $settings = [];
+ foreach (grep /^stgs\./, $cgi->param) {
+ my $val = $cgi->param($_);
+ next unless $val; # opt-in settings are always Boolean,
+ # so just skip if not set
+ $self->inspect_register_value($_, $val);
+ s/^stgs.//g;
+ my $setting = Fieldmapper::staging::setting_stage->new;
+ $setting->setting($_);
+ $setting->value('true');
+ push @$settings, $setting;
+ }
+
# At least one value was invalid. Exit early and re-render.
return Apache2::Const::OK if $ctx->{register}{invalid};
my $resp = $U->simplereq(
'open-ils.actor',
'open-ils.actor.user.stage.create',
- $user, $addr
+ $user, $addr, undef, [], $settings
);
if (!$resp or ref $resp) {
}
}
+sub collect_opt_in_settings {
+ my $self = shift;
+ my $e = $self->editor;
+
+ my $types = $e->json_query({
+ select => {cust => ['name']},
+ from => {atevdef => 'cust'},
+ transform => 'distinct',
+ where => {
+ '+atevdef' => {
+ owner => [ map { $_ } @{ $self->ctx->{register}{valid_orgs} } ],
+ active => 't'
+ }
+ }
+ });
+ $self->ctx->{register}{opt_in_settings} =
+ $e->search_config_usr_setting_type({name => [map {$_->{name}} @$types]});
+}
+
# 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 {
sub inspect_register_value {
my ($self, $field_path, $value) = @_;
my $ctx = $self->ctx;
- my ($scls, $field) = split(/\./, $field_path);
+ my ($scls, $field) = split(/\./, $field_path, 2);
+
+ if ($scls eq 'stgs') {
+ my $found = 0;
+ foreach my $type (@{ $self->ctx->{register}{opt_in_settings} }) {
+ if ($field eq $type->name) {
+ $found = 1;
+ }
+ }
+ if (!$found) {
+ $ctx->{register}{invalid}{$scls}{$field}{invalid} = 1;
+ $logger->info("patron register: trying to set an opt-in ".
+ "setting $field that is not allowed.");
+ }
+ return;
+ }
if (!$value) {
</tr>
[% END %]
<!-- ====> shifting the code back to the right for context -->
+ [% IF ctx.register.opt_in_settings.size > 0 %]
+ [% FOR optin IN ctx.register.opt_in_settings %]
+ <tr>
+ <td><label for="stgs.[% optin.name | uri %]'">[% optin.label | html %]</label></td>
+ <td>
+ <input type='checkbox'
+ name='stgs.[% optin.name | uri %]'
+ id='stgs.[% optin.name | uri %]'
+ title="[% optin.label | html %]"
+ ></input>
+ </td>
+ <td><!-- display errors and example text --></td>
+ </tr>
+ [% END %]
+ [% END %]
<tr>
<td colspan='3'>
<a href="[% ctx.opac_root %]/home"