From b1078a8eab4bca8b493f91b0ae0f7d773ac6f61e Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Thu, 29 Jul 2021 15:40:07 +0200
Subject: [PATCH] Bug 28786: Add new DB column borrowers.auth_method
Content-Type: text/plain; charset=utf-8

Sponsored-by: Orex Digital

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
---
 installer/data/mysql/atomicupdate/two-fa.perl | 12 ++++++++++++
 installer/data/mysql/kohastructure.sql        |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/installer/data/mysql/atomicupdate/two-fa.perl b/installer/data/mysql/atomicupdate/two-fa.perl
index 5d62189b1c..f11c0d0684 100644
--- a/installer/data/mysql/atomicupdate/two-fa.perl
+++ b/installer/data/mysql/atomicupdate/two-fa.perl
@@ -15,6 +15,18 @@ if( CheckVersion( $DBversion ) ) {
     if( !column_exists( 'deletedborrowers', 'secret' ) ) {
       $dbh->do(q{
           ALTER TABLE deletedborrowers ADD COLUMN `secret` MEDIUMTEXT COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Secret for 2FA' AFTER `password`
+        });
+    }
+
+    if( !column_exists( 'borrowers', 'auth_method' ) ) {
+      $dbh->do(q{
+          ALTER TABLE borrowers ADD COLUMN `auth_method` ENUM('password', 'two-factor') NOT NULL DEFAULT 'password' COMMENT 'Authentication method' AFTER `secret`
+      });
+    }
+
+    if( !column_exists( 'deletedborrowers', 'auth_method' ) ) {
+      $dbh->do(q{
+          ALTER TABLE deletedborrowers ADD COLUMN `auth_method` ENUM('password', 'two-factor') NOT NULL DEFAULT 'password' COMMENT 'Authentication method' AFTER `secret`
       });
     }
 
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index a3307dc511..ba21a686db 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -1424,6 +1424,7 @@ CREATE TABLE `borrowers` (
   `sex` varchar(1) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s gender',
   `password` varchar(60) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s Bcrypt encrypted password',
   `secret` MEDIUMTEXT COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Secret for 2FA',
+  `auth_method` ENUM('password', 'two-factor') NOT NULL DEFAULT 'password' COMMENT 'Authentication method',
   `flags` int(11) DEFAULT NULL COMMENT 'will include a number associated with the staff member''s permissions',
   `userid` varchar(75) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s opac and/or staff interface log in',
   `opacnote` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'a note on the patron/borrower''s account that is visible in the OPAC and staff interface',
@@ -2433,6 +2434,7 @@ CREATE TABLE `deletedborrowers` (
   `sex` varchar(1) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s gender',
   `password` varchar(60) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s encrypted password',
   `secret` MEDIUMTEXT COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Secret for 2FA',
+  `auth_method` ENUM('password', 'two-factor') NOT NULL DEFAULT 'password' COMMENT 'Authentication method',
   `flags` int(11) DEFAULT NULL COMMENT 'will include a number associated with the staff member''s permissions',
   `userid` varchar(75) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'patron/borrower''s opac and/or staff interface log in',
   `opacnote` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'a note on the patron/borrower''s account that is visible in the OPAC and staff interface',
-- 
2.20.1