From bf696127a92d990865914b56bf4b36bc6e1372f4 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Tue, 27 Feb 2024 15:49:52 +0100
Subject: [PATCH] Reworked email lookup logic on CheckoutPage, so a user will
 be automatically created if their email address exists in sukat but doesn't
 have a corresponding boka user yet.

---
 include/CheckoutPage.php | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/CheckoutPage.php b/include/CheckoutPage.php
index f72af55..797b047 100644
--- a/include/CheckoutPage.php
+++ b/include/CheckoutPage.php
@@ -45,13 +45,18 @@ class CheckoutPage extends Page {
                     $search = $email .'@dsv.su.se';
                 }
                 # Lookup email directly in ldap since we don't store it
-                $emailuser = new User($this->ldap->search_email($search),
-                                      'name');
-            } catch(Exception $ue) {
+                $uid = $this->ldap->search_email($search);
+            } catch(Exception $le) {
                 $err = i18n('Email address {address} not found.',
                             $search);
                 throw new Exception($err);
             }
+            try {
+                $emailuser = new User($uid, 'name');
+            } catch(Exception $ue) {
+                # User wasn't found locally, so initialize a new user
+                $emailuser = User::create_user($uid);
+            }
         }
         if($nameuser && $emailuser) {
             if($nameuser != $emailuser) {