Browse Source

unSuspendAccount - enable users

andre 2 years ago
parent
commit
012ae39fdc
2 changed files with 45 additions and 13 deletions
  1. 1 1
      app/Http/Actions/SuspendAccount.php
  2. 44 12
      app/Http/Actions/UnsuspendAccount.php

+ 1 - 1
app/Http/Actions/SuspendAccount.php

@@ -96,7 +96,7 @@ class SuspendAccount extends AddonController
                 return ['error' => $error->getMessage()];
             }             
         }
-
+        $api->logout();
         /**
          * return success response
          */

+ 44 - 12
app/Http/Actions/UnsuspendAccount.php

@@ -7,6 +7,7 @@ use ThurData\Servers\KerioEmail\App\Enums\Response;
 use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
 use ThurData\Servers\KerioEmail\App\Traits\ExtensionsCheckerTrait;
 use ThurData\Servers\KerioEmail\Core\App\Controllers\Instances\AddonController;
+use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
 
 /**
  *
@@ -55,20 +56,51 @@ class UnsuspendAccount extends AddonController
      */
     protected function kerioRunService($params = null)
     {
-        $service = (new KerioManager())
-            ->getApiByServer($params['serverid'])
-            ->soap
-            ->service()
-            ->unsuspendDomain()
-            ->setFormData($params)
-        ;
-
-        $result = $service->run();
+        $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
+        try {
+            $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
+            $domainID = $api->getDomainId($params['domain']);
+        } catch (KerioApiException $error) {
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                $error,
+                'Debug Error',
+                $error->getMessage()
+            );
+            return ['error' => $error->getMessage()];
+        }             
+        if ($domainID === FALSE) {
+            return "Error: Domain $domain not found";
+        }
+        try {
+            $users = $api->getUsers(['id', 'loginName'], $domainID);
+        } catch (KerioApiException $error) {
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                $error,
+                'Debug Error',
+                $error->getMessage()
+            );
+            return ['error' => $error->getMessage()];
+        }             
 
-        if(!$result)
-        {
-            return $service->getError();
+        foreach($users as $user) {
+            try {
+                $api->modifyUser($user['id'], ['isEnabled' => TRUE]);
+            } catch (KerioApiException $error) {
+                logModuleCall(
+                    'kerioEmail',
+                    __FUNCTION__,
+                    $error,
+                    'Debug Error',
+                    $error->getMessage()
+                );
+                return ['error' => $error->getMessage()];
+            }             
         }
+        $api->logout();
 
         /**
          * return success response