Customer can now log into the Portal, but can't see anything. See #32
Customer can now log into the Portal, but can't see anything. See #32

--- a/lib/auth.class.php
+++ b/lib/auth.class.php
@@ -217,7 +217,11 @@
 $username = rtrim($username," ");
 
   if (!$user = $db->retrieveUserCreds($username)){
-  return false;
+    // Not a user, user. Check the Portal login
+    $cust = new CredLockCust;
+    if ((!BTMain::getConf()->custPortalEnabled) || (!$user = $cust->checkLogin($username))){
+      return false;
+    }
   }
 
 

--- a/lib/customer.class.php
+++ b/lib/customer.class.php
@@ -42,6 +42,9 @@
     global $notifications;
     $not->className = 'alert alert-success';
     $not->text = "The customer has been successfully added to the customer portal and can use the password <i>$password</i> to manage their credentials";
+    // This echo is a temporary thing until I update Notifications
+    echo "<div class='{$not->className}'>{$not->text}</div>";
+
 
     $notifications->setNotification($not);
     }
@@ -58,7 +61,9 @@
 
 
 
-
+/** Edit a Customer record - including updating the portal details (i.e. update the email address if changed)
+*
+*/
 function edit($id,$name,$group,$firstname,$surname,$email){
 
 $db = new CustDB;
@@ -83,6 +88,30 @@
 }
 
 
+/** Called by ProgAuth::ProcessLogin - See if the supplied username matches any in the PortalDB
+*
+* @arg username
+*
+* @return object or false
+*/
+function checkLogin($username){
+$db = new AuthDB;
+
+if (!$user = $db->getPortalByUsername($username)){
+return false;
+}
+$crypt = new Crypto;
+
+// Set the customer indicator
+$user->membergroup = "-99,";
+$user->Name = $crypt->decrypt($user->ContactName,'auth')." ".$crypt->decrypt($user->Surname,'auth');
+return $user;
+
+
+
+}
+
+
 
 
 

--- a/lib/db/authdb.class.php
+++ b/lib/db/authdb.class.php
@@ -70,6 +70,20 @@
 $sql = "UPDATE #__CustPortal SET `email`='$email' WHERE `id`='$id'";
 $this->setQuery($sql);
 return $this->runQuery();
+}
+
+
+/** See if a Customer Portal record exists, and return it if it does
+* @arg username
+*
+* @return object
+*/
+function getPortalByUsername($username){
+$crypt = new Crypto;
+$username=$this->stringEscape($crypt->encrypt($username,'auth'));
+$sql = "SELECT a.*, b.ContactName, b.ContactSurname FROM #__CustPortal as a LEFT JOIN #__Cust as b ON a.id = b.id WHERE a.`email`='$username'";
+$this->setQuery($sql);
+return $this->loadResult();
 }