This commit is contained in:
kshitige
2025-04-23 16:55:25 +05:30
parent 6148f82832
commit d07dc2fd6a

View File

@@ -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");