2018-06-07 10:56:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Customer extends Application
|
|
|
|
{
|
|
|
|
private $Virtualmin;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::_construct();
|
|
|
|
|
|
|
|
$this->Virtualmin = new VirtualminHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
// By default, this function sets the customer as inactive (e.g. newly created, awating payment)
|
2018-06-07 14:14:25 +00:00
|
|
|
// Returns the customer's hosting passwords
|
2018-06-07 10:56:13 +00:00
|
|
|
public function newCustomer($Domain, $Name, $Email, $CheckoutID, $SubscriptionStatus, $Package, $PaddleSubscriptionID, $SystemStatus, $GDPRConsent, $hasVirtualServer = false, $attachedVServerID = null)
|
|
|
|
{
|
|
|
|
$passwordFactory = new RandomLib\Factory();
|
|
|
|
$pGen = $passwordFactory->getLowStrengthGenerator();
|
|
|
|
|
2018-06-07 14:14:25 +00:00
|
|
|
$PAC_Ptext = $pGen->generate(4);
|
|
|
|
$PAC = password_hash($PAC_Ptext, PASSWORD_BCRYPT);
|
|
|
|
|
2018-06-07 10:56:13 +00:00
|
|
|
$this->db->insert('Customers', [
|
|
|
|
'CustomerName' => $Name,
|
|
|
|
'CustomerEmail' => $Email,
|
|
|
|
'CustomerCheckoutID' => $CheckoutID,
|
|
|
|
'Package' => $Package,
|
|
|
|
'SubscriptionStatus' => $SubscriptionStatus,
|
|
|
|
'PaddleSubscriptionID' => $PaddleSubscriptionID,
|
|
|
|
'SystemStatus' => $SystemStatus,
|
|
|
|
'GDPRConsent' => $GDPRConsent,
|
|
|
|
'hasVirtualServer' => $hasVirtualServer,
|
|
|
|
'attachedVServerID' => $attachedVServerID,
|
2018-06-07 14:14:25 +00:00
|
|
|
'PAC' => $PAC
|
2018-06-07 10:56:13 +00:00
|
|
|
]);
|
|
|
|
|
2018-06-07 14:14:25 +00:00
|
|
|
$PanelPassword = $pGen->generate(16);
|
|
|
|
$this->Virtualmin->CreateVirtualServer($Domain, $PanelPassword);
|
2018-06-07 10:56:13 +00:00
|
|
|
|
|
|
|
|
2018-06-07 14:14:25 +00:00
|
|
|
return
|
|
|
|
[
|
|
|
|
"PanelPassword" => $PanelPassword,
|
|
|
|
"PersonalAuthenticationCode" => $PAC_Ptext
|
|
|
|
];
|
2018-06-07 10:56:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function updateCustomerInformation($CustomerID, $UpdateField, $NewValue)
|
|
|
|
{
|
|
|
|
$db->update('Customers', [
|
|
|
|
$UpdateField => $NewValue
|
|
|
|
], [
|
|
|
|
'ID' => $CustomerID
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function eraseCustomer($CustomerID)
|
|
|
|
{
|
|
|
|
// Virtualmin: Delete virutal server attached to customer
|
|
|
|
$db->delete('Customers', [
|
|
|
|
'ID' => $CustomerID
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function listCustomersByEmail($CEmail)
|
|
|
|
{
|
|
|
|
$Customer = $this->db->row(
|
|
|
|
"SELECT * FROM Customers WHERE CustomerEmail = ?",
|
|
|
|
$CEmail
|
|
|
|
);
|
|
|
|
|
2018-06-07 14:14:25 +00:00
|
|
|
return $Customer;
|
2018-06-07 10:56:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function translateEmailToID($Email)
|
|
|
|
{
|
|
|
|
$Customer = $this->listCustomersByEmail($Email);
|
|
|
|
|
|
|
|
return $Customer['ID'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function customerExists($CustomerEmail)
|
|
|
|
{
|
|
|
|
|
|
|
|
return $this->Exists("Customers", "CustomerEmail", $CustomerEmail);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getCustomerGDPRConsent($CustomerEmail)
|
|
|
|
{
|
|
|
|
$Customer = $this->listCustomersByEmail($CustomerEmail);
|
|
|
|
|
|
|
|
// assume this returns an array. do var_dump($Customer) if not
|
|
|
|
return $Customer['GDPRConsent'];
|
|
|
|
}
|
|
|
|
|
2018-06-07 14:14:25 +00:00
|
|
|
|
2018-06-07 10:56:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|