@@ -, +, @@ - GoogleOpenIDConnectAutoRegister whether it will attempt to auto-register the patron. - GoogleOpenIDConnectDefaultCategory This category code will be used to create Google OpenID Connect patrons. - GoogleOpenIDConnectDefaultBranch' This branch code will be used to create Google OpenID Connect patrons. --- .../bug_16892_AutomaticPatronSystemPreferences.sql | 4 ++++ .../prog/en/modules/admin/preferences/admin.pref | 12 +++++++++++ opac/svc/auth/googleopenidconnect | 25 ++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_16892_AutomaticPatronSystemPreferences.sql --- a/installer/data/mysql/atomicupdate/bug_16892_AutomaticPatronSystemPreferences.sql +++ a/installer/data/mysql/atomicupdate/bug_16892_AutomaticPatronSystemPreferences.sql @@ -0,0 +1,4 @@ +INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES +('GoogleOpenIDConnectAutoRegister', '0',NULL,' Google OpenID Connect logins to auto-register patrons.','YesNo'), +('GoogleOpenIDConnectDefaultCategory','','','This category code will be used to create Google OpenID Connect patrons.','Textarea'), +('GoogleOpenIDConnectDefaultBranch', '','','This branch code will be used to create Google OpenID Connect patrons.','Textarea'); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref @@ -156,6 +156,18 @@ Administration: - "Google OpenID Connect Restrict to domain (or subdomain of this domain): " - pref: GoogleOpenIDConnectDomain - Leave blank for all google domains + - + - pref: GoogleOpenIDConnectAutoRegister + choices: + yes: Allow + no: "Don't Allow" + - users logging in with Google Open ID to automatically register. + - + - pref: GoogleOpenIDConnectDefaultCategory + - Use this category code when automatically registering a Google Open ID patron. + - + - pref: GoogleOpenIDConnectDefaultBranch + - Use this branch code when automatically registering a Google Open ID patron. Share anonymous usage statistics: - - "Share anonymous Koha usage data with the Koha community: " --- a/opac/svc/auth/googleopenidconnect +++ a/opac/svc/auth/googleopenidconnect @@ -34,7 +34,9 @@ use Modern::Perl; use CGI qw ( -utf8 escape ); use C4::Auth qw{ checkauth get_session get_template_and_user }; use C4::Context; +use C4::Members; use C4::Output; +use Koha::Patrons; use LWP::UserAgent; use HTTP::Request::Common qw{ POST }; @@ -179,6 +181,29 @@ elsif ( defined $query->param('code') ) { . ' .' ); } else { + my $auto_registration = C4::Context->preference('GoogleOpenIDConnectAutoRegister') // q{0}; + my $borrower = Koha::Patrons->find( { email => $email } ); + if (! $borrower && $auto_registration==1) { + my $cardnumber = fixup_cardnumber(); + my $firstname = $claims_json->{'given_name'} // q{}; + my $surname = $claims_json->{'family_name'} // q{}; + my $delimiter = $firstname ? q{.} : q{}; + my $userid = $firstname . $delimiter . $surname; + my $categorycode = C4::Context->preference('GoogleOpenIDConnectDefaultCategory') // q{}; + my $branchcode = C4::Context->preference('GoogleOpenIDConnectDefaultBranch') // q{}; + my $password = undef; + $borrower = Koha::Patron->new( { + cardnumber => $cardnumber, + firstname => $firstname, + surname => $surname, + email => $email, + categorycode => $categorycode, + branchcode => $branchcode, + userid => $userid, + password => $password, + } ); + $borrower->store(); + } my ( $userid, $cookie, $session_id ) = checkauth( $query, 1, {}, 'opac', $email ); if ($userid) { # A user with this email is registered in koha --