From 873d1c63364ddc0b4593117fd56d64877f20c0d9 Mon Sep 17 00:00:00 2001 From: Nahuel Angelinetti Date: Tue, 2 Dec 2008 11:24:30 +0100 Subject: [PATCH] bug #2757: change the opac login generation This patch change the method used to generate a new login for a user when his informations are modified(memberentry.pl). Before the login are generated with the first letter of lastname and the 9 first letter of the surname, and do not verify the login already exist). Now the login will be lastname.surnameX, where X is an incremented digit if the login already exists. Signed-off-by: Galen Charlton --- C4/Members.pm | 34 +++++++++++++++++++++++++--------- members/memberentry.pl | 6 +----- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 7ee9eb3bbe..49a29ccf67 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -97,15 +97,16 @@ BEGIN { ); #Check data - push @EXPORT, qw( - &checkuniquemember - &checkuserpassword - &Check_Userid - &fixEthnicity - ðnicitycategories - &fixup_cardnumber - &checkcardnumber - ); + push @EXPORT, qw( + &checkuniquemember + &checkuserpassword + &Check_Userid + &Generate_Userid + &fixEthnicity + ðnicitycategories + &fixup_cardnumber + &checkcardnumber + ); } =head1 NAME @@ -799,6 +800,21 @@ sub Check_Userid { } } +sub Generate_Userid { + my ($borrowernumber, $firstname, $surname) = @_; + my $newuid; + my $offset = 0; + do { + $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; + $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; + $newuid = lc("$firstname.$surname"); + $newuid .= $offset unless $offset == 0; + $offset++; + + } while (!Check_Userid($newuid,$borrowernumber)); + + return $newuid; +} sub changepassword { my ( $uid, $member, $digest ) = @_; diff --git a/members/memberentry.pl b/members/memberentry.pl index 3a97e894b8..7bc41e8a42 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -181,13 +181,10 @@ if ($guarantorid eq '') { #builds default userid if ( (defined $newdata{'userid'}) && ($newdata{'userid'} eq '')){ - my $onefirstnameletter = substr($data{'firstname'},0,1); - my $fivesurnameletter = substr($data{'surname'} ,0,9); - $newdata{'userid'}=lc($onefirstnameletter.$fivesurnameletter); + $newdata{'userid'} = Generate_Userid($borrowernumber, $newdata{'firstname'}, $newdata{'surname'}); } $debug and warn join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry); -my $loginexist = 0; my $extended_patron_attributes = (); if ($op eq 'save' || $op eq 'insert'){ if (checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){ @@ -214,7 +211,6 @@ if ($op eq 'save' || $op eq 'insert'){ # Check if the userid is unique unless (Check_Userid($newdata{'userid'},$borrowernumber)) { push @errors, "ERROR_login_exist"; - $loginexist=1; } my $password = $input->param('password'); -- 2.39.5