Default is "Only allowed to change username if it looks like a barcode".
There is a "Lock Username Changes" option to disallow username changing via
the OPAC entirely, useful if syncing usernames to an outside source.
There is also a username change limit disabling option that, if enabled and
the Lock option is disabled, allows the previous behaviour of unlimited
username changes.
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
$self->prepare_extended_user_info;
my $user = $self->ctx->{user};
+ my $lock_usernames = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.lock_usernames');
+ if($lock_usernames == 1) {
+ # Policy says no username changes
+ $self->ctx->{username_change_disallowed} = 1;
+ } else {
+ my $username_unlimit = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.unlimit_usernames');
+ if($username_unlimit != 1) {
+ my $regex_check = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.barcode_regex');
+ if(!$regex_check) {
+ # Default is "starts with a number"
+ $regex_check = '^\d+';
+ }
+ # You already have a username?
+ if($regex_check and $self->ctx->{user}->usrname !~ /$regex_check/) {
+ $self->ctx->{username_change_disallowed} = 1;
+ }
+ }
+ }
+
return Apache2::Const::OK unless
$pending_addr or $replace_addr or $delete_pending;
my $username = $self->cgi->param('username') || '';
my $current_pw = $self->cgi->param('current_pw') || '';
+ $self->prepare_extended_user_info;
+
+ my $allow_change = 1;
+ my $regex_check;
+ my $lock_usernames = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.lock_usernames');
+ if($lock_usernames == 1) {
+ # Policy says no username changes
+ $allow_change = 0;
+ } else {
+ # We want this further down.
+ $regex_check = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.barcode_regex');
+ my $username_unlimit = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.unlimit_usernames');
+ if($username_unlimit != 1) {
+ if(!$regex_check) {
+ # Default is "starts with a number"
+ $regex_check = '^\d+';
+ }
+ # You already have a username?
+ if($regex_check and $self->ctx->{user}->usrname !~ /$regex_check/) {
+ $allow_change = 0;
+ }
+ }
+ }
+ if(!$allow_change) {
+ my $url = $self->apache->unparsed_uri;
+ $url =~ s/update_username/prefs/;
+
+ return $self->generic_redirect($url);
+ }
+
return Apache2::Const::OK
unless $self->cgi->request_method eq 'POST';
}
# New username can't look like a barcode if we have a barcode regex
- my $regex_check = $ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.barcode_regex');
if($regex_check and $username =~ /$regex_check/) {
$ctx->{invalid_username} = $username;
return Apache2::Const::OK;
'coust', 'description'),
'bool', null)
+,( 'opac.lock_usernames', 'glob',
+ oils_i18n_gettext('opac.lock_usernames',
+ 'Lock Usernames',
+ 'coust', 'label'),
+ oils_i18n_gettext('opac.lock_usernames',
+ 'If enabled username changing via the OPAC will be disabled',
+ 'coust', 'description'),
+ 'bool', null)
+
,( 'opac.org_unit_hiding.depth', 'opac',
oils_i18n_gettext('opac.org_unit_hiding.depth',
'Org Unit Hiding Depth',
'coust', 'description'),
'interval', null)
+,( 'opac.unlimit_usernames', 'glob',
+ oils_i18n_gettext('opac.unlimit_usernames',
+ 'Allow multiple username changes',
+ 'coust', 'label'),
+ oils_i18n_gettext('opac.unlimit_usernames',
+ 'If enabled (and Lock Usernames is not set) patrons will be allowed to change their username when it does not look like a barcode. Otherwise username changing in the OPAC will only be allowed when the patron''s username looks like a barcode.',
+ 'coust', 'description'),
+ 'bool', null)
+
,( 'opac.username_regex', 'glob',
oils_i18n_gettext('opac.username_regex',
'Patron username format',
</div>[% l("Username") %]
</td>
<td class='light_border'>[% ctx.user.usrname | html %]</td>
+ [% IF ctx.username_change_disallowed %]
+ <td></td>
+ [% ELSE %]
<td class='light_border'><a href='update_username'>[% l("Change") %]</a></td>
+ [% END %]
</tr>
<tr>
<td class='color_4 light_border'>[% l("Password") %]</td>
req.callback(myopacDrawNotes);
req.send();
+ r = fetchOrgSettingDefault(G.user.home_ou(), 'opac.lock_usernames');
+ if(r) {
+ // No changing username - Policy Lock
+ hideMe($('myopac_summary_username_change'));
+ } else {
+ r = fetchOrgSettingDefault(G.user.home_ou(), 'opac.unlimit_usernames');
+ if(!r) {
+ r = fetchOrgSettingDefault(G.user.home_ou(), 'opac.barcode_regex');
+ if(r) REGEX_BARCODE = new RegExp(r);
+
+ if(!user.usrname().match(REGEX_BARCODE)) {
+ // No changing username - You already have one!
+ hideMe($('myopac_summary_username_change'));
+ }
+ }
+ }
var tbody = $('myopac_addr_tbody');
var template;
return;
}
- r = fetchOrgSettingDefault(globalOrgTree.id(), 'opac.barcode_regex');
+ r = fetchOrgSettingDefault(G.user.home_ou(), 'opac.barcode_regex');
if(r) REGEX_BARCODE = new RegExp(r);
if(username.match(REGEX_BARCODE)) {