$self->prepare_extended_user_info;
my $user = $self->ctx->{user};
+ # PINES - check whether or not to provide account renewal link
+ if ($self->ctx->{user}->billing_address) {
+ $self->ctx->{valid_billing_address} = $self->ctx->{user}->billing_address->valid;
+ } else {
+ $self->ctx->{valid_billing_address} = 0;
+ }
+ if ($self->ctx->{user}->mailing_address) {
+ $self->ctx->{valid_mailing_address} = $self->ctx->{user}->mailing_address->valid;
+ } else {
+ $self->ctx->{valid_mailing_address} = 0;
+ }
+ $self->check_account_exp();
+
my $lock_usernames = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.lock_usernames');
if(defined($lock_usernames) and $lock_usernames == 1) {
# Policy says no username changes
my $self = shift;
my $e = $self->editor;
-
my $stat = $self->_load_user_with_prefs;
return $stat if $stat;
pub => 't'
})
);
+
+ # PINES - need to make sure we're retrieving current info
+ $self->prepare_extended_user_info;
+ # PINES - check whether or not to provide account renewal link
+ if ($self->ctx->{user}->billing_address) {
+ $self->ctx->{valid_billing_address} = $self->editor->retrieve_actor_user_address($self->ctx->{user}->billing_address)->valid;
+ } else {
+ $self->ctx->{valid_billing_address} = 0;
+ }
+ if ($self->ctx->{user}->mailing_address) {
+ $self->ctx->{valid_mailing_address} = $self->editor->retrieve_actor_user_address($self->ctx->{user}->mailing_address)->valid;
+ } else {
+ $self->ctx->{valid_mailing_address} = 0;
+ }
+ $self->check_account_exp();
+
return $self->prepare_fines($limit, $offset) || Apache2::Const::OK;
}
return Apache2::Const::OK;
}
+# PINES - check whether patron has standing penalties that should block
+# online account renewal
+sub has_penalties {
+ my $self = shift;
+ my $ctx = $self->ctx;
+ my $user = $self->ctx->{user};
+ my $e = new_editor(xact => 1);
+
+ #I'm sure there is a way to combine the following standing penalty checks, but this is working for now
+
+ #check for INVALID_PATRON_ADDRESS
+ my $findpenalty_address = $e->search_config_standing_penalty({name => 'INVALID_PATRON_ADDRESS'})->[0];
+ my $searchpenalty_address = $e->search_actor_user_standing_penalty({
+ usr => $user->id,
+ standing_penalty => $findpenalty_address->id,
+ '-or' => [
+ {stop_date => undef},
+ {stop_date => {'>' => 'now'}}
+ ]
+ });
+
+ #check for INVALID_PATRON_DAY_PHONE
+ my $findpenalty_phone = $e->search_config_standing_penalty({name => 'INVALID_PATRON_DAY_PHONE'})->[0];
+ my $searchpenalty_phone = $e->search_actor_user_standing_penalty({
+ usr => $user->id,
+ standing_penalty => $findpenalty_phone->id,
+ '-or' => [
+ {stop_date => undef},
+ {stop_date => {'>' => 'now'}}
+ ]
+ });
+
+ #check for PATRON_IN_COLLECTIONS
+ my $findpenalty_coll = $e->search_config_standing_penalty({name => 'PATRON_IN_COLLECTIONS'})->[0];
+ my $searchpenalty_coll = $e->search_actor_user_standing_penalty({
+ usr => $user->id,
+ standing_penalty => $findpenalty_coll->id,
+ '-or' => [
+ {stop_date => undef},
+ {stop_date => {'>' => 'now'}}
+ ]
+ });
+
+ #check for alerting block
+ my $findpenalty_alertblock = $e->search_config_standing_penalty({name => 'STAFF_CHR'})->[0];
+ my $searchpenalty_alertblock = $e->search_actor_user_standing_penalty({
+ usr => $user->id,
+ standing_penalty => $findpenalty_alertblock->id,
+ '-or' => [
+ {stop_date => undef},
+ {stop_date => {'>' => 'now'}}
+ ]
+ });
+
+ #check for PATRON_TEMP_RENEWAL
+ my $findpenalty_temp = $e->search_config_standing_penalty({name => 'PATRON_TEMP_RENEWAL'})->[0];
+ my $searchpenalty_temp = $e->search_actor_user_standing_penalty({
+ usr => $user->id,
+ standing_penalty => $findpenalty_temp->id,
+ '-or' => [
+ {stop_date => undef},
+ {stop_date => {'>' => 'now'}}
+ ]
+ });
+
+ if (@$searchpenalty_address || @$searchpenalty_coll || @$searchpenalty_phone || @$searchpenalty_alertblock) {
+ $ctx->{haspenalty} = 1;
+ } else {
+ $ctx->{haspenalty} = 0;
+ }
+
+ if (@$searchpenalty_temp) {
+ $ctx->{hastemprenew} = 1;
+ } else {
+ $ctx->{hastemprenew} = 0;
+ }
+
+ return;
+}
+
+# PINES - check whether or not to show account renewal link
+sub check_account_exp {
+ my $self = shift;
+ my $ctx = $self->ctx;
+ $self->update_dashboard_stats();
+
+ #make sure patron is in an eligible perm group for renewal
+ my $grp = new_editor()->retrieve_permission_grp_tree($ctx->{user}->profile);
+
+ if ($grp->erenew eq 't') {
+ $ctx->{eligible_permgroup} = 1;
+ } else {
+ $ctx->{eligible_permgroup} = 0;
+ }
+
+ #check for various standing penalties that would block an online renewal
+ $self->has_penalties();
+
+ #check for other problems that would block an online renewal
+ if ($ctx->{user}->active ne 't') { #user is no longer active
+ $ctx->{hasproblem} = 1;
+ } elsif ($ctx->{haspenalty} eq 1) { #user has a standing penalty block
+ $ctx->{hasproblem} = 1;
+ } elsif ($ctx->{user}->barred eq 't') { #user is barred
+ $ctx->{hasproblem} = 1;
+ } elsif ($ctx->{valid_billing_address} ne 't') { #user has invalid billing address
+ $ctx->{hasproblem} = 1;
+ } elsif ($ctx->{valid_mailing_address} ne 't') { #user has invalid mailing address
+ $ctx->{hasproblem} = 1;
+ } else {
+ $ctx->{hasproblem} = 0;
+ }
+
+ #determine which message to show (if any)
+ my $cache = OpenSRF::Utils::Cache->new('global');
+ $cache->put_cache('account_renew_ok','false',3600);
+
+ if ($ctx->{hastemprenew} eq 1) { #user already has active temp renewal
+ $ctx->{account_renew_message} = '<div style="border:2px solid green;padding:5px;">Your account
+ could only be temporarily renewed because your address changed. Please visit your nearest PINES
+ library with your current proof of address to complete your account renewal.</div>';
+ } elsif (DateTime->today->add(days=>30) lt $ctx->{user}->expire_date) {
+ #expiration date is too far in future - don't show message
+ $ctx->{account_renew_message} = '';
+ } elsif ($ctx->{hasproblem} eq 1 or $ctx->{eligible_permgroup} eq 0) { #see other problems above
+ $ctx->{account_renew_message} = '<div style="border:2px solid green;padding:5px;">Your account is
+ due for renewal, but it cannot be renewed online. Please visit your nearest PINES
+ library with your current ID and proof of address to update and renew your account.</div>';
+ } elsif ($ctx->{user_stats}->{fines}->{balance_owed} gt 0) { #user has fines
+ $ctx->{account_renew_message} = '<div style="border:2px solid green;padding:5px;">Your account
+ is due for renewal. Please pay your outstanding fines in order to renew your account.</div>';
+ } else {
+ $ctx->{account_renew_message} = '<span class="light_border"><a class="btn btn-sm btn-action"
+ href="/eg/opac/renew-account"><i class="fas fa-user-cog"></i>Click here to renew your account</a></span>';
+ $cache->put_cache('account_renew_ok','true',3600);
+ }
+
+ return 1;
+}
+
1;
use OpenSRF::Utils::JSON;
use OpenSRF::Utils qw/:datetime/;
use OpenILS::Utils::Fieldmapper;
+use OpenSRF::Utils::Cache;
use OpenILS::Application::AppUtils;
use OpenILS::Utils::CStoreEditor qw/:funcs/;
use OpenILS::Event;
$Data::Dumper::Indent = 0;
my $U = 'OpenILS::Application::AppUtils';
-my @api_fields = (
+my $update_type = 'register';
+
+my @api_fields_renew = (
+ {name => 'vendor_username', required => 1},
+ {name => 'vendor_password', required => 1},
+ {name => 'email', class => 'au'},
+ {name => 'day_phone', class => 'au', required => 1},
+ {name => 'home_ou', class => 'au'},
+ {name => 'pref_first_given_name', class => 'au'},
+ {name => 'pref_second_given_name', class => 'au'},
+ {name => 'pref_family_name', class => 'au'},
+ {name => 'physical_id', class => 'aua'},
+ {name => 'physical_street1', class => 'aua'},
+ {name => 'physical_street1_name'},
+ {name => 'physical_street2', class => 'aua'},
+ {name => 'physical_city', class => 'aua'},
+ {name => 'physical_post_code', class => 'aua'},
+ {name => 'physical_county', class => 'aua'},
+ {name => 'physical_state', class => 'aua'},
+ {name => 'physical_country', class => 'aua'},
+ {name => 'mailing_id', class => 'aua'},
+ {name => 'mailing_street1', class => 'aua'},
+ {name => 'mailing_street1_name'},
+ {name => 'mailing_street2', class => 'aua'},
+ {name => 'mailing_city', class => 'aua'},
+ {name => 'mailing_post_code', class => 'aua'},
+ {name => 'mailing_county', class => 'aua'},
+ {name => 'mailing_state', class => 'aua'},
+ {name => 'mailing_country', class => 'aua'},
+ {name => 'voter_registration', class => 'asvr'}
+);
+
+my @api_fields_register = (
{name => 'vendor_username', required => 1},
{name => 'vendor_password', required => 1},
{name => 'first_given_name', class => 'au', required => 1},
{name => 'ident_type', class => 'au', required => 1},
{name => 'ident_value', class => 'au', required => 1},
{name => 'ident_value2',
- class => 'au',
- notes => "AKA parent/guardian",
- required_if => 'Patron is less than 18 years old'
+ class => 'au',
+ notes => "AKA parent/guardian",
+ required_if => 'Patron is less than 18 years old'
},
{name => 'pref_first_given_name', class => 'au'},
{name => 'pref_second_given_name', class => 'au'},
{name => 'in_house_registration', required => 1},
);
-
-# TODO: wrap the following in a check for a library setting as to whether or not
-# to require emailed verification
-
-## Random 6-character alpha-numeric code that avoids look-alike characters
-## https://ux.stackexchange.com/questions/53341/are-there-any-letters-numbers-that-should-be-avoided-in-an-id
-## Also exclude vowels to avoid creating any real (potentially offensive) words.
-#my @code_chars = ('C','D','F','H','J'..'N','P','R','T','V','W','X','3','4','7','9');
-#sub generate_verify_code {
-# my $string = '';
-# $string .= $code_chars[rand @code_chars] for 1..6;
-# return $string;
-#}
-#
-#
-## only if we're verifying the card via email
-#sub load_ecard_verify {
-# my $self = shift;
-# my $cgi = $self->cgi;
-# $self->collect_header_footer;
-#
-# # Loading the form.
-# return Apache2::Const::OK if $cgi->request_method eq 'GET';
-#
-# #$self->verify_ecard;
-# return Apache2::Const::OK;
-#}
-#
-#sub verify_ecard {
-# my $self = shift;
-# my $cgi = $self->cgi;
-# my $ctx = $self->ctx;
-# $self->log_params;
-#
-# my $verify_code = $ctx->{verify_code} = $cgi->param('verification_code');
-# my $barcode = $ctx->{barcode} = $cgi->param('barcode');
-#
-# $ctx->{verify_failed} = 1;
-#
-# my $e = new_editor();
-#
-# my $au = $e->search_actor_user({
-# profile => $PROVISIONAL_ECARD_GRP,
-# ident_type => $ECARD_VERIFY_IDENT,
-# ident_value => $verify_code
-# })->[0];
-#
-# if (!$au) {
-# $logger->warn(
-# "ECARD: No provisional ecard found with code $verify_code");
-# sleep 2; # Mitigate brute-force attacks
-# return;
-# }
-#
-# my $card = $e->search_actor_card({
-# usr => $au->id,
-# barcode => $barcode
-# })->[0];
-#
-# if (!$card) {
-# $logger->warn("ECARD: Failed to match verify code ".
-# "($verify_code) with provided barcode ($barcode)");
-# sleep 2; # Mitigate brute-force attacks
-# return;
-# }
-#
-# # Verification looks good. Update the account.
-#
-# my $grp = new_editor()->retrieve_permission_grp_tree($FULL_ECARD_GRP);
-#
-# $au->profile($grp->id);
-# $au->expire_date(
-# DateTime->now(time_zone => 'local')->add(
-# seconds => interval_to_seconds($grp->perm_interval))->iso8601()
-# );
-#
-# $e->xact_begin;
-#
-# unless ($e->update_actor_user($au)) {
-# $logger->error("ECARD update failed for $barcode: " . $e->die_event);
-# return;
-# }
-#
-# $e->commit;
-# $logger->info("ECARD: Update to full ecard succeeded for $barcode");
-#
-# $ctx->{verify_success} = 1;
-# $ctx->{verify_failed} = 0;
-#
-# return;
-#}
-
-
sub log_params {
my $self = shift;
my $cgi = $self->cgi;
# Strip data we don't want to publish.
my @doc_fields;
- for my $field_info (@api_fields) {
+ for my $field_info (@api_fields_register) {
my $doc_info = {};
for my $info_key (keys %$field_info) {
$doc_info->{$info_key} = $field_info->{$info_key}
$ctx->{response}->{messages} = [fields => \@doc_fields];
$ctx->{response}->{status} = 'API_OK';
+
return $self->compile_response;
}
}
$ctx->{response}->{status} = 'DATA_OK';
+
return $self->compile_response;
}
my $ctx = $self->ctx;
my $cgi = $self->cgi;
+ #determine whether this is a new registration or a renewal
+ if ($cgi->param('patron_id') > 1) {
+ $update_type = 'renew';
+ } else {
+ $update_type = 'register';
+ }
+
+ #If this is a renewal, double-check that they are eligible to renew
+ my $cache = OpenSRF::Utils::Cache->new('global');
+ if ($update_type eq 'renew') {
+ if ($cache->get_cache("account_renew_ok") && $cache->get_cache("account_renew_ok") eq 'true') {
+ } else {
+ $logger->error("ERENEW - User not in correct status to renew account");
+ return $self->compile_response;
+ }
+ }
+
$self->log_params;
my $testmode = $cgi->param('testmode') || '';
return $self->handle_testmode_api if $testmode eq 'API';
return $self->handle_datamode_api($datamode) if $datamode;
- return $self->compile_response unless $self->make_user;
- return $self->compile_response unless $self->add_addresses;
- return $self->compile_response unless $self->check_dupes;
- return $self->compile_response unless $self->add_card;
- return $self->compile_response unless $self->add_survey_responses;
- return $self->compile_response unless $self->save_user;
- return $self->compile_response unless $self->add_usr_settings;
- return $self->compile_response if $ctx->{response}->{status};
-
- $U->create_events_for_hook(
- 'au.create.ecard', $ctx->{user}, $ctx->{user}->home_ou);
+ # Accommodate reg vs renew
+ if ($update_type eq 'register') {
+ return $self->compile_response unless $self->make_user;
+ return $self->compile_response unless $self->add_addresses;
+ return $self->compile_response unless $self->check_dupes;
+ return $self->compile_response unless $self->add_card;
+ return $self->compile_response unless $self->add_survey_responses;
+ return $self->compile_response unless $self->save_user;
+ return $self->compile_response unless $self->add_usr_settings;
+ return $self->compile_response if $ctx->{response}->{status};
+
+ $U->create_events_for_hook(
+ 'au.create.ecard', $ctx->{user}, $ctx->{user}->home_ou);
+ } else {
+ return $self->compile_response unless $self->update_user;
+ return $self->compile_response unless $self->update_addresses;
+ return $self->compile_response unless $self->add_survey_responses;
+ return $self->compile_response unless $self->save_user;
+ return $self->compile_response if $ctx->{response}->{status};
+ }
+ # Add extra info to response message
$ctx->{response}->{status} = 'OK';
- $ctx->{response}->{barcode} = $ctx->{user}->card->barcode;
+
+ if ($update_type eq 'renew') {
+ #New expiration date
+ $ctx->{response}->{expire_date} = $ctx->{user}->expire_date;
+ #Mark whether this is a temporary renewal or not
+ my $findpenalty_temp = $e->search_config_standing_penalty({name => 'PATRON_TEMP_RENEWAL'})->[0];
+ my $searchpenalty_temp = $e->search_actor_user_standing_penalty({
+ usr => $cgi->param('patron_id'),
+ standing_penalty => $findpenalty_temp->id,
+ '-or' => [
+ {stop_date => undef},
+ {stop_date => {'>' => 'now'}}
+ ]
+ });
+ if (@$searchpenalty_temp) {
+ $ctx->{response}->{temp_renew} = 1;
+ } else {
+ $ctx->{response}->{temp_renew} = 0;
+ }
+ #set renewal flag in cache to false to prevent user from refreshing the page and submitting again
+ $cache->put_cache('account_renew_ok','false',3600);
+ } else {
+ $ctx->{response}->{barcode} = $ctx->{user}->card->barcode;
+ }
return $self->compile_response;
}
return 1;
}
-
sub compile_response {
my $self = shift;
my $ctx = $self->ctx;
+
$self->apache->content_type("application/json; charset=utf-8");
$ctx->{response} = OpenSRF::Utils::JSON->perl2JSON($ctx->{response});
$logger->info("ECARD responding with " . $ctx->{response});
- return Apache2::Const::OK;
-}
-my %keep_case = (usrname => 1, passwd => 1, email => 1);
-sub upperclense {
- my $self = shift;
- my $field = shift;
- my $value = shift;
- $value = uc($value) unless $keep_case{$field};
- $value = lc($value) if $field eq 'email'; # force it
- $value =~ s/(^\s*|\s*$)//g;
- return $value;
+ return Apache2::Const::OK;
}
-# Create actor.usr perl object and populate column data
+# Create actor.usr perl object and populate column data (for new registration)
sub make_user {
my $self = shift;
my $ctx = $self->ctx;
$au->isnew(1);
$au->net_access_level(1); # Filtered
$au->name_keywords($in_house ? 'quipu_inhouse' : 'quipu_remote');
+
my $home_ou = $cgi->param('home_ou');
my $perm_grp = $U->ou_ancestor_setting_value(
seconds => interval_to_seconds($grp->perm_interval))->iso8601()
);
- for my $field_info (@api_fields) {
+ for my $field_info (@api_fields_register) {
my $field = $field_info->{name};
next unless $field_info->{class} eq 'au';
$val = undef if $field eq 'day_phone' && $val eq '--';
$self->verify_dob($val) if $field eq 'dob' && $val;
+
$au->$field($val);
}
return $ctx->{user} = $au;
}
+# If existing account, update instead of create
+sub update_user {
+
+ my $self = shift;
+ my @extra_flesh = @_;
+ my $e = $self->editor;
+ my $ctx = $self->ctx;
+ my $cgi = $self->cgi;
+
+ # Grab user id, retrieve patron info from db and create patron object
+ my $patron_id = $cgi->param('patron_id');
+
+ my $au = $self->editor->retrieve_actor_user([$patron_id,
+ {
+ flesh => 1,
+ flesh_fields => {
+ au => ['billing_address', 'mailing_address', 'groups', 'permissions', 'standing_penalties']
+ }
+ }
+ ]);
+ #indicate that this is an update, not a new record
+ $au->isnew(0);
+
+ # Replace values in patron object with new data
+
+ # Need to append new keyword for use in reports later
+ my $orig_kw = $au->name_keywords;
+ my $dt = DateTime->now;
+ my $dty = $dt->year;
+ my $dtm = $dt->month;
+ if ($orig_kw ne '') {
+ $au->name_keywords("$orig_kw quipu_renew_$dty$dtm");
+ } else {
+ $au->name_keywords("quipu_renew_$dty$dtm");
+ }
+
+ # Temp renewal is only 30 days, otherwise use perm_interval
+ # If perm group is Homebound or GLS, allow full renewal
+ my $temp_renewal = $cgi->param('temp_renewal');
+ my $grp = new_editor()->retrieve_permission_grp_tree($au->profile);
+
+ if ($temp_renewal eq '1' && $grp->name ne 'GLS' && $grp->name ne 'Homebound') {
+ $au->expire_date(
+ DateTime->now(time_zone => 'local')->add(
+ seconds => interval_to_seconds('30 days'))->iso8601()
+ );
+ # Add temp renewal standing penalty to account
+ $self->apply_temp_renewal_penalty;
+ } else {
+ $au->expire_date(
+ DateTime->now(time_zone => 'local')->add(
+ seconds => interval_to_seconds($grp->perm_interval))->iso8601()
+ );
+ }
+
+ # loop through fields submitted by quipu
+ for my $field_info (@api_fields_renew) {
+ my $field = $field_info->{name};
+ next unless $field_info->{class} eq 'au';
+
+ my $val = $cgi->param($field);
+
+ if ($field_info->{required} && !$val) {
+ my $msg = "Value required for field: '$field'";
+ $ctx->{response}->{status} = 'INVALID_PARAMS';
+ push(@{$ctx->{response}->{messages}}, $msg);
+ $logger->error("E-RENEW $msg");
+ }
+
+ $val = undef if $field eq 'day_phone' && $val eq '--';
+ $val = $au->home_ou if $field eq 'home_ou' && $val eq '';
+
+ $au->$field($val);
+ }
+
+ return $ctx->{user} = $au;
+}
+
# Card generation must occur after the user is saved in the DB.
sub add_card {
my $self = shift;
return 1;
}
-# returns true if the addresses contain all of the same values.
-sub addrs_match {
- my ($self, $addr1, $addr2) = @_;
- for my $field ($addr1->real_fields) {
- return 0 if ($addr1->$field() || '') ne ($addr2->$field() || '');
- }
- return 1;
-}
-
-
sub add_addresses {
my $self = shift;
my $cgi = $self->cgi;
# Confirm we have values for all of the required fields.
# Apply values to our in-progress address object.
- for my $field_info (@api_fields) {
+ for my $field_info (@api_fields_register) {
my $field = $field_info->{name};
next unless $field =~ /physical|mailing/;
next if $field =~ /street1_/;
return 1;
}
+sub update_addresses {
+ my $self = shift;
+ my $cgi = $self->cgi;
+ my $ctx = $self->ctx;
+ my $e = $ctx->{editor};
+ my $user = $ctx->{user};
+
+ my $physical_addr = Fieldmapper::actor::user_address->new;
+ $physical_addr->id($user->billing_address->id);
+ $physical_addr->usr($user->id);
+ $physical_addr->address_type('PHYSICAL');
+ $physical_addr->within_city_limits($user->billing_address->within_city_limits);
+ $physical_addr->valid('t');
+ $physical_addr->pending('f');
+
+ my $mailing_addr = Fieldmapper::actor::user_address->new;
+ $mailing_addr->id($user->mailing_address->id);
+ $mailing_addr->usr($user->id);
+ $mailing_addr->address_type('MAILING');
+ $mailing_addr->within_city_limits($user->mailing_address->within_city_limits);
+ $mailing_addr->valid('t');
+ $mailing_addr->pending('f');
+
+ # Confirm we have values for all of the required fields.
+ # Apply values to our in-progress address object.
+ for my $field_info (@api_fields_renew) {
+ my $field = $field_info->{name};
+ next unless $field =~ /physical|mailing/;
+ next if $field =~ /street1_/;
+
+ my $val = $cgi->param($field);
+
+ if ($field_info->{required} && !$val) {
+ my $msg = "Value required for field: '$field'";
+ $ctx->{response}->{status} = 'INVALID_PARAMS';
+ push(@{$ctx->{response}->{messages}}, $msg);
+ $logger->error("E-RENEW $msg");
+ }
+
+ if ($field =~ /physical/) {
+ (my $col_field = $field) =~ s/physical_//g;
+ $physical_addr->$col_field($val) if $val;
+ } else {
+ (my $col_field = $field) =~ s/mailing_//g;
+ $mailing_addr->$col_field($val) if $val;
+ }
+ }
+
+ # Determine what exactly to do with addresses
+ if ($physical_addr->id eq $mailing_addr->id && $physical_addr->street1 eq $mailing_addr->street1) {
+ # if one address & stays at one address, just update it (don't need to do both physical & mailing)
+ $mailing_addr->isnew(0);
+ $mailing_addr->ischanged(1);
+ } elsif ($physical_addr->id eq $mailing_addr->id && $physical_addr->street1 ne $mailing_addr->street1) {
+ # if one address splitting to two addresses, update the first and create a second address entry
+ $physical_addr->isnew(0);
+ $physical_addr->ischanged(1);
+ $mailing_addr->isnew(1);
+ $mailing_addr->id(-1);
+ } elsif ($physical_addr->id ne $mailing_addr->id && $physical_addr->street1 eq $mailing_addr->street1) {
+ # if there were previously 2 addresses, but there is only one address now, use the updated single address entry for both
+ $physical_addr->isnew(0);
+ $physical_addr->ischanged(1);
+ $mailing_addr->isnew(0);
+ $mailing_addr->ischanged(1);
+ $mailing_addr->id($physical_addr->id);
+ } else {
+ # otherwise, update existing entries
+ $physical_addr->isnew(0);
+ $physical_addr->ischanged(1);
+ $mailing_addr->isnew(0);
+ $mailing_addr->ischanged(1);
+ }
+
+ # exit if there were any errors above.
+ return undef if $ctx->{response}->{status};
+
+ $user->billing_address($physical_addr);
+ $user->mailing_address($mailing_addr);
+ $user->addresses([$physical_addr, $mailing_addr]);
+
+ return 1;
+}
+
sub add_usr_settings {
my $self = shift;
my $cgi = $self->cgi;
my $answer = $cgi->param('voter_registration');
my $survey_response = Fieldmapper::action::survey_response->new;
+
$survey_response->id(-1);
$survey_response->isnew(1);
- $survey_response->survey(1); # voter registration survey
+ $survey_response->survey(1);
$survey_response->question(1);
$survey_response->answer($answer);
return 1;
}
-# TODO: this is KCLS-specific, but maybe we can make it something
-# generic for adding stat cats to the patron
-
-#sub add_stat_cats {
-# my $self = shift;
-# my $cgi = $self->cgi;
-# my $user = $self->ctx->{user};
-#
-# my $ds_map = Fieldmapper::actor::stat_cat_entry_user_map->new;
-# $ds_map->isnew(1);
-# $ds_map->stat_cat(12);
-# $ds_map->stat_cat_entry('KCLS');
-#
-# my $events = $cgi->param('events_mailing');
-# my $em_map = Fieldmapper::actor::stat_cat_entry_user_map->new;
-# $em_map->isnew(1);
-# $em_map->stat_cat(3);
-# $em_map->stat_cat_entry($events ? 'Y' : 'N');
-#
-# my $foundation = $cgi->param('foundation_mailing');
-# my $fm_map = Fieldmapper::actor::stat_cat_entry_user_map->new;
-# $fm_map->isnew(1);
-# $fm_map->stat_cat(4);
-# $fm_map->stat_cat_entry($foundation ? 'Y' : 'N');
-#
-# $user->stat_cat_entries([$ds_map, $em_map, $fm_map]);
-# return 1;
-#}
-
# Returns true if no dupes found, false if dupes are found.
sub check_dupes {
my $self = shift;
$logger->info("ECARD found potential duplicate patrons: @$ids");
-# if (my $streetname = $self->cgi->param('physical_street1_name')) {
-# # We found matching patrons. Perform a secondary check on the
-# # address street name only.
-#
-# $logger->info("ECARD secondary search on street name: $streetname");
-#
-# my $addr_ids = $e->search_actor_user_address(
-# { usr => $ids,
-# street1 => {'~*' => "(^| )$streetname( |\$)"}
-# }, {idlist => 1}
-# );
-#
-# if (@$addr_ids) {
-# # we don't really care what patrons match at this point,
-# # only whether a match is found.
-# $ids = [1];
-# $logger->info("ECARD secondary address check match(es) ".
-# "found on address(es) @$addr_ids");
-#
-# } else {
-# $ids = [];
-# $logger->info(
-# "ECARD secondary address check found no matches");
-# }
-#
-# } else {
-# $ids = [];
-# # unclear if this is a possibility -- err on the side of allowing
-# # the registration.
-# $logger->info("ECARD found possible patron match but skipping ".
-# "secondary street name check -- no street name was provided");
-# }
-#
-# return 1 if @$ids == 0;
-
$ctx->{response}->{status} = 'DUPLICATE';
$ctx->{response}->{messages} = ['first_given_name',
'family_name', 'dob'];
my $ctx = $self->ctx;
my $cgi = $self->cgi;
my $user = $ctx->{user};
+ my $update_type = $user->isnew;
my $resp = $U->simplereq(
'open-ils.actor',
$resp = {textcode => 'UNKNOWN_ERROR'} unless $resp;
if ($U->is_event($resp)) {
+ my $msg = '';
- my $msg = "Error creating user account: " . $resp->{textcode};
- $logger->error("ECARD: $msg");
+ if ($update_type eq '1') {
+ $msg = "Error creating user account: " . $resp->{textcode};
+ $logger->error("ECARD: $msg");
+ $ctx->{response}->{status} = 'CREATE_ERR';
+ } else {
+ $msg = "Error updating user account: " . $resp->{textcode};
+ $logger->error("E-RENEW: $msg");
+ $ctx->{response}->{status} = 'UPDATE_ERR';
+ }
- $ctx->{response}->{status} = 'CREATE_ERR';
$ctx->{response}->{messages} = [{msg => $msg, pid => $$}];
return 0;
return 1;
}
+sub apply_temp_renewal_penalty {
+
+ my $self = shift;
+ my $ctx = $self->ctx;
+ my $cgi = $self->cgi;
+ my $patron_id = $cgi->param('patron_id');
+
+ my $e = new_editor(xact => 1);
+ my $ptype = $e->search_config_standing_penalty({name => 'PATRON_TEMP_RENEWAL'})->[0];
+
+ my $penalty = Fieldmapper::actor::user_standing_penalty->new;
+ $penalty->usr($patron_id);
+ $penalty->org_unit(1);
+ $penalty->standing_penalty($ptype->id);
+
+ my $aum = Fieldmapper::actor::usr_message->new;
+ $aum->create_date('now');
+ $aum->sending_lib(1);
+ $aum->title('Temporary Account Renewal');
+ $aum->usr($penalty->usr);
+ $aum->message('Patron renewed online with an address change so was given a 30-day
+ temporary account renewal. Please archive this message after the address is
+ verified and the renewal date extended.');
+ $aum->pub(0);
+
+ $aum = $e->create_actor_usr_message($aum);
+ unless($aum) {
+ $e->rollback;
+ return 0;
+ }
+
+ $penalty->usr_message($aum->id);
+
+ unless($e->create_actor_user_standing_penalty($penalty)) {
+ $e->rollback;
+ return 0;
+ }
+
+ $e->commit;
+ return 1;
+}
+
+
1;