diff --git a/app/Services/AdminService.php b/app/Services/AdminService.php index 8ec4a60..84f448c 100644 --- a/app/Services/AdminService.php +++ b/app/Services/AdminService.php @@ -490,12 +490,42 @@ class AdminService } } + // public function activateUser(User $user, string $password, string $activateToken) + // { + // try { + // $payload = [ + // 'activateToken' => $activateToken, + // 'password' => $password + // ]; + + // $activationUrl = "{$this->baseUrl}/api/noauth/activate"; + + // $response = Http::withHeaders([ + // 'Content-Type' => 'application/json', + // ])->post($activationUrl, $payload); + + // if (!$response->successful()) { + // Log::error("Failed to activate user in ThingsBoard. Error: " . $response->body()); + // throw new \Exception('Failed to activate user: ' . $response->body()); + // } + + // Log::info("User activated successfully in ThingsBoard for User ID: {$user->id}"); + // } catch (\Exception $e) { + // Log::error("Error activating user in ThingsBoard for User ID: {$user->id}. Exception: " . $e->getMessage()); + // throw $e; + // } + // } + + public function activateUser(User $user, string $password, string $activateToken) { try { + $dummyEmail = 'dummy+' . $user->id . '@example.com'; // unique dummy email + $payload = [ 'activateToken' => $activateToken, - 'password' => $password + 'password' => $password, + 'email' => $dummyEmail // send dummy email to ThingsBoard ]; $activationUrl = "{$this->baseUrl}/api/noauth/activate"; @@ -509,7 +539,7 @@ class AdminService throw new \Exception('Failed to activate user: ' . $response->body()); } - Log::info("User activated successfully in ThingsBoard for User ID: {$user->id}"); + Log::info("User activated in ThingsBoard with dummy email: {$dummyEmail} for User ID: {$user->id}"); } catch (\Exception $e) { Log::error("Error activating user in ThingsBoard for User ID: {$user->id}. Exception: " . $e->getMessage()); throw $e; @@ -517,8 +547,6 @@ class AdminService } - - public function getUserByEmailThingsBoard(string $email) { Log::info("Fetching ThingsBoard ID by email: $email");